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.
I am a little confused on what you mean by add your field, at what point of the model do you want me to add the field into based on your mobel? Also i am confused on the "Add Join" after the spaital join. what is the output of the spatial join suppose to be joining to?
Thanks for the replay.
Hi,
Here's a quick python snippet that will:
Definitely a bunch of assumptions in this and no error handling but it should get you going... Arcpy doesn't let us do spatial searches yet so you have to fallback on the "selectbylocation" tool .... it's heavy handed but works.
fc1 = "points" fc2 = "Polygons" lyr2 = arcpy.MakeFeatureLayer_management(fc2) with arcpy.da.UpdateCursor(fc1, ["SHAPE@", "SiteAddress", "Verifi"]) as cursor1: for row1 in cursor1: print row1 arcpy.SelectLayerByLocation_management(lyr2, "INTERSECT", row1[0]) with arcpy.da.SearchCursor(lyr2, ["SiteAddress"]) as cursor2: row2 = cursor2.next() print row2 row1[2] = "Match" if row1[1].lower() == row2[0].lower() else "No" print row1[2] cursor1.updateRow(row1)
I get the following.
Runtime error
Traceback (most recent call last):
File "<string>", line 5, in <module>
RuntimeError: The operation was attempted on an empty geometry.
Thanks for the reply.
Never mind i had the wrong layer in arcmap.
The code does work but i am trying to do all of them at one time. the code only does one at a time.
I am thinking i need to do a spatial join first.
It should loop all the features in the point feature class. If you're in ArcMap and you have any features selected it will only execute on those selected features so make sure you unselect all features in the point layer before running the code.
Hi,
Couple questions:
1. what version of ArcGIS are you running?
2. how are you running the script? Inside ArcMap/Catlog python window, IDLE, standalone, etc
3. It looks like the syntax highlighter or copy paste didn't get the correct indents for lines 6-8. I tried to edit the original post so make sure you get a clean copy or adjust your version.
4. Is your line 5 the same as mine? for row1 in cursor1: .... if so then something is wrong with the cursor. are all the names spelled correctly?
1. 10.2.2
2. In Arcmap python window
3. i did catch that indent and fixed before i ran the code.
4. row1 in cursor1:, same as you have it.
The names are spelled correctly. Although the polygon "SiteAddres" filed address are upper case for example, "2120 RANCH RD".
Where the polygons layers "SiteAddres" are proper case for example, "2120 Ranch Rd".