[Mapserver-users] shape bounds for map and layer with different projections
Sean Gillies
sgillies at frii.com
Thu Aug 14 11:50:32 PDT 2003
On Thursday, August 14, 2003, at 10:38 AM, Armin Burger wrote:
> Hi
>
> I found a problem with map and layer having different projections:
>
> For queries I want to display the result with a link that allows a zoom
> to the respective feature in the map. In MapScript I use the function
> $shape->bounds
> to get the shape extent used for the zoom-to-feature. This works well,
> when layers are in the same projection as the map.
>
> If the layer, however, has a different projection, then the shape
> bounds
> are returned in the layer projection, not in the map projection. This
> way, you cannot use this extent rectangle to make a zoom in because it
> typically is of a completely different dimension compared to the map
> projection.
>
> I was thinking of a workaround by re-projecting the shape extent
> rectangle. For that I have to get the map projection and apply this
> projection to the rectangle. This may work when the projection is
> defined
> explicitely with all parameters (lat_0, lon_0, ellipsoid, etc) but not
> when using the 'init=epsg:xxxx' notation. With epsg, the request
> $map->getProjection() just retrieves the string 'init=epsg:xxxx'. But
> to
> define a new projection object (ms_newprojectionobj) I have to define
> the
> projection with all the single parameters and not just the epsg.
>
> I hope that I expressed this small 'problem' in an understandable way
>
> Is there a solution possible to solve that? The best would be to have
> the
> '$shape->bounds' return the extent in map projection. A maybe simpler
> solution might be to have the ability to define a projection object via
> epsg. Perhaps this would be similar to the 'setWKTProjection()' method
> that exists for layers and maps.
>
> Any thoughts about it?
>
> Regards
>
> Armin
You _can_ construct a projectionObj from an "init=epsg:xxxx" string.
In the code below I create a rectObj and then project it from map
projection to an arbitrary EPSG projection. This is using the 4.0
MapScript and should be equally applicable to Perl.
Python 2.1.3 (#18, Jun 24 2003, 18:02:42)
[GCC 3.1 20020420 (prerelease)] on darwin6
Type "copyright", "credits" or "license" for more information.
>>> from mapscript import *
>>> mapobj = mapObj('/Users/sean/Projects/ZMapServer/demo/demo.map')
>>> e = mapobj.extent
>>> e.minx, e.miny, e.maxx, e.maxy
(388108.0, 5203121.0, 500896.0, 5315909.0)
>>> mapobj.getProjection()
'init=epsg:26915'
>>> prj_map = projectionObj(mapobj.getProjection())
>>> prj_nad83 = projectionObj("init=epsg:4269")
>>> f = rectObj()
>>> f.minx = e.minx
>>> f.minx, f.miny, f.maxx, f.maxy = e.minx, e.miny, e.maxx, e.maxy
>>> f.project(prj_map, prj_nad83)
0
>>> e.minx, e.miny, e.maxx, e.maxy
(388108.0, 5203121.0, 500896.0, 5315909.0)
>>> f.minx, f.miny, f.maxx, f.maxy
(-94.499615104017138, 46.972164652306077, -92.987989369267908,
47.996480038279742)
cheers,
Sean
--
Sean Gillies
sgillies at frii dot com
http://www.frii.com/~sgillies
More information about the MapServer-users
mailing list