Question

I have top view image of my house and know lat longitude for left top pixel i.e 0,0 now how to get latitude longitude values of other pixels?

While googling i came across following:

function longToX(longitudeDegrees)
  {
    var longitude =degreesToRadians(longitudeDegrees);
    return (radius * longitude);
  }

  function latToY(latitudeDegrees)
  {
    var latitude =degreesToRadians(latitudeDegrees);
    var newy = radius/2.0 * 
            Math.log( (1.0 + Math.sin(latitude)) /
                      (1.0 - Math.sin(latitude)) );
    return newy;
  }

 function xToLong(xx)
  {
    var longRadians = xx/radius;
    var longDegrees = radiansToDegrees(longRadians);

    /* The user could have panned around the world a lot of times.
    Lat long goes from -180 to 180.  So every time a user gets 
    to 181 we want to subtract 360 degrees.  Every time a user
    gets to -181 we want to add 360 degrees. */

    var rotations = Math.floor((longDegrees + 180)/360)
    var longitude = longDegrees - (rotations * 360)
    return longitude;
  }

  function yToLat(yo)
  {
    var latitude =  (Math.PI/2) - 
                    (2 * Math.atan(
                       Math.exp(-1.0 * yo / radius)));
    return radiansToDegrees(latitude);
  }  

radius = 6371 km radius of earth.. but however if i pass 0,0 i get 0,0 how to fix latitude longitude for 0,0 and derive from it other values

Was it helpful?

Solution

You need to know the distance between pixels. To convert distance to degrees, you can use the fact that one nautical minute (1/60 of a degree) latitude is 1,852 meters or about 6076 feet. The longitude is the same at the equator, but you need to multiply by the cosine of the latitude elsewhere.

One degree latitude = 1852 meters

One degree longitude = 1852 meters * cos(latitude)

(You might need to multiply the degrees latitude by pi/180 to convert them to radians for the cosine function.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top