I am trying to summarize multiple road segments with the same name (e.g. Main St) into an array, that I can then write to a single line in a table within the same datastore. I found a similar workflow suggestion by @JohannesLindner but I do not have a relationship between the road feature class and the master road name table and I am concatenating values in an array instead of summing to a total.
Before this rule runs, there is another rule that Intersects the line segment being created or updated with a grid/map index which is the "IntersectingGrids" field below.
Here's what I have so far:
/ Get all features with the same LineID
var line_id = $feature.LineID;
var query = "LineID = + @line_id";
var roads = Filter($featureset, query);
// Output array
var grid_arr = [];
// Sort function for later
function grid_sort(a, b){
if (a > b){
return 1;
} else {
return -1;
}
}
// Check if records exist
if (Count(roads) > 0) {
for (var row in roads) {
// split value by commas
var items = Split(row.IntersectingGrids, ',', -1, true);
for (var i in items) {
// trim any whitespace
var grid_value = Trim(items[i]);
// Check if grid value already in array
if (Find(grid_value, grid_arr) == -1){
// Add to array
Push(grid_arr, grid_value);
}
}
}
// Sort grid_arr with custom sort function
var sorted = Concatenate(Sort(grid_arr, grid_sort), ', ');
} else {
return 'No records.';
}
var lineListExpression =;
var lineListFeatures = FeatureSetByName($datastore, 'Line_List', ['GridList1'], false);
var features = Filter(lineListFeatures, "LineID = '" + line_id + "'")
But I am not sure where to go after that.
I have a batch attribute rule in the Line_List table that works, although it does not update if there is already something in the field. Ideally, when a change is made to a road segment (geometry edit or road name change), the GridList field in the master road names table would automatically update.
//This batch rule is saved in the Line_List table and works to summarize the various line segments and group them by LineID, then produce a summary array, but it does not update when changes are made to the road segments in the feature class.
// Output array
var grid_arr = []
// Sort function for later
function grid_sort(a, b){
if (a > b){
return 1
} else {
return -1
}
}
var lineID = $feature.LineID
// Get related records
var segments = FeatureSetByName($datastore, "Line", ['LineID', 'Test_txt'], false)
var segment_data = Filter(segments, "lineID = '" + $feature.LineID + "'")
// Check if related records exist
if(Count(segment_data) > 0){
for (var row in segment_data){
// split value by commas
var items = Split(row.Test_txt, ',', -1, true)
for (var i in items){
// trim any whitespace
var grid_value = Trim(items[i])
// Check if grid value already in array
if (Find(grid_value, grid_arr) == -1){
// Add to array
Push(grid_arr, grid_value)
}
}
}
// Sort grid_arr with custom sort function
var sorted = Sort(grid_arr, grid_sort)
// Return concatenated string of array values
return Concatenate(sorted, ', ')
} else {
return 'No records.'
}