## HowTo:  Convert a file with coordinates in degrees, minutes, and seconds to a feature class or shapefile using ArcMap at version 10

Article ID: 37264 ArcGIS - ArcEditor 10 ArcGIS - ArcInfo 10 ArcGIS - ArcView 10 N/A

#### Summary

Instructions provided describe the process for converting point data in degrees, minutes and seconds (DMS) to a shapefile using a Python script in ArcMap.

The instructions in this article apply only to ArcGIS Desktop version 10 and later versions. For the equivalent process in earlier versions, refer to ESRI Knowledge Base article 27548. -show me-
 Summary Instructions provided describe the process for converting point data in degrees, minutes and seconds (DMS) to a shapefile using ArcMap. Procedure Follow the steps below.Format the coordinate values for ArcGIS to correctly interpret the data. A. Coordinates in DMS from a file need to be formatted with spaces separating the degree, minute and second values, as shown in the example below: 80 37 40,35 00 48 B. For data in North America, the Longitude values must be negative. Note the example: -80 37 40,35 00 48 C. Each column in the table must have a heading, that describes the data entered into that column of the table: Longitude,Latitude -80 37 40,35 00 48 D. The table needs a field that contains a unique identifying number for each record in the table. ID,Longitude,Latitude 1,-80 37 59,35 00 38 Start ArcMap with a new, empty map once the table is correctly formatted. Save the script below as 'conv_DMS2DD.cal' in ArcMap with the following steps. ```Dim sField Dim sDMS As String, sS As String, sSuf As String, sPre as string Dim sList Dim i As Integer, j As Integer Dim iDec As Integer, iNum As Integer Dim dD As Double, dM As Double, dS As Double, dDD As Double Dim bReplace As Boolean '============================= 'Change the source field name bellow sField = [dms] '============================= sDMS = sField If Len(Trim(sDMS)) = 0 Then dDD = 0 Else iDec = 0 iNum = 0 For i = 1 To Len(sDMS) sS = Mid(sDMS, i, 1) If Not IsNumeric(sS) Then If sS = "." Then If Not iDec = 0 Then bReplace = True Else bReplace = False End If iDec = iDec + 1 ElseIf sS = "-" Then sPre = "-" bReplace = True Else bReplace = True End If If bReplace Then If iNum > 0 Then Mid(sDMS, i, 1) = "," Else Mid(sDMS, i, 1) = " " End If End If Else iNum = iNum + 1 End If Next i sList = Split(sDMS, ",") Dim iLen As Integer If UBound(sList) = 0 Then sDMS = sList(0) iLen = Len(sDMS) If iLen >= 4 Then dS = CDbl(Mid(sDMS, iLen - 1, 2)) dM = CDbl(Mid(sDMS, iLen - 3, 2)) sDMS = Left(sDMS, (iLen - 4)) If (Len(sDMS) > 2) Then dD = CDbl(Right(sDMS, 3)) ElseIf (Len(sDMS) = 0) Then dD = 0# Else dD = CDbl(sDMS) End If Else dDD = 0 End If dDD = dD + dM / 60# + dS / 3600# Else j = 0 dD = 0# dM = 0# dS = 0# For i = 0 To UBound(sList) If IsNumeric(sList(i)) Then If j = 0 Then dD = CDbl(sList(i)) j = j + 1 ElseIf j = 1 Then dM = CDbl(sList(i)) j = j + 1 ElseIf j = 2 Then dS = CDbl(sList(i)) j = j + 1 End If End If Next i dDD = dD + dM / 60# + dS / 3600# End If If dDD < -180# Or dDD > 180# Then dDD = 0# End If If sPre = "-" Then dDD = dDD * -1# End If End If```A. Open a table in ArcMap. B. Right-click a field and select Calculate Values. C. Check the Advanced check box. D. Copy the code above into the Pre-Logic VBA Script Code section of the field calculator. E. Type dDD into the bottom section of the Field Calculator. F. Click Save to save the script to a .cal file and name the file 'conv_DMS2DD.cal'. Follow these steps to run the code above in the Field Calculator: A. Add the table containing the DMS coordinates to ArcMap through the Add Data button. B. Right-click on the table name > Data > Export and export the table to a DBF file. C. Open the DBF table and add items named 'longDD' and 'latDD' to the table, defining these as Double, Precision 18, and Scale 13. D. Calculate the field values for 'longDD' and 'latDD' by starting a load of the conv_DMS2DD.cal script to the field calculator.  Change the name of the field in the script to that of the original DMS fields: 'Change the source field name below sField = [Long] Right-click the DBF table and select Display XY Data after the coordinates have been converted from DMS to DD. Define the projection for the event layer by clicking the Edit button in the 'Spatial Reference of Input Coordinates' section of the dialog box.  Defining the projection permits the data to display in the correct location in ArcMap as an Event layer. Convert the Event layer to a shapefile. A. Right-click the Event layer and select Data > Export data. B. Select the output location for the shapefile and type in the name. C. Click Save and OK on the Export Data dialog box to create the shapefile. Convert degrees minutes seconds values to decimal degree values using the Field Calculator The procedure below is for ArcGIS 9.3.1 or earlier versions. Starting at ArcGIS 10.0, expressions in the Calculator are created using only VBScript or a standard Python format. Instructions provided describe how to use the Field Calc...Import XY data tables to ArcMap and convert the data to a shapefileTables containing X coordinates (Longitude) and Y coordinates (Latitude) can be brought into ArcMap and converted to a shapefile or geodatabase feature class. Instructions provided outline one method to accomplish this task.  The instruct...

