
112
|
Chapter 3, Mapping Your World
#25 Work with Multiple Lat/Long Formats
HACK
multiplying it by 60 again. To convert the parking lot’s latitude from deci-
mal degrees to DMS:
38.4160° =
Degrees = 38°
Minutes = .4160 * 60 = 24.96'
Seconds = .96 * 60 = 57.60"
= 38° 24' 57.60" N
To get degree/decimal-minute format, just stop when you have the minutes
in decimal form (
Minutes = .4160 * 60 = 24.96').
Converting Lat/Long to Lat/Long using PROJ.4
PROJ.4 is the open source cartographic projections library. PROJ.4, which
can be obtained from http://proj.maptools.org/, includes the Swiss Army
Chainsaw of coordinate conversions: a command-line tool called cs2cs.
Among the many tricks of cs2cs is its ability to convert lat/long between dif-
ferent formats. The following example converts from decimal degrees to
DMS:
$ cs2cs +proj=latlong +to +proj=latlong
-122.50 38.75
122d30'W 38d45'N 0.00
Using the format (-f) parameter, you can change the value from DMS to
decimal degrees:
$ cs2cs +proj=latlong +to +proj=latlong -f "%.2f" \
122d45'W 35d12'N
-122.75 35.20 0.00
You can also use shell redirection to convert a whole file of coordinates at
once:
$ cs2cs +proj=latlong +to +proj=latlong < coords.txt
125d19'6.6"E 12d6'29.16"N 0.000
90d33'26.64"W 33d25'56.28"N 0.000
15d30'E 39d18'S 0.000
See “Work with Different Coordinate Systems” [Hack #26] for other uses of
PROJ.4.
Input should be provided to cs2cs with longitude first and