English

How To: Convert a file with coordinates in degrees, minutes, and seconds to a feature class or shapefile using ArcMap 10.x

Summary

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

Warning:
The instructions in this article apply only to ArcGIS Desktop version 10 and later versions. For the equivalent process in earlier versions, refer to How To: Convert a file with coordinates in degrees, minutes and seconds to a shapefile using ArcMap.

Procedure

  1. Format the coordinate values so ArcMap can correctly read the data.
    1. 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:
      80 37 40.86,35 00 48.75
      80 37 20.55,35 01 42.35
      80 37 55.23,35 01 12.80
    2. For data in North America, the Longitude values must be negative. Note the sample:
      -80 37 40.86,35 00 48.75
      -80 37 20.55,35 01 42.35
      -80 37 55.23,35 01 12.80
    3. Each column in the table must have a heading that describes the data entered into that column of the table.
      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 
      Note:
      Any field name can be used, but the name must not be over ten characters long and must not contain spaces or special characters.
    4. The table requires a field that contains a unique identifying number for each record in the table.
      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:
    1. Right-click the table name > Export to DBF. This creates a table that can be edited in ArcMap.
    2. Add the new DBF table to ArcMap.
  3. Right-click the new DBF table name and select Open.

    In the Table dialog box, click 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.
    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:
    1. Start an edit session.
    2. Open the new DBF table, right-click the field name LongDD, and select Field Calculator.
    3. At the top of the Field Calculator dialog box, select the Python radio button.
    4. Click Load, navigate to the location where conv_DMS2DD.cal is saved on the computer, and click Open.
    5. In the lower window, where the string appears that reads Convert("ChangeFieldNameHere"), double-click between the parentheses to select the string.
    6. In the Fields box, double-click the name of the field that contains the Longitude value in DMS. The field name is copied into the lower window between the parentheses.
    7. Click OK. The decimal degree values for Longitude are calculated into the LongDD field.
    8. Repeat Steps b through g, this time selecting the LatDD field and entering the original Latitude field name.
    9. Save edits and stop editing.
  6. Right-click 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 the Edit button and select the correct Geographic Coordinate System definition for the coordinates. For assistance in finding the correct definition, refer to KB article 000007924, "What geographic coordinate system or datum should be used for my data?", from the link in the Related Links 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 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