[mapserver-users] Convert Geo Points to Image Points
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:
$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.
Things are only difficult while you don't understand them.
Use video conversation to talk face-to-face with Windows Live Messenger.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the mapserver-users