This document will walk you through how to summarize point counts within polygons using GeoEvent. In this example, I will demonstrate how to summarize the number of crimes within each NYPD precinct. I have a feature service that is being updated with crimes, and another feature service of the NYPD precincts. The NYPD precincts feature service contains a field called crimecount that I wish to update with the number of crimes.
1. First I will want to add a GeoFence Synchronization Rule by going to GeoEvent Manager > Site > GeoFences > Add:
2. I will select the NYPD_Crimes feature service and set a refresh interval to update the geofences every 5 minutes. Geofences are stored in memory, so if there will be potentially several thousands of GeoFences, you may want to consider adding a Time Extent End. This will specify when a particular GeoFence is no longer in effect and will be subject to the GeoFence Purging settings in the Global Settings. In this example, I will not be setting one.
You will see the GeoFences after they are imported and will update automatically every 5 minutes:
3. Next, I will set up a Poll an ArcGIS Server for Features input connector to poll the NYPD Precincts feature service:
4. I will also set up an Update a Feature output connector on the same NYPD Precincts feature service:
5. Next, I will create a GeoEvent Service and add the NYPD Precinct Input and a GeoTagger Processor. I specify the GeoFences I want to search for by the category name and a wildcard. The geotags are written to a new field called GeoTags and I choose the option not to include the category.
6. The GeoTags field will contain all the GeoFences that the precincts contain, separating them with a comma (i.e 63570376, 63570255). A Field Calculator (Regular Expression) processor is added to add all of the commas from the GeoTags field to a new String field, count, using the expression (,[^,]{0}).
7. A Field Calculator processor is added to remove the spaces between the commas, and count the length of the String field (count). The value is written to a new field called crimes. The expression used is: length(replaceAll(count,' ',''))
8. The previous Field Calculator won't give an accurate count. For example, if there were two crimes (i.e 63570376, 63570255) only 1 comma exists, so the crimes count would be 1 when it should be 2. So, we need to add one to the crimes field, but only when this field does not equal 0. We will add a Filter to only process crimes greater than 0:
9. After the Filter, use the Field Calculator processor to add 1 to the crimes field:
10. Finally a Field Mapper processor is used to map the crimes to the crimecount in the precinct feature service:
The precinct feature service should now show a count for all the crimes that occur within each precinct: