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