[Shape].Z
Both of the above suggestions work great, when run from the attribute table. I'd like to extend this, though, to creating a python program which reads all of the shapefiles in a workspace, adds a field for z, and updates with the appropriate value.For example, in a set of shapefiles that have PointZ values in meters, I'd like to add a field which captures the Z value in feet (from the source shapefiles, which are in meters). Not sure why I can't get this to work: import arcpy from arcpy import env env.workspace = "P:/path/to/some/directory" fcList = arcpy.ListFeatureClasses( ) for fc in fcList: arcpy.AddField_management( fc, "Z_feet", "DOUBLE", "10", "3" ) arcpy.CalculateField_management(fc, "Z_feet", "3.28083 * float(!SHAPE.CENTROID.Z!)", "PYTHON") In particular, !SHAPE.CENTROID.Z! seems to work in the field calculator (Python mode), but not in a Python program.Suggestions?
import arcpy from arcpy import env env.workspace = "P:/path/to/some/directory" fcList = arcpy.ListFeatureClasses( ) for fc in fcList: arcpy.AddField_management( fc, "Z_feet", "DOUBLE", "10", "3" ) arcpy.CalculateField_management(fc, "Z_feet", "3.28083 * float(!SHAPE.CENTROID.Z!)", "PYTHON")
Brackets only apply to VBA and VB Script fields. With python you use exclamation marks for fields. If you are at ArcGIS 10.0 or above, VBA is no longer supported by the Field Calculator and VB Script, which replaced it, cannot do geometry calculations. You have to use Python. Also you have to specify that you want the Centroid for a point feature class. So check the Python option and use:!Shape.Centroid.Z!
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.