[Proj] get lat\lon from mouse position on image

Doğan -- doganay44 at gmail.com
Tue Apr 1 12:46:49 EDT 2008


Hi, I have *.jpg of a map and want to get lat\lon of mouse position on
*.jpg.
I know the *.jpg file size (ex. 1024x768) and *.jpg lat\lon top_left
corner(ex. N2030,320,E01015,400)
and bottom_right corner(ex.N1030,220,E01814,300 )
I do this as below code.
How to do this with proj4 lib or another more efficient way.
(if ı use another *.jpg of map projections different from mercator below
code wil be fail.(?)  )


QString Map::Y2Lat(int Y_size_of_image)//Y_size of jpg ( 768 )
{
//distVincenty(lat1,long1,lat2,long2) returns distance in NM.
//here give long same because , want to know *.jpg y size in real.
double YRealDist = distVincenty("2030,320","N","01015,400","E",
"1030,220","N","01015,400","E");

double YPerPixel=YRealDist/Y_size_of_image;// real distance per pixel of
image

double convfaktor=YPerPixel*currentMousePosY;//real distance from top to
current mouse pos.

//gives destination lat  from top_left  convfaktor miles with course 180
QString newLatLon =
destinationVincenty("2030,320","N","01015,400","E",180.,convfaktor);
QString Latitude =toDMS(newLatLon.toDouble(),"NS");

qDebug()<<"Current mouse position Lat = "<< Latitude ;
return Latitude;
}

QString Map::X2Long(int X_size_of_image)//X_size of jpg ( 1024 )
{
double top_left_lon = dm2dd("01015,400","E");//long in degree

double bottom_right_lon = dm2dd("01814,300","E");//long in degree

double XRealDist=(bottom_right_lon-top_left_lon)*60.;//using mercator map 1
degree 60 miles

double XPerPixel=XRealDist/X_size_of_image;

double convfaktor=XPerPixel*currentPosX;//top left to mouse pos distance in
X

double newLong=top_left_lon + convfaktor/60.;

QString Long=toDMS(newLong,"EW");

qDebug()<<"Current mouse position Long = "<< Long ;
return Long;

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/proj/attachments/20080401/c7eb9d97/attachment.html


More information about the Proj mailing list