I have the following python script that creates a feature layer from an attribute selection. The layer ‘zipcodes’ has a field with multiple zipcodes and instead of writing the following code over again for each particular zipcode I want to write a for loop that performs the following for each separate zipcode.
I have gotten as far as getting the value of the different zipcodes, but how would I write it so that I can create a selection of parcels by the selection statement?
Code:
import arcpy
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "workspace path"
zipcodes = "shapefile location"
parcels = “sde feature location”
arcpy.MakeFeatureLayer_management(zipcodes, "zipcodes_lyr")
arcpy.SelectLayerByAttribute_management("zipcodes_lyr", "NEW_SELECTION", """ "NAME" = '27012' """)
arcpy.CopyFeatures_management("zipcodes_lyr", "zip27012")
arcpy.MakeFeatureLayer_management(parcels, "parcel_lyr")
arcpy.SelectLayerByLocation_management("parcel_lyr", 'HAVE_THEIR_CENTER_IN',
" zip27012.shp")
arcpy.CopyFeatures_management("parcel_lyr", "27012")
arcpy.Delete_management("zip27012.shp")
Code:
import arcpy
import os
import sys
zipcodes = "zipcodes.shp"
name = "NAME"
rows = arcpy.SearchCursor(zipcodes)
row = rows.next()
arcpy.MakeFeatureLayer_management(zipcodes, "zipcodes_lyr")
for row in arcpy.SearchCursor(zipcodes):
value = row.getValue(name)
for value in row.getValue(name):
arcpy.SelectLayerByAttribute_management(??)