Changing Map Projection Dynamically
Steve Lime
Steve.Lime at DNR.STATE.MN.US
Fri Jul 13 15:47:05 PDT 2007
It is an interesting problem. MapServer templates do allow you access to the bbox for an map
in both lat/lon and the projection of choice. If you are willing to live with a bit of slop you could
change projections on the client and use the lat/lon bbox as an intermediate value.
I would be tempted to change projections after a user submits a request (e.g. onSubmit). You
have the scale value of the current map, you also have the current extent and the requested
zoom value. You could with just a little bit of javascript determine a rough new scale by multiplying
the old scale by the zoom factor and then change the projection (e.g. map_projection accordingly)
and use the lat/lon bbox. It wouldn't be exact but would work I think.
MapServer also has a little known feature called scale dependent templates. They were added
for a purpose like this but I've never used them. Basically in the webObj you can set MINTEMPLATE
and MAXTEMPLATE and when you hit the MINSCALE or MAXSCALE values those templates are
used if defined. The can be HTML templates or URL templates. So for example, you could have an
application where you zoom in to a point and then hand off to another application. The lat/lon
values become the bridge.
So for example, you might have separate mapfiles for each projection. They could use the same
guts:
MAP
NAME 'scale1000to10000'
...
PROJECTION
...
END
WEB
MINSCALE 1000
MAXSCALE 10000
MINTEMPLATE 'http://mapserver.mydomain.com?map=scale0to1000.map&mapext=[mapext_latlon]&[layers]'
MAXTEMPLATE 'http://mapserver.mydomain.com?map=scale10000to100000.map&mapext=[mapext_latlon]&[layers]'
...
END
INCLUDE 'layers.map'
END
MAP
NAME 'scale0to1000'
...
PROJECTION
...
END
WEB
MAXSCALE 1000
MAXTEMPLATE 'http://mapserver.mydomain.com?map=scale1000to10000.map&mapext=[mapext_latlon]&[layers]'
...
END
INCLUDE 'layers.map'
END
and so on...
Then you'd move between the applications as the scale changed, or at least that was the idea. This handles the in/out
issue but not the east/west issue. Now, off course the min/max template could trigger a query that might, for example,
set the write state plane or UTM zone and the query result fires off the right URL with the right projection, the layer list
and so on. That would be all server based...
Steve
>>> On 7/12/2007 at 10:02 PM, in message
<ae9185aa0707122002wfd625eie7f6c729656b9fbf at mail.gmail.com>, Richard Greenwood
<richard.greenwood at GMAIL.COM> wrote:
> On 7/12/07, Frank Warmerdam <warmerdam at pobox.com> wrote:
>> Bill Thoen wrote:
>> > This has probably been asked before, but I can't find any info on it.
>> > Basically, I'd like to know how to change the map projection in
>> > MapServer as I zoom in to a larger scale map view. Specifically, I start
>> > at a national scale using a Lambert projection, but when I zoom into a
>> > state scale, I'd like to choose a more appropriate projection (like
>> > State Plane).
>> >
>> > Can this be done easily with a map file or an HTML template? What's the
>> > best way to solve this problem?
>>
>> Bill,
>>
>> I likely shouldn't speak up since I don't really know the best way to do
>> this. But I do not believe it can be done entirely from the server side
>> with mapserv cgi and a map file. Either you would have to have a mapscript
>> application on the server that decided at some point to switch projections
>> or you would have to engineer all the logic on the client side.
>>
>> With WMS you can request specific projections using the SRS (or CRS?)
>> item in the request. With the non-OGC "classic" mapserver interface
>> there is also a way of overriding the map projection which I think has
>> been recently discussed on this list though I don't know the exact
>> details.
>>
>> But one important thing to remember is that the region requested is going
>> to have to match the projection which means there has to be quite a bit
>> of smarts either in the client (to change the coordinate system of the BBOX)
>> or in a mapscript script on the server to reproject the requested box into
>> the alternate projection. And in that case the returned window won't
>> be exactly what was requested.
>>
>> 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
>>
>
> Bill,
>
> You have a pretty interesting problem. Frank summarized the challenges
> that you may encounter . If you decide to do it on the client side,
> there is a JavaScript port of some of the Proj.4 code at:
> http://svn.codehaus.org/mapbuilder/cscs/trunk/cscs/
> that might be useful. I am particularly interested determining an
> appropriate coordinate system based on location.
>
> Please keep us posted.
> Rich
More information about the MapServer-users
mailing list