Can't change points from attribute

455
9
Jump to solution
11-17-2016 06:41 AM
JoannaGrossman2
New Contributor III

HI all - Currently I'm getting:

Runtime error
Traceback (most recent call last):
  File "<string>", line 14, in <module>
AttributeError: 'module' object has no attribute 'updateCursor'

from the following code:

# Move points based up current lat/lon
#grab stuff you need
import arcpy, os

#filepath
filepath = r"C:\Users\joanna.grossman\AppData\Roaming\ESRI\Desktop10.4\ArcCatalog\AGR_SecureProd__AGR_Admin.sde"

#get feature class, feidds
fc = "GDB_AGR_SECURE.AGR_ADMIN.ApiariesWGS_20160927"
lat = "Latitude"
lon = "Longtitude"

#create curser on fc
cursor = arcpy.da.updateCursor(fc, ["SHAPE@XY"])
row = cursor.next()

#get points
pnt = arcpy.Point()

while row:
    x = row.getValue(lon)
    y = row.getValue(lat)
    xy = (x,y)
    #pnt = arcpy.Point(xy)
    #pnt_geometry = arcpy.PointGeometry(pnt)
    print x
    print xy
    #print(pnt_geometry.getGeohash(6))
    #row.shape = pnt  
    cursor.updateRow([xy])
    row = cursor.next()

I'm a total Python/arcpy noob. Would really appreciate your feedback.

0 Kudos
1 Solution

Accepted Solutions
MitchHolley1
MVP Regular Contributor

Capitalize the 'u'.  

cursor = arcpy.da.UpdateCursor(fc, ["field"])

View solution in original post

9 Replies
MitchHolley1
MVP Regular Contributor

Capitalize the 'u'.  

cursor = arcpy.da.UpdateCursor(fc, ["field"])

JoannaGrossman2
New Contributor III

wow. Thanks!

0 Kudos
BlakeTerhune
MVP Regular Contributor

I think Mitch Holley‌ has identified the issue causing the error you posted. Here's the documentation for UpdateCursor. However, I think you will have some additional issues with how you're using the UpdateCursor. Check out the code samples in the help documentation for some guidance.

Also, Posting code with Syntax Highlighting on GeoNet 

JoshuaBixby
MVP Esteemed Contributor

Blake is spot on.  You are mixing the usage patterns of the old cursors and newer Data Access cursors.  Specifically, getValue() doesn't apply with the newer Data Access cursors.

JoannaGrossman2
New Contributor III

okay. I'm learning things! So the way to get a value now is to grab it from a stack of fields?

0 Kudos
MitchHolley1
MVP Regular Contributor

Yeah, if you're trying to update geometries based on a Lat and Long field. It would look something like this: 

JoannaGrossman2
New Contributor III

I don't have to create a point or anything?

Like any of this...

pnt = arcpy.Point(xy)
pnt_geometry = arcpy.PointGeometry(pnt)

?

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I encourage you to read Accessing data using cursors.  Mitch is using "tokens" to access the spatial object.  The tokens are a form of shortcut/optimization that can be used to simplify working with geometry objects in data tables.

JoannaGrossman2
New Contributor III

will do - thank you!

0 Kudos