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

Michael Schulz mschulz at WEBGIS.DE
Fri Apr 20 06:36:55 EDT 2007


Hi Stef,

> 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 ?)

I'd say you will have to set the projection of the returned map. That
is the projection obj from your mapObj. As you mentioned, there is the
setProjection method:
setProjection( string proj4 ) : int - Set map projection from PROJ.4
definition string proj4.

I'm not sure, but it may be crucial to set the projection of your map
before setting a new projectet extent.

> 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) ??

I don't think so, since the data of your layer in PostGIS is in 4326,
your layer projection will also remain 4326. On-the-fly projection
implies that the projection takes place between the layer projections
to the resulting map projection.

Cheers, Michael


-- 
-----------------------------------------------------------
Michael Schulz
mschulz at webgis.de

in medias res
Gesellschaft für Informationstechnologie mbH

In den Weihermatten 66
79108 Freiburg

Tel  +49 (0)761 556959-5
Fax +49 (0)761 556959-6

http://www.webgis.de / http://www.zopecms.de
-----------------------------------------------------------



More information about the mapserver-users mailing list