Is it possible to perform spatial relationship calculations in the ArcGis Pro field calculator?
For example:
Is it possible to determine how many points of a layer are contained within each entity of a polygon layer and place that result in a field using the field calculator?
The new field created in the polygon layer would have an integer value with the number of points contained.
Perhaps using SQL? does it require a special license?
Solved! Go to Solution.
You can use Arcade in the Field Calculator (default is Python). Arcade is a language developed by ESRI specifically for use in their Desktop and Web GIS environments. You can find a more thorough introduction here: Getting Started | ArcGIS Arcade | ArcGIS Developer
With Arcade, what you ask is easily achievable. This would be a sample expression for counting the points in a polygon feature:
// load the point featureclass
var points = FeatureSetByName($datastore, "NameOfThePointFeatureClass", ["*"], true)
// get the points inside the current polygon feature
var points_in_polygon = Contains($feature, points)
// count them and return the number
return Count(points_in_polygon)
Yes, spatial relations of some types can be calculated using Python. The issue you’re going to run into here is that the field calculator only sees the fields in one layer, so you would need to join the second layer to it, which for the example you describe would be easiest if the first layer of polygons had a uniform field and the second layer of points was a single multipoint-feature with that same uniform field. Then all of the points would be available for comparison to each polygon with the Spatial Join method of Arcpy:
Spatial Join (Analysis)—ArcGIS Pro | Documentation
But I wouldn’t do it that way; if you’re working with the field calculator you can also use the geoprocessing tools, and the Spatial Join tool will be much easier, with the non-multipoint point layer as the Target Features and the polygons as the Join Features, which will label each point with attributes of the polygon in which it lies. You can then use the Pivot Table tool to summarize the number of points for each polygon.
Pivot Table (Data Management)—ArcGIS Pro | Documentation
— Andy
You can use Arcade in the Field Calculator (default is Python). Arcade is a language developed by ESRI specifically for use in their Desktop and Web GIS environments. You can find a more thorough introduction here: Getting Started | ArcGIS Arcade | ArcGIS Developer
With Arcade, what you ask is easily achievable. This would be a sample expression for counting the points in a polygon feature:
// load the point featureclass
var points = FeatureSetByName($datastore, "NameOfThePointFeatureClass", ["*"], true)
// get the points inside the current polygon feature
var points_in_polygon = Contains($feature, points)
// count them and return the number
return Count(points_in_polygon)
Thank you! this works!