Hello, I am currently trying to use Arcpy to automate and autofill address attribute information on one or multiple selected points using multiple different polygon features that are also located in different GDB's. I found the following on google searches.
import arcpy
arcpy.env.overwriteOutput = True
# -------------------- Quadrant Codes --------------------
arcpy.SelectLayerByAttribute_management ("AddressMaster", "NEW_SELECTION", "STRT_NAM IS NULL")
arcpy.MakeFeatureLayer_management("I:\Workspace.gdb\Addressmaster", "lyr_address")
arcpy.MakeFeatureLayer_management("I:\Workspace.gdb\AddressQuad", "lyr_addressquad")
rows = arcpy.SearchCursor("lyr_addressquad")
for row in rows:
arcpy.SelectLayerByAttribute_management("lyr_addressquad", "NEW_SELECTION", "\"OBJECTID \" = " + str(row.getValue("OBJECTID")))
arcpy.SelectLayerByLocation_management("lyr_address", "INTERSECT", "lyr_addressquad", "", "NEW_SELECTION")
arcpy.CalculateField_management("lyr_address", "Quadrant", "'{0}'".format(str(row.getValue("Quadrant"))), "PYTHON_9.3", "")
# -------------------- ZIP Codes --------------------
arcpy.SelectLayerByAttribute_management ("AddressMaster", "NEW_SELECTION", "STRT_NAM IS NULL")
arcpy.MakeFeatureLayer_management("I:\Workspace.gdb\Addressmaster", "lyr_address")
arcpy.MakeFeatureLayer_management("I:\Workspace.gdb\ZIPCode2021", "lyr_ZIPcodes")
rows = arcpy.SearchCursor("lyr_ZIPcodes")
for row in rows:
arcpy.SelectLayerByAttribute_management("lyr_ZIPcodes", "NEW_SELECTION", "\"OBJECTID \" = " + str(row.getValue("OBJECTID")))
arcpy.SelectLayerByLocation_management("lyr_address", "INTERSECT", "lyr_ZIPcodes", "", "NEW_SELECTION")
arcpy.CalculateField_management("lyr_address", "ZIP", "'{0}'".format(str(row.getValue("ZCTA5CE"))), "PYTHON_9.3", "")
# -------------------- UGA Zones --------------------
arcpy.MakeFeatureLayer_management(r"I:\Workspace.gdb\Addressmaster", "lyr_address")
arcpy.MakeFeatureLayer_management(r"I:\Workspace.gdb\UGA", "lyr_UGA")
rows = arcpy.SearchCursor("lyr_UGA")
for row in rows:
arcpy.SelectLayerByAttribute_management("lyr_UGA", "NEW_SELECTION", "\"OBJECTID \" = " + str(row.getValue("OBJECTID")))
arcpy.SelectLayerByLocation_management("lyr_address", "INTERSECT", "lyr_UGA", "", "NEW_SELECTION")
arcpy.CalculateField_management("lyr_address", "UGA", "'{0}'".format(str(row.getValue("Jurisdiction"))), "PYTHON_9.3", "")
# -------------------- Parcels ID --------------------
arcpy.SelectLayerByAttribute_management ("AddressMaster", "NEW_SELECTION", "STRT_NAM IS NULL")
arcpy.MakeFeatureLayer_management("I:\Workspace.gdb\Addressmaster", "lyr_address")
arcpy.MakeFeatureLayer_management("I:\Workspace.gdb\ParcelsAndAssess", "lyr_parcels")
rows = arcpy.SearchCursor("lyr_parcels")
for row in rows:
arcpy.SelectLayerByAttribute_management("lyr_parcels", "NEW_SELECTION", "\"OBJECTID \" = " + str(row.getValue("OBJECTID")))
arcpy.SelectLayerByLocation_management("lyr_address", "INTERSECT", "lyr_parcels", "", "NEW_SELECTION")
arcpy.CalculateField_management("lyr_address", "PARCEL_NO", "'{0}'".format(str(row.getValue("Parcel_ID"))), "PYTHON_9.3", "")
This is my code so far that is currently working fine for ZIP codes, UGA zones (if combined with county polygon so there is no blanks or nulls) and Quadrant Codes, however, Parcels are a different story. When running this same code for parcels, it takes about an hour as its going row by row. I have tried using the "SUBSET_SELECTION" but it doesn't change anything. I have also tried doing a forced select by attribute at the very beginning on the points with a Null street name value (point was just created so it will always be null) still, nothing changes and it takes an hour to run.
Is there something I am missing that lets it use the points I have selected to spatially select the parcels so it doesn't search the whole layers database row by row and take an hour to run?
Bonus question: Is there a way I can use the SearchCurser and an else if statement for UGA so it can give a "No" for not located within a UGA
Any help would be greatly appreciated! Thank you.