
Work with Different Coordinate Systems #26
Chapter 3, Mapping Your World
|
115
HACK
Converting with the PROJ.4 Toolkit
The PROJ.4 toolkit provides a tool called proj for just this sort of task.
PROJ.4 is in Debian APT and can also be obtained at http://proj.maptools.
org/. proj accepts coordinate pairs, one per line, separated by whitespace,
with longitude given first. Anything after the first two numbers is consid-
ered to be a label and is preserved in the output. Suppose we have some data
in places.txt:
123d03'02.97"W 38d21'56.98"N Alice Rock
122d48'13.00"W 38d34'09.01"N Allan Ranch
122d23'57.01"W 38d16'27.01"N Arrowhead Mount
123d02'26.01"W 38d28'44.00"N Austin Gap
We can use proj to turn these coordinates into UTM as follows:
$ proj +proj=utm +zone=10 < places.txt
495559.96 4246406.86 Alice Rock
517108.31 4268986.90 Allan Ranch
552554.55 4236406.09 Arrowhead Mount
496462.37 4258951.69 Austin Gap
The only downside of using proj this way is that you have to know which
longitudinal zone you’re in. In this case, we knew we were in zone 10 by
looking at the UTM grid zone map at http://www.dmap.co.uk/utmworld.htm.
Although this example used coordinates in DMS format, you can also use
degrees and decimal minutes, or just decimal degrees (see “Work with Mul-
tiple Lat/Long Formats”
[Hack #25] for more details).
You can use the invproj program from PROJ.4, with the same command-line
arguments and file format, ...