[Mapserver-users] MapScript: map-Y coordinate is always wrong while map-X is right
Eric Bridger
eric at gomoos.org
Tue Jul 8 09:11:56 PDT 2003
One issue, which bit me when I was dealing with this, was that when
using mapscript you should ensure that the aspect ratio of your image
(SIZE) should closely match the aspect ratio of your map
extents.(EXTENT). i.e
x/y = (maxx - minx) / (maxy - miny)
Eric
On Tue, 2003-07-08 at 19:31, Bjoern Platzen wrote:
> Hi Sean, Adam and Lowell,
>
> thanks for your Support, but I think, I took a way into a
> one-way-street...
>
> I think I'll start again with the whole MapXY & Extend-Thing. Whatever I
> did, and with all your tipps, I couldn't get it going. At least I tried
> the following:
>
> def _click2map2(self,clickX, clickY, Extend):
> '''Uebersetze Klick-Koordinaten in Kartenkoordinaten'''
> Extend = Extend.split(" ")
>
> cx = (clickX/self.mymap.width)
> cy = 1-(clickY/self.mymap.height)
>
> xMap = float(Extend[0])+((float(Extend[2])-float(Extend[0]))*cx)
> yMap = float(Extend[1])+((float(Extend[3])-float(Extend[1]))*cy)
>
>
> return (xMap,yMap)
>
> This was a step in the right direction, but not yet right...
> (now I've got Y = 5668350 where it should be 5669095 (Gauss-Krueger)
>
> Maybe It's the wrong Extend, I'm calculating with. I think, I should
> calculate with the imgext and not the mapext, right?
> So when the first calculation of imgext is wrong, every clickpoint has
> to be wrong as well.
>
> I'm going to figure it out tomorrow...
>
> Thanks for your help,
>
> Bye Bjoern.
>
>
> Am Dienstag, 8. Juli 2003 16:49 schrieb Sean Gillies:
> > Hi Bjoern,
> >
> > I found the problem in your code. See below.
> >
> > On Tuesday, July 8, 2003, at 07:57 AM, Bjoern Platzen wrote:
> > > Hello List,
> > >
> > > maybe I'm just to blind, but I can't figure out, what is going
> > > wrong.
> > >
> > > I wrote a small Program using PythonMapscript.
> > >
> > > I'm calculating the following to get the Map-Coordinates from the
> > > Click-Coordinates (where clickX and clickY come as img.x and img.y
> > > from a HTML-form, Extend is the [mapext]):
> > >
> > > def _click2map(self,clickX, clickY, Extend):
> > > '''Uebersetze Klick-Koordinaten in Kartenkoordinaten'''
> > > Extend = Extend.split(" ")
> > >
> > > cx = (float(Extend[2])-float(Extend[0]))/(self.mymap.width-1)
> > > cy = (float(Extend[3])-float(Extend[1]))/(self.mymap.height-1)
> > >
> > > xMap = float(currentExtend[0])+cx*clickX
> > > yMap = float(currentExtend[1])+cy*clickY
> >
> > should be:
> >
> > yMap = float(currentExtent[1])-cy*clickY
> >
> > Remember that the origin of your image is the upper left corner
> > and so your new map point will always have a smaller y value. Also,
> > it looks like you are calculating cx and cy incorrectly.
> >
> > Here is an example of how this calculation is done in ZMapServer
> > (http://zmapserver.sourceforge.net):
> >
> >
> > extent = (mapobj.extent.minx,
> > mapobj.extent.miny,
> > mapobj.extent.maxx,
> > mapobj.extent.maxy )
> > width = mapobj.width
> > height = mapobj.height
> > pxsize = (extent[2]-extent[0])/width
> > pysize = (extent[3]-extent[1])/height
> > point = {}
> > point['x'] = extent[0] + pixel*pxsize
> > point['y'] = extent[3] - line*pysize
> >
> > cheers,
> > Sean
>
> --
> small office solutions
> info at sosnetz.de - http://www.sosnetz.de
>
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
>
More information about the MapServer-users
mailing list