# How do I convert from Lat/Long (DD) or East/North TO Lat Long (DMS)?

2521
4
07-11-2016 06:12 PM
Occasional Contributor III

Hi All,

I have never worked with coordinates other than Easting Northings, and today I have been given a table that contains Eastings and Northings, and another two columns with Lat Long (DD). Unfortunately my client requires a table with Lat Long shown in Degrees Minutes and Seconds, and this is not something I have ever had to do so I have some questions.

1. When I create the fields which will hold the Lat Long data in DMS, what type (format) should the field be? I am assuming a double is not sufficient?
2. Is there a simple field calculator tool that takes a column (Easting) for example, and spits out the Latitude in DMS format?

I am very new to coordinate conversion, so any tips are appreciated.

Tags (2)
1 Solution

Accepted Solutions
MVP Legendary Contributor
4 Replies
MVP Legendary Contributor
Occasional Contributor III

Great suggestion, looks like it will do exactly what I want, but im getting the error every GIS User wants to see 'Error 999999' with the below code

# imports
import arcpy

arcpy.env.workspace = r"F:\Nathan Duncan\Assets & Planning\2015-2016\Sewer Sample Points\SewerSamplePoints.gdb"

# set parameter values
input_table = r'F:\Nathan Duncan\Assets & Planning\2015-2016\Sewer Sample Points\TempSampSite.shp'
output_points = r'F:\Nathan Duncan\Assets & Planning\2015-2016\
Sewer Sample Points\SewerSamplePoints.gdb\CoordConversion\DMS'
x_field = "Longitude"
y_field = "Latitude"
input_format = "DD_2"
output_format = "DDM_2"
spatial_ref = arcpy.SpatialReference('WGS 1984')

try:
arcpy.ConvertCoordinateNotation_management(in_table=input_table, out_featureclass=output_points,
x_field=x_field, y_field=y_field,
input_coordinate_format=input_format,
output_coordinate_format=output_format
)
print(arcpy.GetMessages(0))

except arcpy.ExecuteError:
print(arcpy.GetMessages(2))

except Exception as ex:
print(ex.args[0])

ERROR 999999: Error executing function.

Failed to execute (ConvertCoordinateNotation).

MVP Legendary Contributor

well... I missed the part where you said you need to creat a script...

Run it once manually... go to the Results window, examine and emulate the syntax

Occasional Contributor III

I don't need to create a script, this is me running it (just using the sample code on the page you provided me)...

By removing the try: and except components (converting from a script to a run once type setup as Dan suggested) I got a more accurate Error Message saying:

Traceback (most recent call last):

File "F:/Ben VK/Conver LatLong DD to LatLong DMS.py", line 19, in <module>

output_coordinate_format=output_format

File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\management.py", line 8663, in ConvertCoordinateNotation

raise e

arcgisscripting.ExecuteError: ERROR 999999: Error executing function.

Failed to execute (ConvertCoordinateNotation).

Upon closer inspection, it seems I was using output_format = "DDM_2" instead of the correct output_format = "DMS_2", now works like a charm.

Thanks for your help Dan, that tool is perfect for my scenario.

Cheers

Final working code for all those playing along at home:

input_table = r'F:\Nathan Duncan\Assets & Planning\2015-2016\Sewer Sample Points\TempSampSite.shp'
output_points = r'F:\Nathan Duncan\Assets & Planning\2015-2016\Sewer Sample Points\SewerSamplePoints.gdb\CoordConversion\DMS'
x_field = "Longitude"
y_field = "Latitude"
input_format = "DD_2"
output_format = "DMS_2"
spatial_ref = arcpy.SpatialReference('WGS 1984')

arcpy.ConvertCoordinateNotation_management(
in_table=input_table,
out_featureclass=output_points,
x_field=x_field,
y_field=y_field,
input_coordinate_format=input_format,
output_coordinate_format=output_format
)