5 Introduction to the PROJ.4 library

The PROJ.4 library currently has three functionalities for coordinate transformation and geodetic calculation:

  • proj/invproj – direct and inverse cartographic projections,

  • cs2cs – conversion between coordinate systems (geographic or projected),

  • geod/invgeod – direct and inverse geodetic calculations.

The PROJ.4 library was developed in early 1980 as the RATFOR program (RATional FORtran programming language), with most of the code originating in the GCTP (Geological Survey’s General Cartographic Transformation Package). The PROJ.4 program was re-coded in the programming language C when the MAPGEN package (of which PROJ.4 is a basic component) was introduced to the UNIX operating system. Many new projections were added to the program.

The library is based on the work of Gerald Evenden; it was later maintained by Frank Warmerdam, the creator of the GDAL library, and now by the programming community. The PROJ.4 library comes with an MIT (Massachusetts Institute of Technology) license allowing free use, copying, editing, sublicensing, and commercial use if the original license is credited.

The installation of the PROJ.4 library depends on the operating system; in the following, a brief illustration will be given on how to use it. The library itself contains parameters of many ellipsoids as well as predefined geodetic datums with parameter values.

Lists of available ellipsoids with parameters can be obtained using the command cs2cs -le, where -le is the function argument for displaying the list of ellipsoids.

cs2cs -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                             
 airy a=6377563.396 b=6356256.910 Airy 1830                        
 APL4.9 a=6378137.0. rf=298.25 Appl. Physics. 1965                 
 NWL9D a=6378145.0. rf=298.25 Naval Weapons Lab., 1965             
 mod_airy a=6377340.189 b=6356034.446 Modified Airy               
 andrae a=6377104.43 rf=300.0 Andrae 1876 (Den., Iclnd.)           
 aust_SA a=6378160.0 rf=298.25 Australian Natl & S. Amer. 1969    
 GRS67 a=6378160.0 rf=298.2471674270 GRS 67(IUGG 1967)             
 bessel a=6377397.155 rf=299.1528128 Bessel 1841                   
 bess_nam a=6377483.865 rf=299.1528128 Bessel 1841 (Namibia)      
 clrk66 a=6378206.4 b=6356583.8 Clarke 1866                        
 clrk80 a=6378249.145 rf=293.4663 Clarke 1880 mod.                 
 clrk80ign a=6378249.2 rf=293.4660212936269 Clarke 1880 (IGN).     
 CPM a=6375738.7 rf=334.29 Comm. des Poids et Mesures 1799         
 delmbr a=6376428. rf=311.5 Delambre 1810 (Belgium)                
 engelis a=6378136.05 rf=298.2566 Engelis 1985                     
 evrst30 a=6377276.345 rf=300.8017 Everest 1830                    
 evrst48 a=6377304.063 rf=300.8017 Everest 1948                    
 evrst56 a=6377301.243 rf=300.8017 Everest 1956                    
 evrst69 a=6377295.664 rf=300.8017 Everest 1969                    
 evrstSS a=6377298.556 rf=300.8017 Everest (Sabah & Sarawak)       
 fschr60 a=6378166. rf=298.3 Fischer (Mercury Datum) 1960          
 fschr60m a=6378155. rf=298.3 Modified Fischer 1960                
 fschr68 a=6378150. rf=298.3 Fischer 1968                          
 helmert a=6378200. rf=298.3 Helmert 1906                          
 hough a=6378270.0 rf=297. Hough                                   
 intl a=6378388.0 rf=297. International 1909 (Hayford)             
 krass a=6378245.0 rf=298.3 Krassovsky, 1942                       
 kaula a=6378163. rf=298.24 Kaula 1961                             
 lerch a=6378139. rf=298.257 Lerch 1979                            
 mprts a=6397300. rf=191. Maupertius 1738                          
 new_intl a=6378157.5 b=6356772.2 New International 1967          
 plessis a=6376523. b=6355863. Plessis 1817 (France)               
 SEasia a=6378155.0 b=6356773.3205 Southeast Asia                  
 walbeck a=6376896.0 b=6355834.8467 Walbeck                        
 WGS60 a=6378165.0 rf=298.3 WGS 60                                 
 WGS66 a=6378145.0 rf=298.25 WGS 66                                
 WGS72 a=6378135.0 rf=298.26 WGS 72                                
 WGS84 a=6378137.0 rf=298.257223563 WGS 84                         
 sphere a=6370997.0 b=6370997.0 Normal Sphere (r=6370997)          
 

Similarly, a list of prime meridians, relative to the Greenwich meridian, can be obtained.

cs2cs -lm                
 greenwich 0dE             
 lisbon 9d07'54.862"W      
 paris 2d20'14.025"E       
 bogota 74d04'51.3"W       
 madrid 3d41'16.58"W       
 rome 12d27'8.4"E          
 bern 7d26'22.5"E          
 jakarta 106d48'27.79"E    
 ferro 17d40'W             
 brussels 4d22'4.71"E      
 stockholm 18d3'29.8"E     
 athens 23d42'58.815"E     
 oslo 10d43'22.5"E 

A list of predefined datums is obtained using the -ld argument.

