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

Julien-Samuel Lacroix jlacroix at MAPGEARS.COM
Fri Apr 20 11:56:41 EDT 2007


Hi,
You'll have to set the projection of all your layers in the mapfile. 
This why changing the projection of the map object won't affect them. 
Then you'll be able to use:
$map->setProjection("proj=robin,lon_0=0,x_0=0,y_0=0", MS_TRUE);

For the PostGIS SRID, you don't have to change anything if you set the 
PROJECTION in your layer.

Julien


Brent Wood wrote:
> --- 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
>>

-- 
Julien-Samuel Lacroix
Mapgears
http://www.mapgears.com/



More information about the mapserver-users mailing list