Get Point XY from update cursor

767
2
Jump to solution
08-15-2019 02:02 AM
StuartMoore
Occasional Contributor III

I'm using an update cursor to populate some fields which works fine but i want to get the XY of the point at the same time but i get an error: 

999999: Error executing function

this is my code:

			UpdRPoint = arcpy.UpdateCursor(NearXY_Lyr)
			for RP in UpdRPoint:

				Desc_1 = RP.getValue("DESCRIPTION_1")
				
				x, y = RP.getValue("SHAPE@XY")
				messages.addMessage("{}, {}".format(x, y))

any ideas why its not working?

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

have you provided the full path to NearXY_Lry somewhere?

Can you print Desc_1?

I would use the newer da.UpdateCursor and acquire the Shape@XY and your other field all at once

UpdateCursor—Data Access module | ArcGIS Desktop 

fc = 'c:/full_path_to.gdb/well'
fields = ['DESCRIPTION_1', 'SHAPE@XY']

# Create update cursor for feature class 
with arcpy.da.UpdateCursor(fc, fields) as cursor:
    for row in cursor:
        #do the stuff here

View solution in original post

2 Replies
DanPatterson_Retired
MVP Emeritus

have you provided the full path to NearXY_Lry somewhere?

Can you print Desc_1?

I would use the newer da.UpdateCursor and acquire the Shape@XY and your other field all at once

UpdateCursor—Data Access module | ArcGIS Desktop 

fc = 'c:/full_path_to.gdb/well'
fields = ['DESCRIPTION_1', 'SHAPE@XY']

# Create update cursor for feature class 
with arcpy.da.UpdateCursor(fc, fields) as cursor:
    for row in cursor:
        #do the stuff here
StuartMoore
Occasional Contributor III

thanks Dan that worked a treat

UpdRPoint = arcpy.da.UpdateCursor(NearXY_Lyr, ["DESCRIPTION_1","SHAPE@XY"])
	for RP in UpdRPoint:
		Desc_1 = RP[0]
		x, y = RP[1]
		messages.addMessage("{}, {}".format(x, y))‍‍‍‍‍‍‍‍‍‍‍‍