Hi I need help with writing a script:
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:
- The number of graffiti incidents falling within the patrol zone. This is an integer that goes in the INCIDENTS field.
- 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.
Patrol zone priority rankings
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:
- TOP CONCERN—15 or more incidents per square mile
- HIGH CONCERN— At least 12 but less than 15 incidents per square mile
- SOME CONCERN— At least 6 but less than 12 incidents per square mile
- LOW CONCERN—Fewer than 6 incidents per square mile
Here's what I have so far:
import arcpy arcpy.env.overwriteOutput= True # layer that we are changing patrolZone= "C:\\...\\PoliceData.gdb\\PatrolZones" # the layer we are selecting from graffiti= "C:\\...\\PoliceData.gdb\\GraffitiIncidents" nameField= "NAME" graffitiField= "OBJECTID" incidentsField= "INCIDENTS" # sits above the first row, starts the cursor patrolRows= arcpy.UpdateCursor(patrolZone) # tells it to go to the first row patrol= patrolRows.next() # now were in the first row doing looping while patrol: arcpy.MakeFeatureLayer_management(graffiti, "GraffitiLayer") zones= patrol.getValue(nameField) #print incidents queryString = '"' + str(nameField) + '" = ' + "'" + str(zones) + "'" print str(queryString) arcpy.MakeFeatureLayer_management(patrolZone, "PatrolLayer", queryString) arcpy.SelectLayerByLocation_management("GraffitiLayer", "CONTAINED_BY", "PatrolLayer") numGraffiti= arcpy.GetCount_management("GraffitiLayer") print numGraffiti patrol= patrolRows.next()
I'm stuck on updating the INCIDENTS field