HI Guys,
I have two layers, polygon (in code "Poly" and "Points") and point, i want to upload polygon layer attribute to point using intersect (like spatial join). E.g in polygon i have A and B features, i wont to update their values in point layer features attributes which under polygons. When i run my code it runs, but uploads only one value from polygon layer, when i have two values fro different features.
Here is a code help me please:
import arcpy
>>> cur_pol = arcpy.da.SearchCursor("Poly","name")
>>> for row_pol in cur_pol:
... arcpy.SelectLayerByLocation_management("Points","INTERSECT","Poly","","NEW_SELECTION")
...
>>> for row in arcpy.da.SearchCursor("Points","my_field"):
... cursor = arcpy.UpdateCursor("Points")
... for row in cursor:
... row.SeniSvna = row_pol[0]
... cursor.updateRow(row)
...
Several things to comment on regarding the code itself.
Hi Joshua,
I did it like this, but still updates only sing one value from polygon:
with arcpy.da.SearchCursor("Poly","name") as cursor:
... for row_lsd in cursor:
... arcpy.SelectLayerByLocation_management("Points","INTERSECT","Poly","","NEW_SELECTION")
... with arcpy.da.UpdateCursor("Points",["name"])as cursor_a:
... for row_a in cursor_a:
... row_a[0]=row_lsd[0]
... cursor_a.updateRow(row_lsd)
Whats fields in the polygon layer and in the points layer are you using? Also what is the field mapping? For example What fields in the polygon layer update which fields in the points layer? If this doesn't make sense please let me know and I can explain it another way.
Dear jeremy,
Field (from which i want to move value into points layer) in polygon Layer('Poly' --- string) i have is called "NAMES" and in points Layer ('Points' --- ) is "NewName".
I try also this code:
Import arcpy
with arcpy.da.SearchCursor("Poly","NAMES") as cursor:
... for row_lsd in cursor:
... arcpy.SelectLayerByLocation_management("Points","INTERSECT","Poly","","NEW_SELECTION")
... with arcpy.da.UpdateCursor("Points",["NewName"]) as cursor_a:
... for row_a in cursor_a:
... row_a[0]=row_lsd[0]
... cursor_a.updateRow(row_lsd)
It makes update, but updates only one value from Polygon ('Poly'), E.G. i have two names - John and Mike, it update only Mike, even if points features is under John.
Thanks Guys, i did it, thank you for your help
If you have found responses helpful, you should mark them Helpful.
Dear Vakhtang_Zubiashvili,
Kindly share the updated code where it is updating the John and Mike both in the "Points" layer.
Thank you
Thank you so much...!!! 🙂