I have a point shapefile where I want to add two new fields "Lat" and "Long" and calculate the X and Y coordinates in decimal degrees for each field in the coordinate system: WGS 84 (EPSG-Code 4326).
This is my code so far for calculating the "Lat" field in "Point_X" geometry_propery:
# Add "Lat" field
arcpy.management.AddField("routenplanung", "Lat", "FLOAT")
# Add "Long" field
arcpy.management.AddField("routenplanung", "Long", "FLOAT")
# "Calculate Geometry" in Decimal Degrees with Output-CS WGS 1984
arcpy.management.CalculateGeometryAttributes("routenplanung",
["Lat", "POINT_X"],
coordinate_system="WGS 1984",
coordinate_format="DD",
length_unit="",
area_unit="")
I get this error message:
---------------------------------------------------------------------------
ExecuteError Traceback (most recent call last)
In [20]:
Line 8: arcpy.management.CalculateGeometryAttributes("routenplanung",
File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py, in CalculateGeometryAttributes:
Line 4254: raise e
File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py, in CalculateGeometryAttributes:
Line 4251: retval = convertArcObjectToPythonObject(gp.CalculateGeometryAttributes_management(*gp_fixargs((in_features, geometry_property, length_unit, area_unit, coordinate_system, coordinate_format), True)))
File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py, in <lambda>:
Line 512: return lambda *args: val(*gp_fixargs(args, True))
ExecuteError: ERROR 000622: Failed to execute (Calculate Geometry Attributes). Parameters are not valid.
ERROR 000628: Cannot set input into parameter coordinate_system.
---------------------------------------------------------------------------
I tried different variations for the parameter "coordinate_system" like:
coordinate_system="PROJCS['WGS_1984_UTM_Zone_12N',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-111.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]"
or
coordinate_system="EPSG 4326"
But nothing works. What value should I use?
coordinate_system
, you are try a geographic coordinate system and the other you are trying a projected coordinate system. Which one specifically are you interested in?arcpy.SpatialReference(4326)
as a parameter? or a.exportToString().split(';')[0]