[mapserver-users] MapScript and ZoomRectangle (and rectObj problems)
Jim Strevinas
voas_acc at hotmail.com
Sat May 2 06:20:43 PDT 2009
> Date: Sat, 2 May 2009 00:35:46 +0200
> From: Baas at speerit.nl
> To: mapserver-users at lists.osgeo.org
> Subject: [mapserver-users] MapScript and ZoomRectangle (and rectObj problems)
>
> Hello List,
>
> Three years ago, I built a web interface for our primary application
> using MapServer. Now we're in the process of building that same
> application in VB.Net (but with more features) using MapScript.
>
> Although everything comes along nicely (I love the fact that everything
> returns objects, etc) there is one huge problem that I can't seem to
> solve: creating and using the rectObj class. I read a lot about it and
> found many bug cases, older messages, etc, but I still can't make heads
> or tails of it. I'm sorry about asking it, since it must be the
> millionth time this question has been asked.
>
> I *CAN* get ZoomRect with a rectObj to work when using image coords,
> even though that requires my own code that flips miny and maxy to solve
> that lovely error about miny => maxy or something. When I try to use it
> with map coords however, I can't get it to work.
>
> In my init code I create a new rect object:
> Map = New mapObj(strMapPath)
> FullExtent = New rectObj(0, 0, 0, 0, 0)
> With Map.extent
> FullExtent.maxx = .maxx
> FullExtent.minx = .minx
> FullExtent.maxy = .maxy
> FullExtent.miny = .miny
> End With
>
> When I feed this to ZoomRectangle using
> Map.zoomRectangle(FullExtent, MapWidth, MapHeight, Map.extent, Nothing)
> I get that famous "mapscript::mapObj::zoomRectangle(): General error
> message. image rectangle maxy >= miny".
>
> When I flip miny and maxy I end up in the middle of the Sahara (while
> the original coords should show the Netherlands).
>
> Things I wonder about:
> 1) How can I get zoomRectangle to work with world/map coords instead of
> image coords?
> 2) Why does the constructor have an "imageunits as integer"? IMHO a
> simple rect object has nothing todo with the coordsys of the/a map
> (since I can more than one).
> 3) When will the much discussed bugfix be applied that automaticly flips
> miny/maxy?
>
> Any help would be greatly appreciated,
>
> With kind regards,
> Jelmer Baas
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-users
Hi,
When I want to use ZoomRectangle with real coordinates, i always transform
the real coordinates to image coords based on the current rendering of the map.
I talk about current rendering because one must compute the pixels by geographical
degrees of the image. A simple function to do such conversion could be:
# Width and height of the map image (from mapObj.width)
# X,Y are the real coord pair
# real_extent from mapObj.extent
def map2img (width, height, x, y, real_extent):
ppd_x=0
ppd_y=0
new_x=0
new_y=0
ppd_x = width / ( real_extent.maxx - real_extent.minx ) # pixel per degrees
ppd_y = height / ( real_extent.maxy - real_extent.miny )
new_x=ppd_x * ( x - real_extent.minx )
new_y=height - ppd_y * ( y - real_extent.miny )
return (new_x , new_y)
Thus, the two pairs of real coordinates can be converted using two call to this
function (there exists a distortion though in large scales).
Beware that if your map is using a different "output" projection than the
REAL zoom coordinates are (say, zoom coords are latlong while map is LAEA)
you should first use a method to reproject the coords to the map's projection equivelant
(i do sth like this using the OGR/GDAL's osr module)
Finally, prevent minx>maxx error by requiring that the users define the proper points for
the input rectangle say (UL and LR) or (UR and LL)
Hope this helps a bit.
_________________________________________________________________
Show them the way! Add maps and directions to your party invites.
http://www.microsoft.com/windows/windowslive/products/events.aspx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20090502/af56ccbc/attachment.htm>
More information about the MapServer-users
mailing list