When iterating through a series of features, how do you know where to put the console message? I have written the following calculate expression:
var AssignedDate = $feature.CreationDate;
var Road = FeatureSetByName($datastore, 'Road');
var line_fs = Intersects(Road, Buffer($feature, 150, "Meters"));
// Cycle through road segments & find closest one
var min_dist = 9999
var nearest_RoadClass = null
var geo = Geometry($feature)
for(var line in line_fs) {
var line_geo = Geometry(line)
var dist = Distance(geo, line_geo)
if(dist < min_dist) {
min_dist = dist
nearest_RoadClass = line.CLASS
}
}
Console(nearest_RoadClass)
and expect to see Class 6 in the console message (if you look in the attribute table, you can see that I have selected a subset of my data and both of the features are closest to a Class 6 Road) but it returns Class 5. Why?
Moving the Console message into the curly brackets above doesn't provide the expected output either:
var AssignedDate = $feature.CreationDate;
var Road = FeatureSetByName($datastore, 'Road');
var line_fs = Intersects(Road, Buffer($feature, 150, "Meters"));
// Cycle through road segments & find closest one
var min_dist = 9999
var nearest_RoadClass = null
var geo = Geometry($feature)
for(var line in line_fs) {
var line_geo = Geometry(line)
var dist = Distance(geo, line_geo)
if(dist < min_dist) {
min_dist = dist
nearest_RoadClass = line.CLASS
}
Console(nearest_RoadClass)
}
Moving it up one more level also returns the Class 5 Class 5 Class 5 output:
var AssignedDate = $feature.CreationDate;
var Road = FeatureSetByName($datastore, 'Road');
var line_fs = Intersects(Road, Buffer($feature, 150, "Meters"));
// Cycle through road segments & find closest one
var min_dist = 9999
var nearest_RoadClass = null
var geo = Geometry($feature)
for(var line in line_fs) {
var line_geo = Geometry(line)
var dist = Distance(geo, line_geo)
if(dist < min_dist) {
min_dist = dist
nearest_RoadClass = line.CLASS
Console(nearest_RoadClass)
}
}