Update cursor and SHAPE@XY token problem

7263
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
11 Replies
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)

PanagiotisChiotis
New Contributor

Hello Joshua,

You are right, I was thinking that the tuple of a feature's centroid X&Y coordinates could be replaced by a Point object (which stores coordinate pairs of X&Y values). And yes, the code works when I updated Line 15 to:

row[0] = (306400, 4098400)

However, for some funny reason, it works fine when running the script for a point feature class .

Anyway, thanks a lot, it really cleared things up!

Best regards,

Panagiotis

0 Kudos