This is a fairly "simple" GIS operation but I wanted to ask, is Spatial Join the only, or best, method to calculate this? As described in this article:
What I am basically wondering is how to have a continually updated polygon feature that would keep a count of points within it. Does that make sense?
Solved! Go to Solution.
You could script the solution with python and then use Windows Task Scheduler to have the operation run every night or more often if needed (every hour, every 30 minutes, or whatever is appropriate for your situation). If python is not your thing one could make it in model builder and the export it to python.
If the geometry is being continually updated, then the time to make the PCOUNT edit is when the shape is updated (together, in one transaction). Updating the counts in batch would only make sense if all the polygons are edited at the same time, in which case you should make all the edits to an intermediate copy, then update the master after the long-running job is complete.
You could look into creating a Python Add-in Application Extension. See a list of available triggers here. It depends how often you want to run your script, but I expect you would probably want something that triggers fairly regularly, like: onEditorSelectionChanged() or onCurrentTaskChanged() or onSaveEdits(). Your script could be as simple as one line within the add-in event method calling Spatial Join.
I have a simple python script that will count points within polygons and add the count to a field in the polygon feature class. It's pretty simple and you could run it automatically using a batch file and windows scheduler - or just run the script as needed from explorer. If that sounds helpful I'll find and post it.
It is attached. You'll need to edit these variables to make it work and the polygon feature class needs an integer field to store the results.
Points = "D:\\Data\\Geodatabase.gdb\\PointFC"
Zones = "D:\\Data\\Geodatabase.gdb\\PolygonFC"
zoneNameField = "NAME"
zoneIncidentsField = "INCIDENTS"
Once your paths and field names are stored you can double-click from windows explorer to run anytime you want.
Wow thanks! Great script. Those does exactly what I needed it to do. One question though, what is the point of the "zoneNameField" in this? Doesn't the script just cycle through all of the features within that feature class? If some features had the same zone name, would those get counted the same?
zoneNameField is used to build a query which is required to create a feature layer containing one polygon. You could use the objectID field for this value too.
queryString = '"' + zoneNameField + '" = ' + "'" + zoneName + "'"
arcpy.MakeFeatureLayer_management(Zones, "CurrentZoneLayer", queryString)
And yes, if you had multiple polygons with the same name, they would get grouped together for the counts because the query would select them all.