Change Projection on-the-fly; Using PostGIS - How?

Brent Wood pcreso at PCRESO.COM
Fri Apr 20 06:29:32 EDT 2007


--- Stefan Schwarzer <stefan.schwarzer at GRID.UNEP.CH> wrote:

> Hi there,
> 
> i am struggling since quite a while to set-up a change-projection-on- 
> the-fly possibility for our website mapserver. But somehow, I don't  
> really have the clue how to do it. Now, making things "worse" (more  
> complicated for me) we have migrated from MySql to Postgres/Postgis.
> 
> ------------------------------------------------------------------------ 
> ----


At least your spatial queries now have a chance of returning correct answers
:-)

The way I prefer to do this is to have the SQL thrown at Postgis do the
conversion, so mapserver doesn't have to. Thus:
  select transform(the_geom, SRID) 
instead of 
  select the_geom

But that's probably just because I have a SQL/database background, so tend to
do my work there. But it saves the wrestling with mapscript that you're going
through :-)  


Cheers,

   Brent Wood

> 
> So, first question would be: What code to use to change the  
> projection via PHP/Mapscript, should be something like this, I guess:
> 
> $newproj=ms_newprojectionObj("proj=robin,lon_0=0,x_0=0,y_0=0");
> $latlon=ms_newprojectionObj("+proj=longlat +ellps=WGS84 +datum=WGS84 
> +no_defs");
> $oldext=ms_newRectObj();
> $oldext->setextent(-180,-90,180,90);  //this is the extent of my map  
> in geographic
> $oldext->project($latlon,$newproj);  //reproject to Robinson
> $map->setextent($oldext->minx,$oldext->miny,$oldext->maxx,$oldext- 
>  >maxy);  //set the new map extent
> 
> But I guess, something is still missing... (What about $map- 
>  >setProjection ?)
> 
> ------------------------------------------------------------------------ 
> ----
> 
> And the second question is: As my mapfile queries the postgis  
> database, using "SRID", I guess I need to change that one too, then?  
> Instead of 4326 for Geographic I would have to use the one for  
> Robinson (or Mollweide or so) ??
> 
> ------------------------------------------------------------------------ 
> ----
> 
> Thanks for giving me any hints...
> 
> Stef
> 



More information about the mapserver-users mailing list