I am working through an open courseware project from PSU found at https://www.e-education.psu.edu/geog485/node/145
I am trying to use an update cursor in a while loop to perform an analysis on individual polygons within a multipart feature. However, the output is for the first row ad infinitum.
Here is what i have so far:
import arcpy arcpy.env.workspace = "c:/users/documents/arcgis/arcgis tutorials/psu tutorials/project3/policedata.gdb" arcpy.env.overwriteOutput = True # Declare variables for files and fields used in analysis incidents = "c:/users/documents/arcgis/arcgis tutorials/psu tutorials/project3/policedata.gdb/GraffitiIncidents" patrol_zones = "c:/users/documents/arcgis/arcgis tutorials/psu tutorials/project3/policedata.gdb/PatrolZones" incidents_layer = "IncidentsLayer" patrol_field = "NAME" cursor = arcpy.UpdateCursor(patrol_zones) zone = cursor.next() # Loop through each patrol zone while zone: try: arcpy.MakeFeatureLayer_management(incidents,"IncidentsLayer" ) zone_name = zone.getValue(patrol_field) print zone_name sql = patrol_field + " = " + "'" + zone_name + "'" # Make a feature layer for each zone arcpy.MakeFeatureLayer_management(patrol_zones, "CurrentZone", sql) # Make selection arcpy.SelectLayerByLocation_management(incidents_layer, "CONTAINED_BY", "CurrentZone") num_incidents = arcpy.GetCount_management(incidents_layer) print "Graffitti incidents = " + str(num_incidents) ## arcpy.Delete_management("CurrentZone") ## zone except: print "Could not perform analysis." del cursor
What in my code is causing the script to produce results only for the first row?