#### Procedure

1. Format the coordinate values so ArcMap can correctly read the data.

A. Coordinates in DMS from a file need to be formatted with spaces separating the degree, minute, and second values as shown in the following example: -show me-

 80 37 40.86,35 00 48.75 80 37 20.55,35 01 42.35 80 37 55.23,35 01 12.80

B. For data in North America, the Longitude values must be negative. Note the sample: -show me-

 -80 37 40.86,35 00 48.75 -80 37 20.55,35 01 42.35 -80 37 55.23,35 01 12.80

C. Each column in the table must have a heading that describes the data entered into that column of the table. -show me-

 LongDMS,LatDMS -80 37 40.86,35 00 48.75 -80 37 20.55,35 01 42.35 -80 37 55.23,35 01 12.80

Any field name can be used, but the name must not be over ten characters long and must not contain spaces or special characters.

D. The table requires a field that contains a unique identifying number for each record in the table. -show me-

 ID,LongDMS,LatDMS 1,-80 37 40.86,35 00 48.75 2,-80 37 20.55,35 01 42.35 3,-80 37 55.23,35 01 12.80
2. When the table is correctly formatted, start ArcMap with a new, empty map. Use the 'Add Data' button to add the table to ArcMap. To ensure that the table can be edited in ArcMap, do the following:

A. Right-click on the table name > Export to DBF. This creates a table that can be edited in ArcMap.
B. Add the new DBF table to ArcMap.
3. Right-click on the new DBF table name and select Open.

In the Table dialog box, click on the Table Options button and select Add Field.

Add a new field named 'LongDD' to the table, defining the field as Type: Double. Accept the default values for Precision and Scale.

Add a second new field named 'LatDD' to the table, also defined as Type: Double.

These new fields contain the Longitude (X) and Latitude (Y) coordinates in decimal degrees.
4. Copy the following Python script into NotePad or another text editor. In the NotePad 'Save As' dialog box, change Encoding: value to 'Unicode'. Name the file "conv_DMS2DD.cal". Click 'Save'. -show me-

 ```def Convert(sField): sDMS = sField if len(sDMS.strip())==0: dDD=0 else: iDec = 0 iNum= 0 sPre="+" sDMSNum="" for i in range(0,len(sDMS)): sS=sDMS[i:i+1] if not sS.isalnum(): if sS==".": if not iDec==0: bReplace=1 else: bReplace=0 elif sS=="-": sPre="-" bReplace=1 else: bReplace=1 if bReplace==1: if iNum<=0: sDMSNum=sDMS.replace(sDMS[i],"") elif iNum>0 and sPre=="+": sDMSNum=sDMS else: iNum=iNum+1 sList=sDMSNum.split(" ") if len(sList)==0: sDMSNum=sList[0] iLen=len[sDMSNum] if iLen>=4: dS=float(sDMSNum[iLen-1,iLen+1]) dM=float(sDMSNum[iLen-3,iLen-1]) sDMSNum = sDMSNum[0,iLen - 4] if (Len(sDMSNum) > 2): dD = float(sDMSNum[-4, -1]) elif (Len(sDMSNum) == 0): dD = 0 else: dD = float(sDMSNum) else: dDD=0 dDD=dD+dM/60+dS/3600 else: j=0 dD=0 dM=0 dS=0 for i in range (0, len(sList)): if j==0: dD=float(sList[i]) j=j+1 elif j==1: dM=float(sList[i]) j=j+1 elif j==2: dS=float(sList[i]) j=j+1 dDD=dD+dM/60+dS/3600 if dDD<-180 or dDD>180: dDD=0 if sPre =="-": dDD=dDD*-1 return dDD __esri_field_calculator_splitter__ Convert ( "ChangeFieldNameHere" )```
