brianmcleer

Populate a value in one feature class from value in another feature class using SearchCursor

Discussion created by brianmcleer on Jul 28, 2017
Latest reply on Aug 2, 2017 by CDow-esristaff

I have two feature classes:

   COH_Address (points)

   TAXLOTS_NOAT (polygons)

I am trying to find the best code for using a cursor to run through TAXLOTS_NOAT, grab the value for TLNO, and populate the field TLNO_GIS in the COH_Address feature class the TAXLOTS_NOAT feature class field TLNO.

 

import arcpy
# Local variables:
COH_Address = "C:\\Users\\mclbr\\Desktop\\AddressTest.gdb\\Places\\COH_Address"
TAXLOTS_NOAT = "C:\\Users\\mclbr\\Desktop\\AddressTest.gdb\\TAXLOTS_NOAT"
arcpy.MakeFeatureLayer_management(TAXLOTS_NOAT, "TAXLOTS_NOAT") 
rows = arcpy.SearchCursor("TAXLOTS_NOAT", "", "", "TLNO", "")
arcpy.MakeFeatureLayer_management(COH_Address, "COH_Address") 
for row in rows: 
    arcpy.SelectLayerByLocation_management("COH_Address", "HAVE_THEIR_CENTER_IN", "TAXLOTS_NOAT", "", "NEW_SELECTION") 
    arcpy.CalculateField_management("COH_Address", "TLNO_GIS", "%(row.TLNO)", "PYTHON")

Outcomes