[Mapserver-users] MapScript: map-Y coordinate is always wrong while map-X is right
Sean Gillies
sgillies at frii.com
Tue Jul 8 07:49:47 PDT 2003
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
--
Sean Gillies
sgillies at frii dot com
http://www.frii.com/~sgillies
More information about the MapServer-users
mailing list