5. In ArcMap, follow the steps below to execute the script and convert the DMS values to DD:

A. Start an Edit session.
B. Open the new DBF table, right-click on the field name LongDD and select Field Calculator.
C. At the top of the Field Calculator dialog box, select the Python radio button.
D. Click Load, navigate to the location where conv_DMS2DD.cal is saved on the computer, and click Open.
E. In the lower window, where the string appears that reads 'Convert("ChangeFieldNameHere")', double-click between the parentheses to select the string.
F. In the Fields box, double-click on the name of the field that contains the Longitude value in DMS. The field name is copied into the lower window between the parentheses.
G. Click OK. The decimal degree values for Longitude are calculated into the LongDD field.

Repeat Steps B through G, this time selecting the LatDD field and entering the original Latitude field name.

Save Edits and stop editing.
6. Right-click on the name of the DBF table and select Display XY Data.
7. In the Display XY Data dialog box, select LongDD as the X field and LatDD as the Y field.
8. Click on the Edit button and select the correct Geographic Coordinate System definition for the coordinates. For assistance in finding the correct definition, refer to Knowledge Base article 29280, entitled "What geographic coordinate system or datum should be used for my data?", from the link in the Related Information section below.
9. Apply the projection definition to the data. An Events theme will be added to ArcMap that displays the points from the table.
10. Right-click on the Events theme, select Data > Export data, and export the Events theme to a shapefile or geodatabase feature class.

After the data is exported to a shapefile or geodatabase feature class, there is an option to add the newly exported data to the map as a layer.

#### Related Information

Created: 10/7/2009

Article Rating: (4)

By msilin - 05/08/2012 2:59 PM

The article needs to be updated.

Had an issue with the original script provided. Asked my developers to review it. The following version worked like a charm: def Convert(sField): sDMS = sField if len(sDMS.strip())==0: dDD=0 else: iDec = 0 iNum= 0 sPre="+" sDMSNum="" for i in range(0,len(sDMS)): sS=sDMS[i:i+1] if not sS.isalnum(): if sS==".": if not iDec==0: bReplace=1 else: bReplace=0 elif sS=="-": sPre="-" bReplace=1 else: bReplace=1 if bReplace==1: if iNum<=0: sDMSNum=sDMS.replace(sDMS[i],"") elif iNum>0 and sPre=="+": sDMSNum=sDMS else: iNum=iNum+1 sList=sDMSNum.split(" ") if len(sList)==0: sDMSNum=sList[0] iLen=len[sDMSNum] if iLen>=4: dS=float(sDMSNum[iLen-1,iLen+1]) dM=float(sDMSNum[iLen-3,iLen-1]) sDMSNum = sDMSNum[0,iLen - 4] if (Len(sDMSNum) > 2): dD = float(sDMSNum[-4, -1]) elif (Len(sDMSNum) == 0): dD = 0 else: dD = float(sDMSNum) else: dDD=0 dDD=dD+dM/60+dS/3600 else: j=0 dD=0 dM=0 dS=0 for i in range (0, len(sList)): if j==0: dD=float(sList[i]) j=j+1 elif j==1: dM=float(sList[i]) j=j+1 elif j==2: dS=float(sList[i]) j=j+1 dDD=dD+dM/60+dS/3600 if dDD<-180 or dDD>180: dDD=0 if sPre =="-": dDD=dDD*-1 return dDD __esri_field_calculator_splitter__ Convert ( !LongDMS! )

Rating:

By tianna.dulmage - 03/20/2012 5:01 PM

The article is incorrect or the solution didn’t work.

The python script "conv_DMs2DD.cal" didn't work. I get a python error running the field calculation: 000989 : Python syntax error: I ran the conversion calculations for DMS to DD (D+M/60+S/3600, then multiply the LongDD by -1 if you need a negative) outside of ArcMap and then used that table to go through the rest of the steps, and got a nice set of points in the end, but a working script would be very helpful. Thanks, td

Rating:

By bswindell - 03/02/2012 10:32 AM

The article is incorrect or the solution didn’t work.

Yep, either the code has a bug or the instructions are incomplete. Please fix.

Rating:

By msilin - 08/02/2011 8:14 AM

The article is incorrect or the solution didn’t work.

Followed the instructions, got error message: Error 000539: Error running Expression Convert ("-74 35 00"): invalid syntax (, line 1) My DMS value are stored in fields of type 'String'. I tried to create new fields of type 'Text' and copy the data over to the new fields to ensure that there was no discrepancy between the data formats, but same error occurs. Please provide an updates code or an alternate solution.

Rating: