Cannot set input into parameter Coordinate_System using arcpy.AddGeometryAttributes
Since your feature class is in GCS_WGS_1984
, you don't need to specify any Coordinate System. Though, if you want to add coord_sys
explicitly, you can use one of those:
- EPSG code as string e.g. "4326"
- EPSG code as integer e.g. 4326
SpatialReference
object
# as string
arcpy.AddGeometryAttributes_management(parcel_feat, "POINT_X_Y_Z_M", "", "", "4326")
#OR as integer
arcpy.AddGeometryAttributes_management(parcel_feat, "POINT_X_Y_Z_M", "", "", 4326)
#OR as SpatialReference object
coord_sys = arcpy.SpatialReference(4326) # EPSG:4326 -> GCS_WGS_1984
arcpy.AddGeometryAttributes_management(parcel_feat, "POINT_X_Y_Z_M", "", "", coord_sys)
Another way is to specify the spatial Reference by name, for instance, Geographic Coordinate Systems/World/WGS 1984
.
The following snippet tested on ArcGIS 10.5 and worked as expected:
import arcpy
from arcpy import env
ws = env.workspace = r"F:\Ahmad\Test\PT"
fc = "Cities.shp"
sr = arcpy.SpatialReference("Geographic Coordinate Systems/World/WGS 1984")
geom = arcpy.AddGeometryAttributes_management(fc, "POINT_X_Y_Z_M","","",sr)
Here is the output:
POINT_X
and POINT_Y
are the new geometry columns added by the code above. As you can see, it is exactly the same coordinates specified in LATITUDE
and LONGITUDE
columns defined already.
The only thing I can guess is that the coordinate system parameter needs to be a coordinate system data type. You're passing a string "GCS_WGS_1984
", however, the documentation states that it should be a coordinate system instead.
Try modifying your code to declare coord_sys as follows:
coord_sys = arcpy.SpatialReference(4326)
The sample code in the documentation is a bit ambiguous, because they're setting the coordinate system to an empty string. However, before that, they set the environment coordinate system explicitly to the coordinate system of the input features. You could try that too. You could try getting the coordinate system of your feature class and then set it in the code to be the same.