I need to convert data points from one geographic projection (Lat Long, Mercator, UTM) to another and I wonder if there's a set of PHP tools or functions that can do this? I tried writing one myself based on formulas I found, but it wasn't accurate enough and I can't find better formulas anywhere, so I was wondering if there might be some prepackaged functions somewhere. Failing that, what about something like PROJ.4? Thanks!
There is a PHP module of Proj4 available in the MapServer/MapScript distribution. I think it is mantanied by DM Solutions, but I could not find any documentation online. To check the available functions, I had to look at the source code.
Anyway, this is how you can tranform coordinates between projections:
<?php
//UTM zone 31N
$projDefSrc = array("proj=utm","zone=31","ellps=intl","units=m","no_defs");
$pjSrc = pj_init($projDefSrc);
//WGS84
$projDefDest = array("proj=longlat","ellps=WGS84","datum=WGS84","no_defs");
$pjDest = pj_init($projDefDest);
$x = 446423;
$y = 4610005;
$test = pj_transform($pjSrc,$pjDest,$x,$y);
//Outputs: Array ( [u] => 2.3567240656 [v] => 41.6384346565 )
print_r($test);
?>
If you want to go this way, you will have to compile php_proj.c from the Mapserver source code folder (mapserver-X.X.X/mapscript/php3) and load the extension in PHP. As I said before, there is no documentation online, so let me know if you find any problems.
Hope this helps.
You can use the api proj4php that I have translated from proj4js and is available here : https://sourceforge.net/projects/proj4php/
It works great from WGS84 to Lambert93, but need some fix to work with the others projections. I can help.
Bye.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With