7

I'm having difficulty calculating the latitude and longitude values of an image that I am hosting inside of a div tag on my webpage. I can easily figure out the x,y (pixel) coordinates of the image and save them to a variable inside of my script. Here's the tricky part...

The map is not a mercator projection, so I cannot simply linearly interpolate the x,y pixel coordinates to lat and lon values. However, I do have the luxury of knowing the latitude and longitude of all four corners of the image (see posted diagram), projection of the map on the image, central meridian, and latitude of origin.

http://i.imgur.com/xcGQCk1.png

The 800x600 pixel image is of the U.S. and I am basically trying to capture the latitude and longitude on click by passing the x,y pixel coordinates. I am assuming I will need some sort of transformation function.

greener
  • 4,989
  • 13
  • 52
  • 93
wuffwuff
  • 730
  • 2
  • 9
  • 19
  • you could play with the precision to give an approximate base on the extrapolation. how precise do you wan to be ? – Jeffrey Nicholson Carré Mar 09 '13 at 05:41
  • I'd like to be as precise as possible, but I'm open to any ideas. What do you mean by, "approximate base on the extrapolation"? – wuffwuff Mar 09 '13 at 05:49
  • 2
    GIS (Geographic Information System) at http://gis.stackexchange.com/ would be a more appropriate site for this question. –  Mar 09 '13 at 07:06
  • 1
    two questions : how do you get the map and the GPS coordinates ? how precise are the coordinate of the 4 points? – Jeffrey Nicholson Carré Mar 09 '13 at 07:12
  • They are precise. The map is a static GIF image, and I can pass the x,y pixel coordinates on mouse click from the div tag. – wuffwuff Mar 09 '13 at 15:14
  • 2
    Does [this](http://mathworld.wolfram.com/StereographicProjection.html) help you? (see eqs. (4) and (5)) – Voitcus Mar 09 '13 at 20:59
  • I see the equations but I'm not sure I understand how to use them or how they would help. – wuffwuff Mar 09 '13 at 21:54
  • Okay, yes, eqn 4 and 5 certainly help. Only problem now is that those equations are dependent on rho and c. Rho is easily calculated with x and y, but c is dependent on R, which is then dependent on something called the conformal latitude. Not sure I can figure out this R piece... – wuffwuff Mar 10 '13 at 00:09
  • If 'R' is simply the radius of the Earth, it doesn't specify the units to use? – wuffwuff Mar 10 '13 at 06:07

1 Answers1

0

It might (for the sake of your sanity) be easier to have use a map API like Leaflet or Google maps on the page and just fix the position and then use the LatLng from the on click event.

A quick look at the Leaflet.js API suggests that's possible and it looks like you can do it with google maps too. It's a little bit of a fiddle to make sure you've disabled all the drag and zoom possibilities. BUT it seems, to me, much easier as all the projection work is done for you.

Unless there really is a burning reason why you need THAT image of the US. But even then you might be able to overlay the picture on the map.

ChrisIPowell
  • 494
  • 2
  • 6
  • I am facing somewhat the same issue where i wanted to find lat longs from images. I'm doing analytics on images which is not possible on google maps. but once i do my analytics i need to find the lat long of the position ive identified. – chrisgiffy May 08 '18 at 15:09