<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Sum Point attribute in Polygons in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/sum-point-attribute-in-polygons/m-p/430173#M33809</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would look at the zonal statistics tool, or use intersect/spatial join/identity then dissolve with a sum option.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 03 Sep 2013 16:29:58 GMT</pubDate>
    <dc:creator>MathewCoyle</dc:creator>
    <dc:date>2013-09-03T16:29:58Z</dc:date>
    <item>
      <title>Sum Point attribute in Polygons</title>
      <link>https://community.esri.com/t5/python-questions/sum-point-attribute-in-polygons/m-p/430170#M33806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a polygon file that is continent wide.&amp;nbsp; Within each unique polygon ID (14,000 total), I have a point dataset where bird point counts were collected.&amp;nbsp; Within a unique polygon ID there could be no ('0') points or up to a total of 5.&amp;nbsp; I'd like to loop through the polygon dataset and sum the number of birds counted at each point.&amp;nbsp; This way, I'll have the total number of birds counted within each polygon.&amp;nbsp; That is, I don't need the number of points within the polygon, but the number of counts at each point within each polygon.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd appreciate any suggestions on how to summarize a point attribute within a polygon.&amp;nbsp; My polygons have a unique ID ("ID") and I have a field within each point ("Count") summarizing the total count at that point.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for any help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jared&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Sep 2013 19:47:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-point-attribute-in-polygons/m-p/430170#M33806</guid>
      <dc:creator>JaredStabach</dc:creator>
      <dc:date>2013-09-02T19:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Sum Point attribute in Polygons</title>
      <link>https://community.esri.com/t5/python-questions/sum-point-attribute-in-polygons/m-p/430171#M33807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jared,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Tim&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Sep 2013 22:14:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-point-attribute-in-polygons/m-p/430171#M33807</guid>
      <dc:creator>TimDonoyou</dc:creator>
      <dc:date>2013-09-02T22:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sum Point attribute in Polygons</title>
      <link>https://community.esri.com/t5/python-questions/sum-point-attribute-in-polygons/m-p/430172#M33808</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Tim&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm going to do the manual approach you suggested for now, but will likely transition to doing it in Python.&amp;nbsp; I'm not great with the update cursor, but having the python is a better approach over the long term.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jared&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Sep 2013 14:55:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-point-attribute-in-polygons/m-p/430172#M33808</guid>
      <dc:creator>JaredStabach</dc:creator>
      <dc:date>2013-09-03T14:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: Sum Point attribute in Polygons</title>
      <link>https://community.esri.com/t5/python-questions/sum-point-attribute-in-polygons/m-p/430173#M33809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would look at the zonal statistics tool, or use intersect/spatial join/identity then dissolve with a sum option.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Sep 2013 16:29:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-point-attribute-in-polygons/m-p/430173#M33809</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-09-03T16:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: Sum Point attribute in Polygons</title>
      <link>https://community.esri.com/t5/python-questions/sum-point-attribute-in-polygons/m-p/430174#M33810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks Tim&lt;BR /&gt;&lt;BR /&gt;I'm going to do the manual approach you suggested for now, but will likely transition to doing it in Python.&amp;nbsp; I'm not great with the update cursor, but having the python is a better approach over the long term.&lt;BR /&gt;&lt;BR /&gt;Jared&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Construct the process through a Model in Model Builder and then export the Model as a Python script.&amp;nbsp; That way you have a start on the process and can decide if you want to replace geoprocessing tools with cursors later.&amp;nbsp; 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.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Sep 2013 16:41:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-point-attribute-in-polygons/m-p/430174#M33810</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2013-09-03T16:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: Sum Point attribute in Polygons</title>
      <link>https://community.esri.com/t5/python-questions/sum-point-attribute-in-polygons/m-p/430175#M33811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for all the responses.&amp;nbsp; I really appreciate it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&amp;nbsp; 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.&amp;nbsp; Thanks Marc for posting this code.&amp;nbsp; For those interested, the python code to summarize a point attribute within polygons (or at least, one way of doing it) is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import system modules&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Define Workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = r"C:\Temp\Projects\Macrosystems\EMap\Emap.gdb"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.overwriteOutput = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;birds = "Bird1720"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Point File in geoDB&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;polys = "Emap_poly"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Polygon File in GeoDB&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;bird_layer = "birds_feat" &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;poly_layer = "polys_feat" &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Make the point dataset a layer file to reference&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.MakeFeatureLayer_management(birds, bird_layer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for row in arcpy.SearchCursor(polys):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; poly_OID = row.OBJECTID&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(polys, poly_layer, 'OBJECTID = ' + str(poly_OID))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management(bird_layer, 'WITHIN', poly_layer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; list2 = [r.BCount for r in arcpy.SearchCursor(bird_layer)]&amp;nbsp;&amp;nbsp; # BCount is the attribute field that you want to summarize&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sumlist = sum(list2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; poly_rows = arcpy.UpdateCursor(poly_layer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for layer_row in poly_rows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer_row.BBS_Cnt = sumlist&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # BBS_Cnt is the field in the polygon file to update&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; poly_rows.updateRow(layer_row)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Clean up....remove locks on dataset&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del poly_rows, row, layer_row&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Sep 2013 14:50:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-point-attribute-in-polygons/m-p/430175#M33811</guid>
      <dc:creator>JaredStabach</dc:creator>
      <dc:date>2013-09-04T14:50:19Z</dc:date>
    </item>
  </channel>
</rss>

