Converting Decimal Degree Coordinates to/from DMS Degrees Minutes Seconds
If you have files or apps that have to filter or convert coordinates – then the cs2cs command is for you. It comes with most distributions of the GDAL/OGR (gdal.org) toolset. Here is one popular example for converting between degrees minutes and seconds (DMS) and decimal degrees (DD).
The following is an excerpt from the book: Geospatial Power Tools – Open Source GDAL/OGR Command Line Tools by me, Tyler Mitchell. The book is a comprehensive manual as well as a guide to typical data processing workflows, such as the following short sample…
Input coordinates can come from the command line or an external file. Assuming a file containing DMS (degree, minute, seconds) style, looks like:
124d10'20"W 52d14'22"N
122d20'05"W 54d12'00"N
Use the cs2cs command, specifying how the print format will be returned, using the -f option. In this case -f “%.6f”
is explicitly requesting a decimal degree number with 6 decimals:
cs2cs -f "%.6f" +proj=latlong +datum=WGS84 input.txt
Example Converting DMS to/from DD
This will return the results, notice no 3D/Z value was provided, so none is returned:
-124.172222 52.239444 0.000000
-122.334722 54.200000 0.000000
To do the inverse, remove the formatting option and provide a list of values in decimal degree (DD):
cs2cs +proj=latlong +datum=WGS84 inputdms.txt
124d10'19.999"W 52d14'21.998"N 0.000
122d20'4.999"W 54d12'N 0.000
Geospatial Power Tools is 350+ pages long – 100 of those pages cover these kinds of workflow topic examples. Each copy includes a complete (edited!) set of the GDAL/OGR command line documentation as well as the following topics/examples:
Workflow Table of Contents
- Report Raster Information – gdalinfo
- Web Services – Retrieving Rasters (WMS)
- Report Vector Information – ogrinfo
- Web Services – Retrieving Vectors (WFS)
- Translate Rasters – gdal_translate
- Translate Vectors – ogr2ogr
- Transform Rasters – gdalwarp
- Create Raster Overviews – gdaladdo
- Create Tile Map Structure – gdal2tiles
- MapServer Raster Tileindex – gdaltindex
- MapServer Vector Tileindex – ogrtindex
- Virtual Raster Format – gdalbuildvrt
- Virtual Vector Format – ogr2vrt
- Raster Mosaics – gdal_merge