I'm creating a grid index for roads. I've created the field (Page:Grid) and it includes the page number and grid number, but they are listed as such:
I'd like the data to display with the page number then all grids on that particular page. So rather than reading 26: C1, 26: C2, 26: C3, 26: C4 it would appear 26: C1, C2, C3, C4. I was thinking calculate field would be the best way to reorganize the field the way I'd like. Is this possible?
Solved! Go to Solution.
This should give you the correct output
var arrField = Split($feature['Page:Grid'],",");
var dict = {}
for (var i in arrField) {
var input = Split(arrField[i], ": ");
var key = input[0];
if (HasKey(dict, key)) {
var value = Concatenate([dict[key], input[1]], ", ")
dict[key] = value;
} else {
dict[key] = input[1]
}
}
var output = [];
for (var k in dict) {
Push(output, Concatenate([k, dict[k]], ': '))
}
return Concatenate(output, ' | ')
For example, this would return "20: E5 | 21: A5 | 22: A1 | 26: D1, E1" for row 8
Does the following calculate field script produce the output you'd like? Be sure to enable Edit Undo! You might need to change the $feature['x'] names to match your fields.
var pagenum = $feature['Page Number'] + ":"
pagenum + Concatenate(Split($feature['Page:Grid'],pagenum))
Thanks, Robert! It did for some records, but not all for some reason. I'm not sure if the attached image is ledgable or not. The field showing 39: A3,39: A4,39: A5,39: B2,39: B3,39: C2,38: E4,38: E5,42: B1,42: C1 produced results of 39: A3, A4, A5, B2, B3, C2,38: E4,38: E5,42: B1,42: C1 with the provided script. I created a new field named Index for the calculate field results to populate.
This should give you the correct output
var arrField = Split($feature['Page:Grid'],",");
var dict = {}
for (var i in arrField) {
var input = Split(arrField[i], ": ");
var key = input[0];
if (HasKey(dict, key)) {
var value = Concatenate([dict[key], input[1]], ", ")
dict[key] = value;
} else {
dict[key] = input[1]
}
}
var output = [];
for (var k in dict) {
Push(output, Concatenate([k, dict[k]], ': '))
}
return Concatenate(output, ' | ')
For example, this would return "20: E5 | 21: A5 | 22: A1 | 26: D1, E1" for row 8
Thank you!!