Update cursor and SHAPE@XY token problem

7164
11
Jump to solution
05-11-2015 05:44 AM
PanagiotisChiotis
New Contributor

Hello everyone,

I am new to Python and ArcPy.

I am testing the script below which is running for a point feaure class, but not for a line feature class.

  1. import arcpy
  2. arcpy.env.workspace = r"D:\Student\PYTH\6_Geometry_objects\SanDiego.gdb"
  3. # Variables
  4. featClass = "MajorAttractions2"
  5. fields = ["SHAPE@XY"]
  6. exp = "OBJECTID = 4"
  7. pnt = arcpy.Point()
  8. pnt.X = 306400
  9. pnt.Y = 4098400
  10. with arcpy.da.UpdateCursor(featClass, fields, exp) as cur:
  11.     for row in cur:
  12.         row[0] = pnt
  13.         cur.updateRow(row)
  14. print "Script completed"

In the latter case, I am getting the following error message: "exceptions.SystemError: error return without exception set" for line 16.

Thank you in advance,

Panagiotis

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

The "SHAPE@XY" token doesn't return an ArcPy Point object, it returns "a tuple of the feature's centroid x,y coordinates."  Line 15 of your code replaces a Python tuple with an ArcPy Point object, which is what I am guessing is causing the error on Line 16.  Does the code work if you update Line 15 to:

row[0] = (306400, 4098400)

View solution in original post

11 Replies
DarrenWiens2
MVP Honored Contributor

Ignoring the fact that you are trying to create a line from a single point (which surprisingly works), does the line feature class contain a feature at OBJECTID = 4?

0 Kudos
PanagiotisChiotis
New Contributor

Hello Darren,

I am not trying to create a line feature class, but rather shift a feature of it. Both point and line feature classes already exist. And, yes, "OBJECTID = 4" is a valid expression in both cases.

Regards,

Panagiotis

0 Kudos
OwenEarley
Occasional Contributor III

SHAPE@XY for a line feature will return the feature centroid. You will need to use SHAPE@ and then locate the vertex point on the polyline to update.

These pages have more detail:

DarrenWiens2
MVP Honored Contributor

I thought you had to do it vertex by vertex, too, but this post seems to disagree: https://arcpy.wordpress.com/2012/11/15/shifting-features/

It shifts geometry all as one.

OwenEarley
Occasional Contributor III

Good catch - I hadn't seen that post.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

You didn't catch it because documenting important functionality like that on a third-party blogging platform is, well, poor taste.  It would be nice and a bit more enterprise-y if the ArcGIS Python development team did more blogging within an Esri domain, say GeoNet maybe.

0 Kudos
DanPatterson_Retired
MVP Emeritus
  1. exp = "OBJECTID = 4"  are you sure it is a valid where clause, it looks like an assignment statement, did you try
  2. exp = "OBJECTID == 4"
DarrenWiens2
MVP Honored Contributor

1. Should be correct through SQL goggles.

DanPatterson_Retired
MVP Emeritus

​sigh.... python googles always on