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 o开发者_StackOverflow社区r 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.
Can you run ArcGIS Server? ESRI has a new service called a Geometry service that lets you do geometry manipulation/conversion/etc through a variety of service interfaces.
You can find a sample version at http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer that you can test with.
精彩评论