[mapserver-users] Convert Geo Points to Image Points

Gail Long codeburg at hotmail.com
Thu Jul 17 09:11:33 EDT 2008


I'm trying to convert a geopoint into an image coordinate so I can place images on a floating div over a map.

I know how to go from image points to geo points and figured that just reversing the process was the way to go back.  Apparently it is not.

Here is what I was trying:

<?php
$minx_geo = 2422041.973271;
$miny_geo = 654245.367973;
$maxx_geo = 2565405;
$maxy_geo = 781169.610946;

$minx_img = 0;
$miny_img = 0;
$maxy_img = 200;
$maxx_img = 300;

$mapwidth = 300;
$mapheight = 200;

$xdelta_geo = $maxx_geo - $minx_geo;
$ydelta_geo = $maxy_geo - $miny_geo;

$xdelta_img = $maxx_img - $minx_img;
$ydelta_img = $maxy_img - $miny_img;

$x_pix = 150;
$y_pix = 100;

// Calculate the image coords to map extents
$x_geo = $minx_geo + (($x_pix/$mapwidth) * $xdelta_geo);
$y_geo = $maxy_geo - (($y_pix/$mapheight) * $ydelta_geo);

// Calculate map points to image coords
$x_img  = $minx_img + (($x_geo/$mapwidth) * $xdelta_img);
$y_img = $maxy_img  - (($y_geo/$mapheight) * $ydelta_img);

print "$x_geo $y_geo\n";
print "$x_img $y_img\n";

I'm math challenged so this probably is easier than it seems but I'm not groking it.  

Thanks very much for any assistance.

Gail
?>

--
Things are only difficult while you don't understand them.
_________________________________________________________________
Use video conversation to talk face-to-face with Windows Live Messenger.
http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_video_072008
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20080717/fe6c4d83/attachment-0001.html


More information about the mapserver-users mailing list