0

I have a similar question to the one found here, Mercator projection: formula for latitude based on pixels? The answer was very helpful but my question is just different enough that it doesn't quite solve it.

Problem: Determine the latitude based on the mouse position on a map.

  1. The map is 1000 pixels tall
  2. Pixel 1 = Equator
  3. Pixel 1000 = 80 degrees latitude

Is there an equation that determines at pixel X (for example 400) the mouse is at latitude Y (maybe 30 degrees)?

  • 1
    What software or API are you using? What CRS is the raster in? Is pixel 1 the first pixel or the 2nd? (0 or 1 based counting).. if pixel 1 is the 0th and your map is geographic then your cell size is 0.08 (80/1000), so therefore if you can find the pixel row your latitude is Row * 0.08 in decimal degrees (if pixel X is row 400 your latitude is 32), it gets more complicated if your raster isn't geographic, if this is so then you'll need to specify an API to calculate the cell E,N then project the E,N to Lon,Lat. – Michael Stimson Mar 1 '18 at 22:45
  • @MichaelStimson I'm testing this in Photoshop but then I'm going to program the equation with Javascript. Since it's Photoshop and not zero based pixel 1 is the equator and pixel 1000 is 80 degrees. But those numbers are just for testing. BTW I've been to Brisbane. It's paradise! 8-) – DR01D Mar 1 '18 at 22:51
  • Ah, I see, I'm not an expert in Java so can't help there but you should find the equation about right provided your raster is geographic, the real task starts when you need to go from Cell -> Map -> Geographic; you have stated that your map is in Mercator projection so a straight Cell -> Geographic formula like the one I suggested won't be accurate, projection is a function of an API like Proj.4 (have a look at stackoverflow.com/questions/38906402/… and see if that helps). Brisbane is nice, a bit hot at the moment though. – Michael Stimson Mar 1 '18 at 23:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.