<?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: Aggregating graffiti incidents with python script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/aggregating-graffiti-incidents-with-python-script/m-p/8688#M724</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi I need help with writing a script:&lt;BR /&gt;&lt;BR /&gt;The task&lt;BR /&gt;&lt;BR /&gt;I have a point feature class of graffiti incidents and a polygon feature class of patrol zones with some empty attributes already created for you. I must write a script that updates the attributes of the patrol zones with:&lt;BR /&gt;&lt;BR /&gt;�?� The number of graffiti incidents falling within the patrol zone. This is an integer that goes in the INCIDENTS field.&lt;BR /&gt;&lt;BR /&gt;�?� The priority ranking for the patrol zone. This is a string that goes in the PRIORITY field. You will derive this string using some simple math that compares the number of incidents in the zone with the area of the zone.&lt;BR /&gt;&lt;BR /&gt;Patrol zone priority rankings&lt;BR /&gt;&lt;BR /&gt;I then will calculate a priority ranking for each zone by dividing the number of graffiti incidents in the zone by the area of the zone. My script should then examine the result and assign the appropriate priority ranking (PRIORITY). These are the priority rankings:&lt;BR /&gt;&lt;BR /&gt;�?� TOP CONCERN�??15 or more incidents per square mile&lt;BR /&gt;�?� HIGH CONCERN�?? At least 12 but less than 15 incidents per square mile&lt;BR /&gt;�?� SOME CONCERN�?? At least 6 but less than 12 incidents per square mile&lt;BR /&gt;�?� LOW CONCERN�??Fewer than 6 incidents per square mile&lt;BR /&gt;&lt;BR /&gt;Here's what I have so far:&lt;BR /&gt;&lt;BR /&gt;import arcpy&lt;BR /&gt;arcpy.env.overwriteOutput= True&lt;BR /&gt;&lt;BR /&gt;# layer that we are changing&lt;BR /&gt;patrolZone= "C:\\...\\PoliceData.gdb\\PatrolZones"&lt;BR /&gt;# the layer we are selecting from&lt;BR /&gt;graffiti= "C:\\...\\PoliceData.gdb\\GraffitiIncidents"&lt;BR /&gt;nameField= "NAME"&lt;BR /&gt;graffitiField= "OBJECTID"&lt;BR /&gt;incidentsField= "INCIDENTS"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# sits above the first row, starts the cursor&lt;BR /&gt;patrolRows= arcpy.UpdateCursor(patrolZone)&lt;BR /&gt;&lt;BR /&gt;# tells it to go to the first row&lt;BR /&gt;patrol= patrolRows.next()&lt;BR /&gt;# now were in the first row doing looping&lt;BR /&gt;&lt;BR /&gt;while patrol:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(graffiti, "GraffitiLayer")&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; zones= patrol.getValue(nameField)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print incidents&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryString = '"' + str(nameField) + '" = ' + "'" + str(zones) + "'"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(queryString)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(patrolZone, "PatrolLayer", queryString)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("GraffitiLayer", "CONTAINED_BY", "PatrolLayer")&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; numGraffiti= arcpy.GetCount_management("GraffitiLayer")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print numGraffiti&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; patrol= patrolRows.next()&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I would appreciate any help!!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Use SpatialJoin_analysis (target_features, join_features, out_feature_class, {join_operation}, {join_type}, {field_mapping}, {match_option}, {search_radius}, {distance_field_name}).&amp;nbsp; target_features will by your polygon feature class. join_features will be your point feature class. {match_option} will be CONTAINS, in your case, means patrolZone contains graffiti incidents. The result feature classs will have a field Join_Count which indicates how many join features match each target feature, in your case, means how many graffiti incidents in each patrolZone. Then you can use CalculateField_management: count/SHAPE.area...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 04 Nov 2011 18:39:52 GMT</pubDate>
    <dc:creator>HemingZhu</dc:creator>
    <dc:date>2011-11-04T18:39:52Z</dc:date>
    <item>
      <title>Aggregating graffiti incidents with python script</title>
      <link>https://community.esri.com/t5/python-questions/aggregating-graffiti-incidents-with-python-script/m-p/8687#M723</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi I need help with writing a script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The task&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a point feature class of graffiti incidents and a polygon feature class of patrol zones with some empty attributes already created for you. I must write a script that updates the attributes of the patrol zones with:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;??? The number of graffiti incidents falling within the patrol zone. This is an integer that goes in the INCIDENTS field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;??? The priority ranking for the patrol zone. This is a string that goes in the PRIORITY field. You will derive this string using some simple math that compares the number of incidents in the zone with the area of the zone.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Patrol zone priority rankings&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I then will calculate a priority ranking for each zone by dividing the number of graffiti incidents in the zone by the area of the zone. My script should then examine the result and assign the appropriate priority ranking (PRIORITY). These are the priority rankings:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;??? TOP CONCERN???15 or more incidents per square mile&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;??? HIGH CONCERN??? At least 12 but less than 15 incidents per square mile&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;??? SOME CONCERN??? At least 6 but less than 12 incidents per square mile&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;??? LOW CONCERN???Fewer than 6 incidents per square mile&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's what I have so far:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&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;# layer that we are changing&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;patrolZone= "C:\\...\\PoliceData.gdb\\PatrolZones"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# the layer we are selecting from&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;graffiti= "C:\\...\\PoliceData.gdb\\GraffitiIncidents"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;nameField= "NAME"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;graffitiField= "OBJECTID"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;incidentsField= "INCIDENTS"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# sits above the first row, starts the cursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;patrolRows= arcpy.UpdateCursor(patrolZone)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# tells it to go to the first row&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;patrol= patrolRows.next()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# now were in the first row doing looping&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;while patrol:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(graffiti, "GraffitiLayer")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; zones= patrol.getValue(nameField)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print incidents&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryString = '"' + str(nameField) + '" = ' + "'" + str(zones) + "'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(queryString)&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; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(patrolZone, "PatrolLayer", queryString)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("GraffitiLayer", "CONTAINED_BY", "PatrolLayer")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; numGraffiti= arcpy.GetCount_management("GraffitiLayer")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print numGraffiti&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; patrol= patrolRows.next()&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would appreciate any help!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Nov 2011 15:31:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/aggregating-graffiti-incidents-with-python-script/m-p/8687#M723</guid>
      <dc:creator>Stephaniejohnson2</dc:creator>
      <dc:date>2011-11-04T15:31:56Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating graffiti incidents with python script</title>
      <link>https://community.esri.com/t5/python-questions/aggregating-graffiti-incidents-with-python-script/m-p/8688#M724</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi I need help with writing a script:&lt;BR /&gt;&lt;BR /&gt;The task&lt;BR /&gt;&lt;BR /&gt;I have a point feature class of graffiti incidents and a polygon feature class of patrol zones with some empty attributes already created for you. I must write a script that updates the attributes of the patrol zones with:&lt;BR /&gt;&lt;BR /&gt;�?� The number of graffiti incidents falling within the patrol zone. This is an integer that goes in the INCIDENTS field.&lt;BR /&gt;&lt;BR /&gt;�?� The priority ranking for the patrol zone. This is a string that goes in the PRIORITY field. You will derive this string using some simple math that compares the number of incidents in the zone with the area of the zone.&lt;BR /&gt;&lt;BR /&gt;Patrol zone priority rankings&lt;BR /&gt;&lt;BR /&gt;I then will calculate a priority ranking for each zone by dividing the number of graffiti incidents in the zone by the area of the zone. My script should then examine the result and assign the appropriate priority ranking (PRIORITY). These are the priority rankings:&lt;BR /&gt;&lt;BR /&gt;�?� TOP CONCERN�??15 or more incidents per square mile&lt;BR /&gt;�?� HIGH CONCERN�?? At least 12 but less than 15 incidents per square mile&lt;BR /&gt;�?� SOME CONCERN�?? At least 6 but less than 12 incidents per square mile&lt;BR /&gt;�?� LOW CONCERN�??Fewer than 6 incidents per square mile&lt;BR /&gt;&lt;BR /&gt;Here's what I have so far:&lt;BR /&gt;&lt;BR /&gt;import arcpy&lt;BR /&gt;arcpy.env.overwriteOutput= True&lt;BR /&gt;&lt;BR /&gt;# layer that we are changing&lt;BR /&gt;patrolZone= "C:\\...\\PoliceData.gdb\\PatrolZones"&lt;BR /&gt;# the layer we are selecting from&lt;BR /&gt;graffiti= "C:\\...\\PoliceData.gdb\\GraffitiIncidents"&lt;BR /&gt;nameField= "NAME"&lt;BR /&gt;graffitiField= "OBJECTID"&lt;BR /&gt;incidentsField= "INCIDENTS"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# sits above the first row, starts the cursor&lt;BR /&gt;patrolRows= arcpy.UpdateCursor(patrolZone)&lt;BR /&gt;&lt;BR /&gt;# tells it to go to the first row&lt;BR /&gt;patrol= patrolRows.next()&lt;BR /&gt;# now were in the first row doing looping&lt;BR /&gt;&lt;BR /&gt;while patrol:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(graffiti, "GraffitiLayer")&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; zones= patrol.getValue(nameField)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print incidents&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryString = '"' + str(nameField) + '" = ' + "'" + str(zones) + "'"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(queryString)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(patrolZone, "PatrolLayer", queryString)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("GraffitiLayer", "CONTAINED_BY", "PatrolLayer")&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; numGraffiti= arcpy.GetCount_management("GraffitiLayer")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print numGraffiti&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; patrol= patrolRows.next()&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I would appreciate any help!!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Use SpatialJoin_analysis (target_features, join_features, out_feature_class, {join_operation}, {join_type}, {field_mapping}, {match_option}, {search_radius}, {distance_field_name}).&amp;nbsp; target_features will by your polygon feature class. join_features will be your point feature class. {match_option} will be CONTAINS, in your case, means patrolZone contains graffiti incidents. The result feature classs will have a field Join_Count which indicates how many join features match each target feature, in your case, means how many graffiti incidents in each patrolZone. Then you can use CalculateField_management: count/SHAPE.area...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Nov 2011 18:39:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/aggregating-graffiti-incidents-with-python-script/m-p/8688#M724</guid>
      <dc:creator>HemingZhu</dc:creator>
      <dc:date>2011-11-04T18:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating graffiti incidents with python script</title>
      <link>https://community.esri.com/t5/python-questions/aggregating-graffiti-incidents-with-python-script/m-p/8689#M725</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you. I'm not sure how to do the write the script to calculate the "SHAPE_Area/2589988.11"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and then take that value and divide the # of incidents by it?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 05 Nov 2011 19:23:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/aggregating-graffiti-incidents-with-python-script/m-p/8689#M725</guid>
      <dc:creator>Stephaniejohnson2</dc:creator>
      <dc:date>2011-11-05T19:23:49Z</dc:date>
    </item>
  </channel>
</rss>

