I am trying to add XY extents to point and line features using the arcpy.AddGeometryAttributes_management
tool, but it throws an error:
RuntimeError Traceback (most recent call last) <ipython-input-13-6497264af48f> in <module>()
65 """
66 #this is failing, but don't know why...
---> 67 arcpy.AddGeometryAttributes_management(in_features, properties)#, length_unit, area_unit, coordinate_system)
68
69 #take first point, search for line with same min/max extent as point AND next point (thus in between points)
C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in AddGeometryAttributes(Input_Features, Geometry_Properties, Length_Unit, Area_Unit, Coordinate_System) 1977 return retval 1978 except Exception as e:
-> 1979 raise e 1980 1981 @gptooldoc('AddXY_management', None)
C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in AddGeometryAttributes(Input_Features, Geometry_Properties, Length_Unit, Area_Unit, Coordinate_System) 1974 from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject 1975 try:
-> 1976 retval = convertArcObjectToPythonObject(gp.AddGeometryAttributes_management(*gp_fixargs((Input_Features, Geometry_Properties, Length_Unit, Area_Unit, Coordinate_System), True))) 1977 return retval 1978 except Exception as e:
C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py in <lambda>(*args)
494 val = getattr(self._gp, attr)
495 if callable(val):
--> 496 return lambda *args: val(*gp_fixargs(args, True))
497 else:
498 return convertArcObjectToPythonObject(val)
RuntimeError: Object: Error in executing tool
My code:
in_features = "points_backup"#, "lines_backup"]
properties = "EXTENT"
length_unit = ""
area_unit = ""
coordinate_system = ""
arcpy.AddGeometryAttributes_management(in_features, properties)#, length_unit, area_unit, coordinate_system)
I commented out the length, area and coord sys as they are optional. This is near verbatim to the example code ESRI gives in the documentation of the AddGeometryAttributes_management
(http://pro.arcgis.com/en/pro-app/tool-reference/data-management/add-geometry-attributes.htm)
Update: I changed my original post to make in_features
a single feature class instead of a list of feature classes-this resolve that original issue, but now I get the error:
ExecuteError Traceback (most recent call last)
<ipython-input-7-c84e1f2e998a> in <module>()
65 """
66 #this is failing, but don't know why...
---> 67 arcpy.AddGeometryAttributes_management(in_features, properties)#, length_unit, area_unit, coordinate_system)
68
69 #take first point, search for line with same min/max extent as point AND next point (thus in between points)
C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in AddGeometryAttributes(Input_Features, Geometry_Properties, Length_Unit, Area_Unit, Coordinate_System)
1977 return retval
1978 except Exception as e:
-> 1979 raise e
1980
1981 @gptooldoc('AddXY_management', None)
C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in AddGeometryAttributes(Input_Features, Geometry_Properties, Length_Unit, Area_Unit, Coordinate_System)
1974 from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject
1975 try:
-> 1976 retval = convertArcObjectToPythonObject(gp.AddGeometryAttributes_management(*gp_fixargs((Input_Features, Geometry_Properties, Length_Unit, Area_Unit, Coordinate_System), True)))
1977 return retval
1978 except Exception as e:
C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py in <lambda>(*args)
494 val = getattr(self._gp, attr)
495 if callable(val):
--> 496 return lambda *args: val(*gp_fixargs(args, True))
497 else:
498 return convertArcObjectToPythonObject(val)
ExecuteError: Failed to execute. Parameters are not valid. ERROR 000800: The value is not a member of Point x-, y-, z-, and m-coordinates. Failed to execute (AddGeometryAttributes).
The in_feature
'points_backup'
is a Point feature class ('enterprise geodatabase Feature Class'), with no Z or M, but I only need to add extent fields (min/max X/Y). This feature is not registered as versioned or enabled archive, if that matters.
-
You're using Iron Python aren't you? Is this being run from within Iron Python or from an Esri python console (or DOS/CMD)?Michael Stimson– Michael Stimson2019年01月14日 23:24:09 +00:00Commented Jan 14, 2019 at 23:24
-
I am currently running it from Jupyter Notebooks (there is currently an issue and cannot use IDLE-I ultimately want this to be a stand alone script I can call) but I am seeing the same error in the python window from within ArcGIS Pro as well.m.Walker– m.Walker2019年01月14日 23:28:08 +00:00Commented Jan 14, 2019 at 23:28
-
It looks like you need to iterate your features (for thisFC in in_features: then substitute thisFC for in_features in your tool) as this tool accepts a single input and not a list of feature classes or layers. However your in_features list looks like layers and not proper feature classes, if you want to run this in CMD you will either need to set your environment workspace to where the in_features are or use the full path.Michael Stimson– Michael Stimson2019年01月14日 23:32:57 +00:00Commented Jan 14, 2019 at 23:32
-
I reduced the in_features to be just a single feature class (in_features = ["points_backup"]) and got a different error (saying my point fc is not a member of Point x-, y-, z-, and m-coordinates???), so that must have been the original issue: you cannot pass in multiple feature classes to that tool (unless like Michael said, you loop through a list of them, and hand them in separately).m.Walker– m.Walker2019年01月14日 23:56:10 +00:00Commented Jan 14, 2019 at 23:56
-
in_features = ["points_backup"] is still a list of one object. Can you edit your question and post your updated code please.Michael Stimson– Michael Stimson2019年01月15日 00:15:26 +00:00Commented Jan 15, 2019 at 0:15
1 Answer 1
I finally got this function working for both features I was trying to add the geometry features to. The original issue was that i was handing in a list when I needed to loop through the in_features list, the second issue was that a point feature and a line feature need to use different properties, which add different geometry fields to the feature classes:
Add geometry attributes to points and lines
arcpy.AddGeometryAttributes_management(db_and_owner + 'points_backup', 'POINT_X_Y_Z_M')
arcpy.AddGeometryAttributes_management(db_and_owner + 'tmp_lines_split', 'EXTENT')
I got rid of the property assignments and put the properties directly in the call to the function, and made two separate functions since they need different 'property' values.
For points, this adds POINT_X, and POINT_Y fields, and for lines it adds EXT_MIN_X, EXT_MIN_Y, EXT_MAX_X, and EXT_MAX_Y fields (http://pro.arcgis.com/en/pro-app/tool-reference/data-management/add-geometry-attributes.htm)