Mac OS X: Installing the PROJ.4 - Cartographic Projections Library

I’ve been following Scott Barnham’s guide to transforming UK postcodes into (lat, long) coordinates and needed to install the PROJ.4 Cartographic Projections library which I initially struggled with.

The first step is to download a tar.gz version which is linked from the wiki page:

$ wget http://download.osgeo.org/proj/proj-4.9.1.tar.gz

Next we’ll unpack the file and then build the binaries:

$ tar -xvf proj-4.9.1.tar.gz
$ cd proj-4.9.1
$ ./configure --prefix ~/projects/land-registry/proj-4.9.1
$ make
$ make install

The files we need are in the bin directory...

$ ls -alh bin/
total 184
drwxr-xr-x   8 markneedham  staff   272B  5 Oct 23:07 .
drwxr-xr-x@ 41 markneedham  staff   1.4K  5 Oct 20:46 ..
-rwxr-xr-x   1 markneedham  staff    20K  5 Oct 23:07 cs2cs
-rwxr-xr-x   1 markneedham  staff    16K  5 Oct 23:07 geod
lrwxr-xr-x   1 markneedham  staff     4B  5 Oct 23:07 invgeod -> geod
lrwxr-xr-x   1 markneedham  staff     4B  5 Oct 23:07 invproj -> proj
-rwxr-xr-x   1 markneedham  staff    13K  5 Oct 23:07 nad2bin
-rwxr-xr-x   1 markneedham  staff    21K  5 Oct 23:07 proj

...now let’s give it a try. We need to feed in OSGB36 grid reference values and then we’ll get back WGS84 Lat/Lng values. We can grab some grid reference values from the Ordnance Survey website.

e.g. the Neo4j London office has the post code SE1 0NZ which translates to coordinates 531950,180195. Let’s try those out with PROJ.4:

$ ./proj-4.9.1/bin/cs2cs -f '%.7f' +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894 +units=m +no_defs +to +proj=latlong +ellps=WGS84 +towgs84=0,0,0 +nodefs

531950 180195
-0.1002020	51.5052917 46.0810195

So it’s suggested a (lat, long) pairing of (51.5052917, -0.1002020). And if we plug that into Google maps...

2015 10 05 23 29 09

...it’s pretty much spot on!

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket