I have two types of spatial data. One is a geodatabase of parcel data by county in Florida, and the other is a shapefile containing wind_zones through out Florida (used for enforcing certain building codes). I want to create and populate two fields in the parcel data based on which county and which wind_zone they are in. I have found a post here: Assigning field value based on location without join that answers a similar question and is what I am basing my code off of, but I need to iterate this process through an entire geodatabase that contains ~70 counties. Is there a line of code that can be added to iterate through the geodatabase so I do not have to manually run the code for each county?
Here is the code I have so far:
import arcpy
# Set overwrite option
arcpy.env.overwriteOutput = True
# KEEPING ORIGINAL LAYERS (NOT CREATING ADDITIONAL "JOINED" LAYER)
# Create FeatureLayers
arcpy.MakeFeatureLayer_management("C:/Data/HAAS/parc_join/parcels_1.gdb", "lyr_parcels")
arcpy.MakeFeatureLayer_management("C:/wind_zones/All_WZs.shp", "lyr_windZones")
# Add a "LOCATED_WZ" & "WZ_CAT" field
arcpy.AddField_management("lyr_parcels", "Located_WZ", "TEXT", "", "", "20")
arcpy.AddField_management("lyr_parcels", "WZ_Cat", "SHORT")
# Create a search cursor for the WZs
rows = arcpy.SearchCursor("lyr_windZones")
for row in rows:
# What you'll do is select each WZ one at a time, and then select all the parcels in that WZ and calculate the "LOCATED_WZ" field
# NOTE: If you are using not using shapefiles, then you'll have to change the FID in the line below to OBJECTID (or similar)
arcpy.SelectLayerByAttribute_management("lyr_windZones", "NEW_SELECTION", "\"FID\" = " + str(row.getValue("FID")))
arcpy.SelectLayerByLocation_management("lyr_Parcels", "INTERSECT", "lyr_windZones", "", "NEW_SELECTION")
arcpy.CalculateField_management("lyr_parcels", "Located_WZ", "'{0}'".format(str(row.getValue("COUNTY"))), "PYTHON_9.3", "")
print "Finished processing " + str(row.getValue("COUNTY"))
# Create a search cursor for the WZs
rows = arcpy.SearchCursor("lyr_windZones")
for row in rows:
# What you'll do is select each WZ one at a time, and then select all the parcels in that WZ and calculate the fields
# NOTE: If you are using not using shapefiles, then you'll have to change the FID in the line below to OBJECTID (or similar)
arcpy.SelectLayerByAttribute_management("lyr_windZones", "NEW_SELECTION", "\"FID\" = " + str(row.getValue("FID")))
arcpy.SelectLayerByLocation_management("lyr_Parcels", "INTERSECT", "lyr_windZones", "", "NEW_SELECTION")
arcpy.CalculateField_management("lyr_parcels", "WZ_Cat", "'{0}'".format(str(row.getValue("DESCRIPT"))), "PYTHON_9.3", "")
print "Finished processing " + str(row.getValue("DESCRIPT"))
Because each county is it's own feature class, I suppose I don't need to add a new field to tell me county name, because I will already know which county it is in.