Mapscript Re-Projection on-the-fly

Frank Warmerdam warmerdam at POBOX.COM
Thu Aug 24 10:38:44 EDT 2006


Delfos, Jacob wrote:
> Hi Stefan,
>  
> Yes, you do have to specify which projection each layer is in, otherwise 
> when they are reprojected you will run into trouble (if it doesn't know 
> where to reproject FROM, it won't be able to do i). It's not too hard, 
> though.
>  
> You should not have to recalculate the extent; it should be automatic. 
> Definitely don't try to change the numbers (coordinates) without 
> changing the projection (that would be bad).
>  
> Try this:
>  
> $newproj="proj=robin,lon_0=0,x_0=0,y_0=0"; // projection string of your 
> new projection
> $map->setProjection($newproj,MS_TRUE);
>  
> I think that ought to be all.  The MS_TRUE makes it pick the best fit to 
> the current extent in the new projection. Make sure your projection 
> string is valid.

Jacob,

A good suggestion!

Just to pick a nit or two, I'd like to encourage people to use the "+"
syntax for projections as it avoids some quirky things with the above
approach.  The plus notation would look like:

   $newproj="+proj=robin +lon_0=0 +x_0=0 +y_0=0";

or as a PROJECTION block:

   PROJECTION
     "+proj=robin +lon_0=0 +x_0=0 +y_0=0"
   END

Also, it is a good practice to include an explicit ellipse or datum
in coordinate system definitions.

   $newproj="+proj=robin +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84";

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org



More information about the mapserver-users mailing list