2011-02-28

Converting WKT projection info to Proj4 (and back) - the PHP edition

As noted in a previous post, it is fairly easy to utilize the language bindings for the GDAL project to work with projections. However, if you're working in PHP, the corresponding GDAL bindings are not maintained and currently do not work as-is from the GDAL project. As-of GDAL 1.8.0, a bit of tinkering will get the PHP modules to compile, but they still do not work as expected.

However, you can get the php_osr.so module to work with some basic functions using the patch posted at http://pastebin.com/SXKKfe6v. Save this to a file, and apply the patch to the gdal 1.8.0 source like so:

cd /path/to/gdal/src
 patch -p0 < /path/to/patch
Then build and install the gdal code as follows:
./configure --with-php
 make
 make install
 sudo cp swig/php/php_osr.so /usr/lib/php5/20090626/
 sudo su -c \
  'echo extension=php_osr.so > /etc/php5/conf.d/osr.ini'
 sudo service apache2 restart
The above assumes: - You're doing this on a typical/recent Ubuntu installation - You already have Apache and PHP configured - You already have all the required dependencies for building gdal and the swig bindings installed (if not, run "
sudo apt-get build-dep libgdal-1.x.x
", and also you may need to install php5-devel and php5-cli packages). Once you've got gdal and the php_osr.so module compiled and installed, try the following PHP script:
<?php
 include("/path/to/gdal/src/swig/php/osr.php");
 $sr = new SpatialReference();
 $sr->ImportFromProj4('+init=epsg:4326');
 echo $sr->ExportToProj4();
?>
The result from that script should be the following Proj4 string:
+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs

Clearly, this is not as good as having all of the GDAL/OGR libraries accessible from PHP, but it's a start. You can review the swig/php/osr.php file to see what objects/functions are available through the php_osr.so module.

2011-02-05

A web page hit counter that plots your visitors on a globe.

While reading someone's NASA blog, I came across this neat little widget that plots all of your visitors as points on a revolving globe (or flat static map if you prefer): http://www.revolvermaps.com

It's free to use, and you can select from a variety of options to choose the coloring and style so that it fits into the layout of your website, and it can run using Flash or it will fail-over to Java (or neither if you choose a static map).  I'm sure this isn't entirely new to everyone, as the site has been around for over two years, but it's fairly impressive regardless.  I also gather that it collects visitor information for your site in their own database somewhere (it's not clear from the info available how this is done), so if privacy is a concern for users on your site, you may not want to add this to your site.

I've added a sample below - I imagine the dots will remain fairly sparse for this blog. :)