1

I have a set of points whose x and y coordinates I would like to add to the attribute table. The points are stored as a feature class in a geodatabase and I have ensured that they have the proper co-ordinate system (World Mercator).

I have tried using both Calculate Geometry Attribute and Calculate Field to add the data to the columns named X and Y but both just yield <Null> even though the tool runs successfully. For Calculate field, I am using the following Syntax:

X=!SHAPE.CENTROID.X!
Y=!SHAPE.CENTROID.Y!

Where am I going wrong?

I started testing at ArcGIS Pro 2.2.0 but have updated to 2.2.3 and the problem persists.

  • What is your syntax for Calculate Geometry Attribute? – smiller Oct 25 '18 at 3:19
  • @smiller: Target Field: 'X', Property: 'Point x-coordinate'. Target Field: 'Y', Property: 'Point y-coordinate'. – DotPi Oct 25 '18 at 3:22
  • 1
    See updated response and report back -- try just getting the !Shape!.X rather than !Shape!.centroid.X – smiller Oct 25 '18 at 3:37
  • 1
    Just out of interest the X and Y fields, are they set up as integer or string? – Keagan Allan Oct 25 '18 at 5:19
  • 1
    I just reran the model builder that was producing this shapefile a few more times and now it works! – DotPi Oct 25 '18 at 6:09
4

Partially, I believe the error is in the way the field is called. The exclamation marks (!) should surround the field name, but usually methods that come after the period should not be surrounded by exclamation marks. As commented by @MichaelStimson, this is case sensitive - so make sure centroid is lowercase.

Suggested modification (tested in ArcGIS Pro 2.1.2 and ArcMap 10.5):

!SHAPE!.centroid.x

And separately,

!SHAPE!.centroid.y
  • I had already tried Add Geometry Attribute. I also just tried your suggestion. But, no change. Still showing <NULL> even though the tool executes successfully. – DotPi Oct 25 '18 at 3:20
  • 2
    CENTROID should be centroid, python is case sensitive and will have a cow saying something like object has no property CENTROID. – Michael Stimson Oct 25 '18 at 3:28
  • The new edits for !SHAPE!.X throws error "AttributeError: DescribeGeometry: Get attribute X does not exist" – DotPi Oct 25 '18 at 3:42
  • Hmm, perhaps we could use the token !SHAPE@X! like what is described for SearchCursor – smiller Oct 25 '18 at 3:44
  • I was able to get !Shape!.centroid.x to work -- so I was wrong, need to use centroid even with points. – smiller Oct 25 '18 at 3:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.