I am trying to update the points selected features field "Verifi2" with "Match" or "No" based on if the 'SiteAddres' field of the selected feature matches the parcels layer 'SiteAddress' field. I currently have the following code but all of the selected features have "No" in the Verifi2 field. Which is not the case because some of the selected point features SiteAddres does match parcels SiteAddress. I would appreciate some help please.
import arcpy
from datetime import datetime as d
startTime = d.now()
fc1 = "AddresPointsTest"
fc2 = "TaxParcels1"
#set up cursors
cursor1 = arcpy.da.SearchCursor(fc1, ["SiteAddres", "Verifi2"])
cursor2 = arcpy.da.SearchCursor(fc2, ["SiteAddress"])
with arcpy.da.UpdateCursor(fc1, ["SiteAddres", "Verifi2"]) as cursor1:
for row1 in cursor1:
with arcpy.da.SearchCursor(fc2, ["SiteAddress"]) as cursor2:
row2 = cursor2.next()
#print row2
row1[1] = "Match" if row1[0].lower() == row2[0].lower() else "No"
#print row1[2]
cursor1.updateRow(row1)
try:
print '(Elapsed time: ' + str(d.now() - startTime)[:-3] + ')'
except Exception, e:
# If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
print "Line %i" % tb.tb_lineno
print e.message
I am still getting all 'No'.
Looking at my data i noticed that the OID@ on both layers where not matching so i had to change the OID@, my apologies. Once i changed the uniqueID and ran the script i get error.
line 18, in <module>
if [row[1]].strip().lower() != addDict[row[0]].strip().lower(): #if the value associated with those ids do not match
AttributeError: 'list' object has no attribute 'strip'
code
import arcpy
from datetime import datetime as d
startTime = d.now()
fc1 = r'C:\Temp\TaxParcels1.shp'
fc2 = r'C:\Temp\AddresPointsTest.shp'
#build a dictionary of OBJECTID : Address pairs, change OID@ to your uniqueID
addDict = {row[0]:row[1] for row in arcpy.da.SearchCursor(fc1, ['ACCOUNT','SiteAddress'])}
#search through fc2 to see if addresses match based on OBJECTID value
#again, change OID@ to your uniqueID
with arcpy.da.UpdateCursor(fc2, ['Account','SiteAddres','Verifi2']) as cursor:
for row in cursor:
if row[0] in addDict:
if row[1].strip().lower() != addDict[row[0]].strip().lower(): #if the value associated with those ids do not match
row[2] = 'No'
else:
row[2] = 'Match'
cursor.updateRow(row)
del cursor
try:
print '(Elapsed time: ' + str(d.now() - startTime)[:-3] + ')'
except Exception, e:
# If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
print "Line %i" % tb.tb_lineno
print e.message
You need to look up how those functions work...
Sorry, i am not understanding that line. .strip()
removes all whitespace and .lower() and lower() method converts all of the characters to lowercase. Not sure why it's given me that error but thank you very much for the assistance.
Hi, see if this tool does what you need:
http://pm.maps.arcgis.com/home/item.html?id=e638afe0695a4ad38388cb8d9b350446