Get latitude/longitude of an image's corners based on two other points

47 Views Asked by At

I have an image that represents a region on the map. For example, this image is 10000px wide by 8000px high. I don't know what the area of this region represented in the image is in terms of m².

What I can do is select a point in the image (x, y) and match that point on the map to get the latitude, longitude. I can do this with almost all points/pixels in the image except those on the edge (imagine that the image has a wide border that is just a white space, and I cannot relate these points within the map to obtain the latitude/longitude).

My goal is to add this image inside the map in a way that it fits perfectly on the map. For this I have to use Leaflet's ImageOverlay feature. However, to use this feature, I need to specify the image's bounds. In other words, I would need the latitude/longitude of two specific points in the image: bottom left and top right.

The first thing I tried was to obtain the equation of the line. As I have the relationship of two other points, I can draw the equation of the latitude/longitude line for this map and then obtain the latitude of every x/y. But as you can already imagine, since the map isn't a "2d plane", the straight line equation appears to be inefficient here.

In pixels, these points would be respectively (0px, 8000px) and (10000px, 0px). Unfortunately these are points that I cannot relate manually due to the mentioned border problem. Is there some kind of calculation I can do to get the latitude/longitude of these fields?

Note that what I want is different from "Convert X,Y pixel to Longitude and Latitude" because in this example the user has precisely the latitudes/longitudes of the corners (max/min lat/long), which I'm missing.

It's also different from "Convert/distort image to match Mercator projection" because again the user knows the coordinates of all corners of the image, which is exactly what I'm missing.

I don't think it's necessary to share the code because I believe the problem is one of mathematics and not programming. What I can do is share the variables I have:

Image width: 15767px Image height: 10629px

This image represents a region on the map, just like this image here.

I can relate some points more in the center of the image, such as:

var points = {
    a: {
        lat: -23.189714427995956,
        long: -45.95251764954021,
        x: 5896,
        y: 2908
    },
    b: {
        lat: -23.19225387170598,
        long: -45.95226547201594,
        x: 6123,
        y: 5432
    }
};

With these variables I need a function that returns the latitude/longitude of any point (x, y) within the image. Of course, my interest is not to obtain the latitude/longitude of ALL points. The points that really interest me are those necessary to obtain the image's bounds and then be able to use the ImageOverlay feature correctly.

The points are bottom left (0, 10629) and top right (15767, 0).

0

There are 0 best solutions below