I'm trying to write an expression to calculate the elevation field of stormwater devices from the intersecting polygon from another layer in the same REST service. I have been able to calculate fields from intersecting features before, but for some reason it keeps giving me an error. If I use $datastore, I get table not found. If I use $map or $layer, I get object not found, even though the layer is loaded in the current map. The error is coming on the first assignment statement. What am I getting wrong?
// Retrieve the DEM polygons feature set
var demFeatures = FeatureSetByName($datastore, "Elev_Polygons_2023", ["gridcode"], true);
// Find the polygons that intersect with the current device
var intersectingPolygons = Filter(demFeatures, 'Intersects($feature)');
// Get the first intersecting polygon
var intersectingPolygon = First(intersectingPolygons);
// Extract the gridcode value if an intersecting polygon exists
var elevation = intersectingPolygon["gridcode"];
// Return the elevation value
return elevation;
I believe you have to include the owner as well as the feature.
In this example, ESAGE is the owner of swSubbasins:
var subb = FeatureSetByName($datastore,"ESAGE.swSubbasin",["SUBBASIN"], true)
Give that a try and see if that helps.
please post code using the insert code sample option
// Retrieve the DEM polygons feature set
var demFeatures = FeatureSetByName($datastore, "Elev_Polygons_2023", ["gridcode"], true);
// Find the polygons that intersect with the current device
var intersectingPolygons = Filter(demFeatures, 'Intersects($feature)');
// Get the first intersecting polygon
var intersectingPolygon = First(intersectingPolygons);
// Extract the gridcode value if an intersecting polygon exists
var elevation = intersectingPolygon["gridcode"];
// Return the elevation value
return elevation;
Why is the 'Interescts($feature)' a string? Dont think you need filter at all
change to
var intersectingPolygons = Intersects(demFeatures, $feature);