I have a points layer and polygon layer , I need to compare field "SiteAddres" from the points layer to "SiteAddress" to the polygon layer and if it matches i need it to populate field "Verifi" with "Match" or if it doesn't match to populate "Verifi" with "No Match". Although i am not sure what would be the best way to achieve what i am trying to do because i am trying to compare address which will have upper case and lower case and spaces. I would prefer not to do a spatial join every time i need to verify and i looked into doing it with a python script but i am not sure how to do it?
I get no error but nothing the field "Verifi" doens't get populated with "Match" or "No Match"
fc1 = "Points" fc2 = "Polygons" cursor1 = arcpy.da.SearchCursor(fc1, ["SiteAddres", "Verifi"]) cursor2 = arcpy.da.SearchCursor(fc2, ["SiteAddres"]) for row1 in cursor1: for row2 in cursor2: if row2[0] == row1[0]: for row1 in cursor1: row1[1] = "Match" else: row1[1] = "No Match"
I tried spatially joining the two layers and using field calculator but i am getting an invalid syntex error on line 2.
def ifBlock( SiteAddres , [SiteAddr_1 ): if SiteAddres = =SiteAddr_1: return "Match" else: return" No Match" ifBlock( SiteAddres , SiteAddr_1 )
Thanks.
Solved! Go to Solution.
python parser
#code block def ifBlock( SiteAddres , SiteAddr_1 ): if SiteAddres == SiteAddr_1: return "Match" else: return "No Match" #expression block ifBlock( !SiteAddres! , !SiteAddr_1! )
Hi,
For your bottom block of code, using an If statement, you need to put the equal signs together
if SiteAddres == SiteAddr_1:
Plus, in the def area, in the bottom block of code, it looks like you have an open bracket without a closed bracket.
And you might need to indent more in the bottom block as well (4 spaces for an indent).
I changed it to the following but i get Error 000539:,
which states...
"This error code covers a number of Python errors:
The above is a Python-specific error. The calculation is attempting to add or concatenate a string and a number. "
def ifBlock( SiteAddres , SiteAddr_1 ): if SiteAddres == SiteAddr_1 : return "Match" else: return "NoMatch" ifBlock( SiteAddres , SiteAddr_1)
python parser
#code block def ifBlock( SiteAddres , SiteAddr_1 ): if SiteAddres == SiteAddr_1: return "Match" else: return "No Match" #expression block ifBlock( !SiteAddres! , !SiteAddr_1! )
Hi Dan.
The after making the following like you suggest it ran" ifBlock( !SiteAddres! , !SiteAddr_1! )".
but all the records returned as "No Match". I just realized that the attributes in SiteAddr_1 are all uppercase and that the SiteAddres are proper case. I had to change the following.
if SiteAddres.lower() == SiteAddr_1.lower():
Thanks!
To update the data the first cursor needs to be an update cursor and after setting the value for the field you'd want to call the updateRow method to commit it.
See the example at the bottom of the following page.
I have tried the following but nothing happens i get no error either.
fc1 = "Points" fc2 = "Polygons" cursor1 = arcpy.da.SearchCursor(fc1, ["SiteAddres", "Verifi"]) cursor2 = arcpy.da.SearchCursor(fc2, ["SiteAddres"]) # Create update cursor for feature class with arcpy.da.UpdateCursor(fc1, "Verifi") as cursor: for row1 in cursor1: for row2 in cursor2: if row2[0] == row1[0]: for row1 in cursor1: row1[1] = "Match" else: row1[1] = "No Match" # Update the cursor with the updated list cursor.updateRow(row)
You could set up a model that does:
or do your spatial join in model builder and export to python and use the resulting field as an input to the following script. The script prints the oids of the non matching of both feature classes you could easily modify to get what you need
#Script to compare 2 feature classes #Author Wes Miller import arcpy import numpy as np import datetime #Print start time and date dt = datetime.datetime.now() print dt #The Feature Class to Check originFC = arcpy.GetParameterAsText(0) #The feature class with updates needed for feature class above changeFC = arcpy.GetParameterAsText(1) origDesc = arcpy.Describe(originFC) oidName = origDesc.oidFieldName field_names = arcpy.GetParameterAsText(2)#Example: "Shape","TMS","OWNERNAME","TOTBDGVAL","DISTRICT","ADD1","ADD2","ADD3","MAP","BLOCK","PARCEL","CALCULATED_ACREAGE","ADDR_SITE" originFCarr = arcpy.da.FeatureClassToNumPyArray(originFC,(field_names),null_value=-9999) originFCarrID = arcpy.da.FeatureClassToNumPyArray(originFC,(oidName)) changeFCarr = arcpy.da.FeatureClassToNumPyArray(changeFC,(field_names),null_value=-9999) changeFCarrID = arcpy.da.FeatureClassToNumPyArray(changeFC,(oidName)) print "Arrays Complete" count = 0 deletesarr = np.where(np.invert(np.in1d(originFCarr,changeFCarr))) addsarr = np.where(np.invert(np.in1d(changeFCarr,originFCarr))) adds = [] for each in addsarr[0]: adds.append(changeFCarrID[each][0]) deletes = [] for each in deletesarr[0]: deletes.append(originFCarrID[each][0]) #Current Outputs are printed here for testing purposes print adds print print deletes ndt = datetime.datetime.now() print ndt
I did try making a model with model builder but i did not have any success.
Add your field or create a copy and add a field then make your model similar to the one below.