cs2cs -ld
_datum_id__ __ellipse___ __definition/comments_
       WGS84 WGS84        towgs84=0,0,0                 
      GGRS87 GRS80        towgs84=-199.87,74.79,246.62  
                          Greek_Geodetic_Reference_System_1987
       NAD83 GRS80        towgs84=0,0,0                 
                          North_American_Datum_1983
       NAD27 clrk66       nadgrids=@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat
                          North_American_Datum_1927
     potsdam bessel       towgs84=598.1,73.7,418.2,0.202,0.045,-2.455,6.7
                          Potsdam Rauenberg 1950 DHDN
    carthage clrk80ign    towgs84=-263.0,6.0,431.0      
                          Carthage 1934 Tunisia
hermannskogel bessel       towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232
                          Hermannskogel
       ire65 mod_airy     towgs84=482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15
                          Ireland 1965
      nzgd49 intl         towgs84=59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993
                          New Zealand Geodetic Datum 1949
      OSGB36 airy         towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894
                          Airy 1830

Using the PROJ.4 notation, any coordinate reference system can be defined, not only the predefined datums contained in the library.

+proj=tmerc +lat_0=0 +lon_0=21 +k=0.9999 +x_0=7500000 +y_0=0 +ellps=bessel +towgs84=574.027,170.175,401.545,4.88786,-0.66524,-13.24673,6.89 +units=m

For Serbia, a coordinate reference system in the Gauss-Krüger projection is given with the following parameters:

+proj=tmerc - Gaus Kriger (Transverse Mercator) projection,
+lat_0=0 +lon_0=21 - coordinate origin on the ellipsoid,
+k=0.9999 - scale along the middle meridian,
+x_0=7500000 +y_0=0 - coordinate origin in the map’s plane
+ellps=bessel - ellipsoid
+towgs84=574.027,170.175,401.545,4.88786,-0.66524,-13.24673,6.89
three translations, three rotations, scale relative to WGS84 expressed in ppm (parts per million)
+=m - units, meters.

Besides this, the coordinate reference system in the PROJ.4 notation can be defined using the EPSG code. The EPSG Geodetic Parameter Dataset is a collection of definitions of coordinate reference system and parameters that describe them.

At http://spatialreference.org/ or http://epsg.io, defitions of coordinate reference systems can be found in several notations: EPSG, proj4, WKT, GML, JSON… In Figure 5.1, an example is given for a WGS84 coordinate system with EPSG code 4326.

Example of using [*http://spatialreference.org*](http://spatialreference.org/) with the possibility of downloading coordinate reference system parameters in multiple notations.

Figure 5.1: Example of using http://spatialreference.org with the possibility of downloading coordinate reference system parameters in multiple notations.

An example of direct calculation is given for the Gauss-Krüger projection:

proj +proj=tmerc +lat_0=0 +lon_0=21 +k=0.9999 +x_0=7500000 +y_0=0 +ellps=bessel  
21.33254 45.22587
   7526110.73   5009091.15

When executing the proj command, the user is expected to input ellipsoid coordinates via a terminal or from a text file in order to obtain rectangular coordinates. Using the linux functionality, the command can be executed directly from the command line.

echo 21.33254 45.22587 | proj +proj=tmerc +lat_0=0 +lon_0=21 +k=0.9999 +x_0=7500000 +y_0=0 +ellps=bessel 
7526110.73  5009091.15

In inverse cartographic calculations, it is necessary to enter the command -I, which should be followed by input rectangular coordinates and, as a result, ellipsoid coordinates (longitude and latitude) are obtained.

proj +proj=tmerc +lat_0=0 +lon_0=21 +k=0.9999 +x_0=7500000 +y_0=0 +ellps=bessel -I 
7526110.73 5009091.15
   21.332540       45.225870

Transformation of coordinates from one system to another is illustrated by the example conversion from the old Gauss-Krüger state system (Bessel ellipsoid and Hermannskogel datum) into the new UTM coordinate reference system for Serbia (GRS80 ellipsoid with an ETRS datum for Serbia):

echo 7526110.73  5009091.15 | cs2cs +proj=tmerc +lat_0=0 +lon_0=21 +k=0.9999 +x_0=7500000 +y_0=0 +ellps=bessel +towgs84=574.027,170.175,401.545,4.88786,-0.66524,-13.24673,6.89 +units=m +to +proj=utm +zone=34 +ellps=GRS80 +towgs84=0.26901,0.18246,0.06872,-0.01017,0.00893,-0.01172,0.04 +units=m
525672.87   5008094.39 42.46

An example of conversion from the Gauss-Krüger system for Serbia into WGS84 is also given, in which WGS84 is defined using the EPSG code, and details about the function can be found at: http://proj4.org/apps/cs2cs.html.

echo 7526110.73  5009091.15 | cs2cs +proj=tmerc +lat_0=0 +lon_0=21 +k=0.9999 +x_0=7500000 +y_0=0 +ellps=bessel +towgs84=574.027,170.175,401.545,4.88786,-0.66524,-13.24673,6.89 +units=m +to +init=epsg:4326 -f %12.6f
   21.327021       45.225867    42.986502

The PROJ.4 library is implemented in numerous GIS software and can be easily used via a graphical interface.