[Mapserver-users] Re: Converting an image point to a geog. space point

pkishor_98 pkishor at geoanalytics.com
Tue May 13 11:26:38 EDT 2003


--- In mapserver-users at yahoogroups.com, "Adam Zornes" <zornes at a...> wrote:
> All,
>  
>             I am trying to query points in php/mapscript.  I get a point
> from the previous form just fine, but I can't seem to get it to convert
> to a proper geog. space point.  Does anyone have an example of how to do
> this, 

you can use the code frag provided by Charles.

> or just an explanation of how to find the actual map size and the
> current map size so that I can work up a formula of my own?
>  

but here is an explanation.

You can find out the actual map dims using any of your script methods

1. in perl, for example, $mapObj->{width} in the x direction (lets
just consider the width for now)

2. You also know how large your image is... say pw pixels wide.

3. So, pw pixels on the screen is the same as $mapObj->{width} on ground

4. So, 1 pixel on the screen is the same as ($mapObj->{width}/pw)

5. If you clicked at a point (px, py) measured from (0,0) of the
image, px will (($mapObj->{width}/p) * px).

6. To get the actual coord, you will add the $minx of the map to the
number you get in #5 above = $minx + (($mapObj->{width}/p) * px)

Now, you would do the same for the y direction, except -- the (0,0) of
the image is from the top-left, while the (0,0) of the map is from
bottom-left. So, you would flip the py before doing any calcs. That
is, instead of py, use ($image_height - py).

Everytime you send the image to the browser, send the bounds ($minx,
$miny, $maxx, $maxy) of the map as hidden form vars. When they are
returned with the new point click, you have them available for doing
the calcs in step #6 above.

Wrap the entire logic in a neat little function, and calculate away
merrily.

Hope this helps.




More information about the mapserver-users mailing list