Knowledge Base - Technical Articles
HowTo: Convert a file with coordinates in degrees, minutes and seconds to a shapefile using ArcMap
| Article ID: | 27548 |
|---|---|
| Software: | ArcGIS - ArcEditor 9.2, 9.3, 9.3.1 ArcGIS - ArcInfo 9.2, 9.3, 9.3.1 ArcGIS - ArcView 9.2, 9.3, 9.3.1 |
| Platforms: | N/A |
Summary
| 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.
-show me- |
| Procedure |
|
|
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 following example:
80 37 40,35 00 48
B. For data in North America, the longitude values must be negative. Note the following 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 must have a field that contains a unique identifying number for each record in the table (primary key).
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 in the Export Data dialog box to create the shapefile.
Related Information
- Convert degrees minutes seconds values to decimal degree values using the Field Calculator
{WARN}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. {/WARN}Instructions provided describe how to use the Field Calc... - Import XY data tables to ArcMap and convert the data to a shapefile
Tables 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. {WARN}The instruct...
Created: 8/26/2004
Last Modified: 1/5/2012
Article Rating:
(1)
By Anonymous - 03/16/2011 11:00 AM
The article contains a dead link.
On my desk top the code works as well as that found in in Ianko's Easy Calc (very similar) which doesn't work at all.
Rating: