ArcMap Field Calculator: Calculating Geometry using arcpy

One of the things I had not gotten around to doing in ArcGIS 10 was figure out how to directly manipulate the geometry of a record using the Field Calculator.  When I stumbled upon a bug in the way the Extract Values to Points tool handles Null geometries, I figured it was time to figure it out.  Setting the X, Y to 0,0 was sufficient for my needs.

I set the Parser to Python and the formula was simple once I figured out the syntax:

pPoint = arcpy.Point(0,0)

Then, to extend my knowledge, I wanted to see how to calculate the geometry based off of two fields (X and Y).   The only real trick is knowing the bracket field names using exclamation points instead of brackets:


So turns out everything it pretty easy and straight-forward.  Whew!


5 thoughts on “ArcMap Field Calculator: Calculating Geometry using arcpy

  1. First of all, great post!

    What script would you use to extract the geometry from the field? Can you do that in ArcGIS 10? I’ve got a bunch of points that I would love to pull the x,y coordinates out of in the field calculator if at all possible.
    I know you can just hit ‘calculate geometry’, but that doesn’t work well in model builder (or doesn’t exist, really). Any suggestions?

    • This is pretty old, but I found this post looking for an answer to the very question asked here by Royce. An alternative to Matthew’s answer below involves a situation where your data already have “X” and “Y” attributes. If this is the case, in ModelBuilder, drop in the Calculate Field tool and use the !shape.extent.XMax! expression for your “X” and !shape.extent.YMax! for your “Y”. Surprisingly easy!

  2. Thanks for reading and posting!

    I would start out using the “Add XY Coordinates” tool (Data Management Tools-Features-Add XY Coordinates). The downside to this tool is that it you don’t have any control over the field names–the location is automatically put into POINT_X and POINT_Y.

    If you need more flexibility, than that, I would lean towards writing an arcpy script that accepts a point shapefile and the field names as 3 parameters.

    Good Luck!

  3. Just a short remark for those making use of this excellent tip:

    Be careful using arcpy.Point(!X!,!Y!) outside an edit session, because it will affect all points regardless of any selection.

    If you want to change geometry within a selection only, start an edit session.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s