You could use an online tool, but when you're scripting (and I'm ALWAYS scripting) you want something a little less manual. Enter cs2cs from the PROJ.4 initiative. It will convert pretty much anything to anything else. Perfect.
In Ubuntu:
sudo apt-get install proj-bin
In Fedora I searched yum for proj-4
If the man page is a little too much too soon to take in, this wonderful page helps you decide which flags and parameters to use, with a rudimentary understanding of what you want
For example, if I want to convert coordinates in Arizona Central State Plane to WGS84 Latitude/Longitude, I use this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cs2cs -f "%.6f" +proj=tmerc +lat_0=31 +lon_0=-111.9166666666667 +k=0.9999 +x_0=213360 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs infile > outfile |
(the State Plane Coordinate System is new to me, but my view of the whole field of geodesy is 'let's make things even more complicated, sorry, accurate!')
Let's decompose that a bit:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-f "%.6f" |
tells it I want decimal degrees with 6 values after the decimal point (you could leave this out if you want deg, min, sec)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+proj=tmerc |
says use the Transverse Mercator projection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+lat_0=31 +lon_0=-111.9166666666667 +k=0.9999 +x_0=213360 +y_0=0 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs |
are all parameters related to the input coordinates in Arizona Central State Plane (the 'to_meter' is a conversion from feet, the default unit, to metres)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs |
are the parameters related to the output coordinates in Latitude/Longitude
infile is a two column list of points e.g.
2.19644131000e+005 6.11961823000e+005
2.17676234764e+005 6.11243565478e+005
2.19763457634e+005 6.11234534908e+005
2.19786524782e+005 6.11923555789e+005
2.19762476867e+005 6.11378246389e+005
outfile will be created with the results:
-111.846501 36.517758 0.000000
-111.868478 36.511296 0.000000
-111.845175 36.511202 0.000000
-111.844912 36.517412 0.000000
-111.845185 36.512498 0.000000
By default it will always give you the third dimension (height) even if you didn't ask for it, like above, so I tend to trim it by asking awk to give me just the first 2 columns separated by a tab:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
awk '{print $(NF-2),"\t",$(NF-1)}' outfile > outfile2 |
-111.846501 36.517758
-111.868478 36.511296
-111.845175 36.511202
-111.844912 36.517412
-111.845185 36.512498
No comments:
Post a Comment