Dynamically counting points in Polygons

10-30-2018 07:05 AM
Occasional Contributor III
  • I have a fairly large points layer in a hosted feature service - Lets call this incidents
    • This layer is frequently changing every couple of minutes with new records, deletes and updated locations.
  • I have a polygon layer as a hosted feature service - lets call this districts
    • A static layer that never changes shape.
  • This is all in ArcGIS Online.  No ArcGIS Enterprise in the mix.

As a user, I want to have a count of how many points there are in each polygon, along with perhaps some summary stats on the numerical fields from the incidents layer.

With a DBMS + ArcGIS Enterprise, I could create a nice Query layer and leverage ST_Intersects to have the polygons dynamically count how many features there are within them.  But, I don't have access to these for this project.

I was looking at Arcade, but does not look like this is possible to reference a separate layer. 

I was also looking at the Geometry Engine and the Contains method on a polygon in the Esri Javascript API (custom front-end logic is fine).  This sounds client-heavy.  I would have to send all incidents to the browser and then loop through each incident that is contained in each district to tally up scores, and then render.  But, could be an option here.  Could do with a sample snippet or pseudocode as a headstart...

There is the Spatial Join analysis tool, but the frequency this would need to be run (every couple of minutes) going to burn through my credits allowance fairly quick.

Anyone want to brainstorm this a little and offer a better suggestion I might not have thought of?

A Python funtion running every couple of minutes on AWS Lambda every with some non-arcpy libraries that perform the counts/summary stats?

0 Kudos
4 Replies
MVP Esteemed Contributor


   Why not just to a simple query on the map service for each district using a queryTask?

0 Kudos
Occasional Contributor III

At the moment, I am investigating the use of doing this with a view.  That way the crunching can be done server-side and looks like it won't incurr any credits.

Set hosted feature layer view definition—ArcGIS Online Help | ArcGIS 

Will report back my findings...

New Contributor

Hi Simon,

Were you ever able to find a solution to this problem?  I am wanting to do something similar and have yet to find a solid answer on this.

0 Kudos
Occasional Contributor III

I would also like to do this but I would like it to display as dynamic text in an ArcPro layout. I am currently using a Count function to display the number of points in my layout but I need it to count the number of points that fall within the polygon in my layout.

0 Kudos