Counting points inside a polygon

7527
20
Jump to solution
01-26-2016 07:32 AM
AdrianWelsh
MVP Honored Contributor

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:

30779 - Count the number of point features within a polygon

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?

Thanks!

0 Kudos
1 Solution

Accepted Solutions
JimmyKroon
Frequent Contributor

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.

View solution in original post

20 Replies
AdrianWelsh
MVP Honored Contributor

...and I know there are issues when points fall outside of the polygon. I found this article that discusses using the Proximity tool to calculate that:

More adventures in overlay: point in polygon | ArcGIS Blog

0 Kudos
WendellThompson
Deactivated User

Have you tried using the PointCollection object? I'm not sure what platform you're on, but on the ArcGIS Runtime for .NET there is a PointCollection class in this namespace "Esri.ArcGISRuntime.Geometry".

You could use this to build a collection of points, and then transpose them to a polygon as needed.  Keeping track of the MapPoint count should be straightforward at this point.

AdrianWelsh
MVP Honored Contributor

This sounds like something that would still have to replace the feature class with, right? Not something that would be an automatic update?

0 Kudos
WendellThompson
Deactivated User

As I mentioned, i'm not sure what platform you're working on, but an implementation (in .NET) that comes to mind would be a wrapper class that held a PointCollection as well a Polygon Feature.  As the PointCollection was updated, the Polygon would be re-drawn on a graphics layer.

0 Kudos
AdrianWelsh
MVP Honored Contributor

I'm running ArcGIS 10.3.1 Desktop (ArcMap) on Windows 10, 64-bit. I am not sure that I would want a graphics layer as opposed to a feature class within a geodatabase. And, I am not as familiar with .NET as I once was year ago...

0 Kudos
VinceAngelo
Esri Esteemed Contributor

You'd need to re-run the operation for each changed geometry, when it is changed.  This sort of thing is better left to a database trigger, but then you'd need to be using an enterprise geodatabase.

- V

AdrianWelsh
MVP Honored Contributor

I was afraid that I would need to re-run it each time. Would a database trigger be something you would script up in Python or so? And do you have to use an enterprise geodatabase for it?

0 Kudos
VinceAngelo
Esri Esteemed Contributor

No, database triggers are generally written in SQL (for which this is a relatively simple operation).

AdrianWelsh
MVP Honored Contributor

Ah, that makes sense.

0 Kudos