arcpy.CalculateField_management(Maxtbl, "XCoord", "!shape.extent.XMax!", "PYTHON_9.3", "")
Solved! Go to Solution.
Thanks,
But I bet your fc is a line feature class. My feature class is a point. Does XMax work for points??
If you use a cursor, you can query each feature for its extent object, which has the properties you seek.
the Extent (arcpy) page in the Help should be of assistance.
There is a sample on that page that queries each feature in a fc for its extent, and prints the values
You would instead use an Update Cursor to perform the same query and then update the
table's fields you have provided for holding these values.
This seems very easy, but I cannot figure it out. I need to calculate the X-Coordinate and Y-Coordinate to the appropriate fields in my featureclass (XCoord, YCoord). I am trying something like this to no avail:arcpy.CalculateField_management(Maxtbl, "XCoord", "!shape.extent.XMax!", "PYTHON_9.3", "")
Maxtbl is set to: r"V:\is\work\mb\Util\MaximoMobile\geodb\TestSnappingSigns.gdb\MaximoSigns_Test" (my feature class).
The shape properties/methods don't seem to be documented very well--where do I find those?
Many of the geometry calculation examples are contained in this help page.
This specific example seems to match the one you are doing, but is written as though you are doing the calculation in Desktop:
Parser:
Python
Expression:
!shape.extent.XMax!
This was built using ModelBuilder and I know it works for my data.
# Import arcpy module
import arcpy
# Local variables:
CENTERLINE_ROUTES_MERGED = "\\\\Agency\\agencydfs\\Trans\\rfairhur\\Layers\\Centerline_Synch.gdb\\CL_Maint\\CENTERLINE_ROUTES_MERGED"
# Process: Calculate Field
arcpy.CalculateField_management(CENTERLINE_ROUTES_MERGED, "EXTENT_MAXX", "!Shape.extent.XMax!", "PYTHON_9.3", "")
It appears the syntax is identically configured to yours (assuming the fc name and field name were changed for our respective databases), so perhaps the problem is with the rest of your model. Possibly a lock is being placed on the fc that prevents the calculation from occurring or you mistyped something in the fc name.
Try capitalizing the word Shape in the calculation, since at 10.0 or later it gets picky about capitalization and in my fgdb Shape is capitalized.
Thanks,
But I bet your fc is a line feature class. My feature class is a point. Does XMax work for points??
No. It does not. There is no extent for a point, only for a buffer polygon around a point. For the X coordinate of the point itself you calculate the X of the point's Centroid. So it is:
!Shape.Centroid.X!
Here is the help that lists the valid geometry calculations allowed for each feature class type thro... There are several others available through the Field Calculator, like extent, but an extent means an object has at least the potential to have both height and width, which a point cannot have.
Thanks for That! Where is this documented? I'm having a hard time finding this kind of info.
Thanks,
But I bet your fc is a line feature class. My feature class is a point. Does XMax work for points??
The only reason it is hard to find it is that it doesn't exist. 😉 It is found in the user forum only as far as I have seen. Users had to do the same for VBA back when it used to work. So be grateful for the furums.