Convert Coordinate Notation (Data Management)
Summary
Converts coordinate notations representing locations from one format to another.
Usage
The input table can be a text file or any table supported by ArcGIS.
The output is a point feature class where each input location with a valid notation is represented as a point. The records with invalid notations will not have any geometry and newly added output fields will be empty.
The IDs of the records with invalid notations that fail to convert are listed in a text file named ConvertCoordinateNotation<x>.log (<x> is an arbitrary number). The file is stored in the user's Temp folder. For example, in Windows 7, the directory is Users\<user>\AppData\Local\Temp. In UNIX systems, the file is located in the user's home directory, under $TMP.
The following formats are supported:
- Decimal degrees (DD)
- Degrees decimal minutes (DDM)
- Degrees-minutes-seconds (DMS)
- Global Area Reference System (GARS)
- GEOREF (World Geographic Reference System)
- Universal Transverse Mercator (UTM)
- United States National Grid (USNG)
- Military Grid Reference System (MGRS)
Any format can be used as the input or output format. For example, DMS can be used as both input and output format to convert values and obtain a point feature class for the locations.
DD_1, DDM_1, and DMS_1 require two values to represent a location: one for latitude and the other for longitude. The two values are concatenated into a single string and stored in a single field.
For DD_2, DDM_2, and DMS_2 the latitude and longitude values are represented by two separate fields.
GARS, GEOREF, UTM, USNG, and MGRS are single-string coordinate formats, meaning only one field contains the coordinate.
See the Input Coordinate Format parameter explanation below for more information.
All non-system fields from the input table, including the input format fields, are transferred to the output point feature class.
Output field names are matched to the name of the output coordinate notation. For example, if the output format is MGRS, then the new output field name will be MGRS.
If a field with the same name as the input field already exists in the output, the name of the copied field is appended with a unique number.
The Add XY Coordinates tool can be used to add two fields—POINT_X and POINT_Y—to the output point feature class. These fields contain the coordinates of a point in the unit of the coordinate system of the feature class.
Syntax
Parameter | Explanation | Data Type |
in_table |
The table containing the fields with coordinate notations to convert. | Table View |
out_featureclass |
The output feature class of points. The attribute table will contain all fields of the input table along with the fields containing converted values in the output format. | Feature Class |
x_field |
A field from the input table containing the longitude value. For DD_2, DDM_2, and DMS_2, this is the longitude field. For DD_1, DDM_1, DMS_1, GARS, GEOREF, UTM, USNG, and MGRS, this is the field containing both latitude and longitude. | Field |
y_field |
A field from the input table containing the latitude value. For DD_2, DDM_2, and DMS_2, this is the latitude field. This parameter is ignored for DD_1, DDM_1, DMS_1, GARS, GEOREF, UTM, USNG, and MGRS. | Field |
input_coordinate_format |
Coordinate format of the input fields. The default is DD_2.
DD, DDM, and DMS are also valid keywords; they can be used just by typing in (on dialog) or passing the value in scripting. However, keywords with underscore and a number tell whether the values are coming from one field or two fields. | String |
output_coordinate_format |
Coordinate format to which the input notations will be converted. The default is DD_2.
DD, DDM, and DMS are also valid keywords; they can be used just by typing in (on dialog) or passing the value in scripting. However, keywords with underscore and a number tell whether the values are coming from one field or two fields. | String |
id_field (Optional) |
Any field from the input table. The selected field will be copied to the output table. If the values of this field are unique, this may be used to join the output records back to the input table. | Field |
spatial_reference (Optional) |
Spatial reference of the output point feature class. The default is GCS_WGS_1984. If the output has a different coordinate system than the input, then the tool projects the data. If the input and output are in different datum, then a default transformation is calculated based on the coordinate systems of the input and the output, and the extent of the data. | Spatial Reference |
Code Sample
ConvertCoordinateNotation usage with one input format field.
#Imports
import arcpy
#Locals
in_tab = r"c:\workspace\inmed.gdb\loc_mgrs"
out_pts = r"c:\workspace\inmed.gdb\loc_final"
#Convert Coordinate Notation with MGRS as input field.
arcpy.ConvertCoordinateNotation_management(in_tab,out_pts,"m10d","#","MGRS","DD_1")
ConvertCoordinateNotation usage with two input format fields.
# imports
import arcpy
arcpy.env.workspace = r"c:\data\mtf.gdb"
# set parameter values
input_table = 'rit_up_DD'
output_points = 'ritLOC'
x_field = 'LON'
y_field = 'LAT'
input_format = 'DD_2'
output_format = 'GARS'
id_field = 'CITY_NAME'
spatial_ref = arcpy.SpatialReference('WGS 1984')
try:
arcpy.ConvertCoordinateNotation_management(input_table, output_points, x_field, y_field,
input_format, output_format, id_field, spatial_ref)
print(arcpy.GetMessages(0))
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
except Exception as ex:
print(ex.args[0])