[mapserver-users] Projecting coordinates without drawing maps?

Paul Spencer pspencer at dmsolutions.ca
Sat Jun 28 15:02:40 PDT 2008


If you care why, mapserver's projection support passes the projection  
string to the proj4 library, which requires a certain style of passing  
parameters.  You can pass in a full projection definition consisting  
of <param>=<value> which is the case with proj=latlong OR you can  
reference the projection parameters defined in a dictionary that proj4  
knows about, in this case the 'epsg' dictionary.

This is a common source of frustration and misunderstanding.  When  
using mapserver as a WMS client, you define the projection that you  
want to get the data in from the remote WMS server by specifying an  
EPSG code in the form SRS=EPSG:XXXXX - and it is important in this  
case that it be in UPPER case and not have 'init='.  Inside  
mapserver's MAP file, when defining a projection (or when using  
mapscript), you use the proj4 definitions.

Note that the method of using init=<dictionary>:<value> is still  
inefficient for mapserver because proj has to parse the rather large  
epsg file to find the appropriate proj string.  If you are just doing  
some one-off translations then no big deal obviously, but if you are  
setting up a service to reproject or are setting up a map file with  
projections, then it can make quite a big difference.

There are two quick optimizations that you can make:

1) move the <value>s that you commonly use in the epsg file to the top  
of the file - proj will stop as soon as it finds the definition

2) copy the proj parameters from the epsg file into the projection  
object of your mapfile (or as a string in your php code in this case).

Cheers

Paul

On 28-Jun-08, at 4:26 PM, Ray Collett wrote:

> Thanks for the reply Nicol.  That looks simple enough.  My initial  
> test gave me this error message:
>
> Fatal error: [MapServer Error]: msProcessProjection(): projection  
> not named in /var/www/home/newlands/www_nc3d_com/temp/kml2mxs.php on  
> line 4
>
> I did some googling and found some suggested modifications that  
> fixed it:
>
> <?PHP
> dl('php_mapscript.so');
> $projInObj = ms_newprojectionobj('proj=latlong');
> $projOutObj = ms_newprojectionobj('init=epsg:2269');
> $poPoint = ms_newpointobj();
> $poPoint->setXY(-122.667591, 45.522973);
> $poPoint->project($projInObj, $projOutObj);
> print_r($poPoint);
> ?>
>
> It looks like the projectionstring "EPSG:####" does not work (at  
> least it does not work with the version in the latest Ubuntu package  
> php5-mapscript_4.10.3-1_amd64.deb).  I had to make the "epsg" lower  
> case and prepend an "init=".  But I now have a functioning  
> projection routine and I'm now off to write an XML routine to  
> process KML files.  What fun!
>
> Thanks!
> -Ray
>
> On Sat, Jun 28, 2008 at 2:40 AM, Nicol Hermann  
> <mapserver at geoworld.de> wrote:
> Ray,
>
> dl('../bin/php_mapscript.so');
> $projInObj = ms_newprojectionobj('EPSG:4326');
> $projOutObj = ms_newprojectionobj('EPSG:31466');
> $poPoint = ms_newpointobj();
> $poPoint->setXY(8.43, 50.4);
> $poPoint->project($projInObj, $projOutObj);
>
> print_r($poPoint);
>
>
> HTH
> Nicol
>
>
> Am Donnerstag, den 26.06.2008, 08:03 -0700 schrieb Ray Collett:
> > Hello all,
> >   I need to project UTM coordinates into stateplane, but I have no
> > need for drawing graphical maps.  My output is to be a script that
> > will be imported into another application.  I have found the
> > Geo::Proj4 for PERL, and I have a functioning skeleton program  
> that is
> > properly translating coordinates, but I'm not that familar with PERL
> > and I'm spending 10x the time trying to do what I want as opposed to
> > PHP which I know very well.  I'm looking for the same  
> functionality in
> > PHP, but having a hard time finding it.  I just discovered
> > PHP/MapScript, and I hope that it can do what I need, but so far I
> > have not found any samples that I can learn from. I have PHP/ 
> MapScript
> > installed and working, It's drawing maps and processing shp files.
> >
> > Here's a sample of the PERL code that I am using:
> >
> > ====================================
> > #!/usr/bin/perl
> > use Geo::Proj4;
> > my $proj = Geo::Proj4->new(init => "epsg:2269") or die;
> > my($lon, $lat) = (-122.667591,  45.522973);
> > my @newLatLon = $proj->forward($lat, $lon);
> > print "x:", $newLatLon[0]," y:", $newLatLon[1],"\n";
> > ====================================
> >
> > When run, it returns: x:7646617.87276814 y:684215.14079164
> >
> > Is there a way to do this in PHP?  Is MapScript the way to go, or is
> > there another project that I have not yet found that could do it for
> > me?  Any assistance is much appreciated!
> >
> > -Ray
> > _______________________________________________
> > mapserver-users mailing list
> > mapserver-users at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/mapserver-users
>
>
>
>
> -- 
> =======================================
> --==-- Ray Collett --==--
> Technical Director; Newlands & Co. Inc.
> 503.287.8000 x520 3dlover at gmail.com
> www.nc3d.com www.norwesters.org
> =======================================  
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-users


__________________________________________

    Paul Spencer
    Chief Technology Officer
    DM Solutions Group Inc
    http://www.dmsolutions.ca/




More information about the MapServer-users mailing list