[mapserver-users] calculating x,y from lat,lon

Walt Lin joemayfair at usa.net
Mon Sep 17 13:10:09 PDT 2001


Hi all,

I have mapserver generating a map image for me, and then I do my own calculation of x,y from lat,lon for certain points and overlay them.  Sometimes they line up correctly, but most of the time, the x coordinate is very accurate but the y coordinate is off by a small margin.  I would like to know the formula mapserver uses to calculate the pixel x,y from the lat,lon of a point, in the decimal degrees units.  I have looked through the source but couldn't find it.  The supposedly incorrect formula I have been using is:

x = (point_lon - left_lon) / (right_lon - left_lon) * image_width
y = (1 - (point_lat - lower_lat) / (upper_lat - lower_lat)) * image_height

(the pixel origin being in the upper left corner).  Also, it is not feasible to simply give mapserver the point and have it do the work.  I need to do the calculation outside of mapserver.  I am guessing that it has something to do with the curvature of the earth and whether it is projecting points with a normal to the earth's surface or a normal to the plane of the image?

Thanks for any help,
Walt



More information about the MapServer-users mailing list