#You have a point feature class of graffiti incidents and a polygon feature class of patrol zones with some empty attributes #already created for you. You 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 import arcpy arcpy.env.overwriteOutput = True PatrolZonesa = "D:/WCGIS/Geog485/Project3/PoliceData.gdb/PatrolZonesa" Graffiti = "D:/WCGIS/Geog485/Project3/PoliceData.gdb/GraffitiIncidents" GraffitiField = "INCIDENTS" ZoneField = "PRIORITY" query = arcpy.AddFieldDelimiters(PatrolZones, "NAMES") PatrolList = [] # array to hold list of values collected with arcpy.da.SearchCursor(PatrolZones, ["NAME"]) as cursor: # create search cursor # iterate through table and collect unique values for row in cursor: PatrolList.append(row[0]) del row del cursor arcpy.SpatialJoin_analysis( Graffiti, PatrolZonesa, "D:/WCGIS/Geog485/Project3/PoliceData.gdb/joinfc") # create search cursor for Patrol in PatrolList: ##print Patrol Incidents = 0 with arcpy.da.SearchCursor("D:/WCGIS/Geog485/Project3/PoliceData.gdb/joinfc", ["NAME"]) as cursor: for row in cursor: if row[0] == Patrol: Incidents += 1 ##print Incidents with arcpy.da.UpdateCursor(PatrolZonesa, ["NAME", GraffitiField, ZoneField, "SHAPE_Area"]) as cursor: for row in cursor: #Calculate area in square miles Area = row[3]/2589988.11 cityIDString = row[0] # check Patrol matches th patrol that the Incidents were calculated for and update that row only if cityIDString == Patrol: row[1] = Incidents cursor.updateRow(row) # Apply Concern ranking to the Patrol if Incidents/Area >= 15: row[2] = "TOP CONCERN" cursor.updateRow(row) elif Incidents/Area >= 12: row[2] = "HIGH CONCERN" cursor.updateRow(row) elif Incidents/Area >= 6: row[2] = "SOME CONCERN" cursor.updateRow(row) else: row[2] = "SOME CONCERN" cursor.updateRow(row)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question