Select to view content in your preferred language

Sum Point attribute in Polygons

3554
5
09-02-2013 12:47 PM
JaredStabach
Deactivated User
Hello

I have a polygon file that is continent wide.  Within each unique polygon ID (14,000 total), I have a point dataset where bird point counts were collected.  Within a unique polygon ID there could be no ('0') points or up to a total of 5.  I'd like to loop through the polygon dataset and sum the number of birds counted at each point.  This way, I'll have the total number of birds counted within each polygon.  That is, I don't need the number of points within the polygon, but the number of counts at each point within each polygon.

I'd appreciate any suggestions on how to summarize a point attribute within a polygon.  My polygons have a unique ID ("ID") and I have a field within each point ("Count") summarizing the total count at that point.

Thanks for any help.

Jared
Tags (2)
0 Kudos
5 Replies
TimDonoyou
Regular Contributor
Hi Jared,

Without using python you could do a spatial join with the bird points as the target layer and the state polygons as the join layer. This would assign a StateID / Name to each point which you could summarise by and get the sum of the bird count attribute. If necessary you could join this by attribute back to the original state polygon layer.

The alternative in python would be to use a search or update cursor to loop through each feature in the polygon layer, select by location the points within in each feature, get the value of the bird count attribute for each point, sum them and then update a field in the polygon layer - this is straightforward to code but would probably take longer than the spatial join approach described above.

Hope this helps

Cheers

Tim
0 Kudos
JaredStabach
Deactivated User
Thanks Tim

I'm going to do the manual approach you suggested for now, but will likely transition to doing it in Python.  I'm not great with the update cursor, but having the python is a better approach over the long term.

Jared
0 Kudos
MathewCoyle
Honored Contributor
I would look at the zonal statistics tool, or use intersect/spatial join/identity then dissolve with a sum option.
0 Kudos
RichardFairhurst
MVP Honored Contributor
Thanks Tim

I'm going to do the manual approach you suggested for now, but will likely transition to doing it in Python.  I'm not great with the update cursor, but having the python is a better approach over the long term.

Jared


Construct the process through a Model in Model Builder and then export the Model as a Python script.  That way you have a start on the process and can decide if you want to replace geoprocessing tools with cursors later.  In any event the script can be run as either a model or a Python script without having to do it manually each time you want to run it.
0 Kudos
JaredStabach
Deactivated User
Thanks for all the responses.  I really appreciate it.

It seems that doing a spatial join and then simply summing the attribute is the quickest option, which can be joined back to my original polygon layer.  I ended up writing a python script to automate the process, which is essentially from another post "Re:Finding sum of values in field" from a few years ago by Marc Nakleh.  Thanks Marc for posting this code.  For those interested, the python code to summarize a point attribute within polygons (or at least, one way of doing it) is:

# Import system modules
import arcpy

# Define Workspace
arcpy.env.workspace = r"C:\Temp\Projects\Macrosystems\EMap\Emap.gdb"
arcpy.env.overwriteOutput = True

birds = "Bird1720"                   # Point File in geoDB
polys = "Emap_poly"                # Polygon File in GeoDB
bird_layer = "birds_feat"
poly_layer = "polys_feat"

# Make the point dataset a layer file to reference
arcpy.MakeFeatureLayer_management(birds, bird_layer)

for row in arcpy.SearchCursor(polys):
    poly_OID = row.OBJECTID
    arcpy.MakeFeatureLayer_management(polys, poly_layer, 'OBJECTID = ' + str(poly_OID))
    arcpy.SelectLayerByLocation_management(bird_layer, 'WITHIN', poly_layer)
   
    list2 = [r.BCount for r in arcpy.SearchCursor(bird_layer)]   # BCount is the attribute field that you want to summarize  
    sumlist = sum(list2)
   
    poly_rows = arcpy.UpdateCursor(poly_layer)
    for layer_row in poly_rows:
        layer_row.BBS_Cnt = sumlist                                    # BBS_Cnt is the field in the polygon file to update
        poly_rows.updateRow(layer_row)

# Clean up....remove locks on dataset
del poly_rows, row, layer_row
0 Kudos