Example usage for Proj.4, OGR, GDAL, and libgeotiff command-line tools


"proj" for projection calculations

Forward

What is 105 West, 40 North expressed in UTM, zone 13 coordinates?

$ proj +proj=utm +zone=13 +ellps=WGS84 -f %12.6f
-105 40                                 (input by the user)
500000.000000   4427757.218739          (output by the program)

Note that input order is lon/lat, and is typed to standard input in this example. The output is printed to standard output, which appears on the next line. The same is true for the next examples. The -f option specifies the output format. %12.6f means floating point (not DMS), six decimals to the right of the decimal point.

Reverse

$ proj +proj=utm +zone=13 +ellps=WGS84 -f %12.6f -I
500000.000000   4427757.218739
-105.000000       40.000000

Note the -I option, which specifies inverse mode.

Convert coordinates in a file

$ cat lonlat_input.txt 
-105 40
-108.4 42.45
$ proj +proj=utm +zone=13 +ellps=WGS84 -f %12.6f < lonlat_input.txt 
500000.000000   4427757.218739
220397.845840   4705343.964765
$

The above example prints the projected coordinates to the screen. If you want them in a file, you could say:

$ proj +proj=utm +zone=13 +ellps=WGS84 -f %12.6f < lonlat_input.txt > utm.txt

Display available ellipsoids

$ proj -le
    MERIT a=6378137.0      rf=298.257       MERIT 1983
    SGS85 a=6378136.0      rf=298.257       Soviet Geodetic System 85
    GRS80 a=6378137.0      rf=298.257222101 GRS 1980(IUGG, 1980)
    IAU76 a=6378140.0      rf=298.257       IAU 1976
    [etc.]

Display available projections

$ proj -lp  # short version
aea : Albers Equal Area
aeqd : Azimuthal Equidistant
airy : Airy
aitoff : Aitoff
alsk : Mod. Stererographics of Alaska
apian : Apian Globular I
[etc.]

$ proj -lP  # longer version
aea : Albers Equal Area
        Conic Sph&Ell
        lat_1= lat_2=
aeqd : Azimuthal Equidistant
        Azi, Sph&Ell
        lat_0 guam
[etc.]

Display available units

$ proj -lu
          km 1000.                Kilometer
           m 1.                   Meter
          dm 1/10                 Decimeter
          cm 1/100                Centimeter
          mm 1/1000               Millimeter
         kmi 1852.0               International Nautical Mile
          in 0.0254               International Inch
          ft 0.3048               International Foot
          yd 0.9144               International Yard
          mi 1609.344             International Statute Mile
        fath 1.8288               International Fathom
          ch 20.1168              International Chain
        link 0.201168             International Link
       us-in 1./39.37             U.S. Surveyor's Inch
       us-ft 0.304800609601219    U.S. Surveyor's Foot
       us-yd 0.914401828803658    U.S. Surveyor's Yard
       us-ch 20.11684023368047    U.S. Surveyor's Chain
       us-mi 1609.347218694437    U.S. Surveyor's Statute Mile
      ind-yd 0.91439523           Indian Yard
      ind-ft 0.30479841           Indian Foot
      ind-ch 20.11669506          Indian Chain

"geod" for geodesic calculations

Distance between two pairs of lat/lon:

# Distance between Denver (39.8667 -104.6667) and San Francisco (37.6167 -122.3833)
$ geod -I +ellps=WGS84 +units=km -f "%.3f"
39.8667 -104.6667 37.6167 -122.3833
-93.566 75.290  1557.738

The numbers in the answer above are: direction, back-direction, distance. Note that the input order is lat/lon.

New lat/lon from initial lat/lon, azimuth, and distance:

# What is the lon/lat of the point 500 km from Boulder in the NE direction?
$ geod +ellps=WGS84 +units=km -f "%.3f"
40 -105.2 45 500
43.104  -100.857        -132.117

The numbers in the answer above are latitude, longitude, back-azimuth. Note that input order is lat/lon.


"cs2cs" for more general conversions

$ cs2cs +proj=latlong +datum=NAD27 +to +proj=latlong +datum=WGS84 -f %12.6f
-117 30

producing:

 -117.000806       30.000113     0.000000

See the FAQ at http://proj.maptools.org/faq.html for more information.