简体   繁体   中英

How to calculate lattitude and longitude from x-y coordinates for geotagged images

In my react application, I have geotagged images with the center latitude-longitude, height and width. When clicked on the image I'm getting xy co-ordinates(pixels of image) where clicked.

I want to calculate the possible lat-lon co-ordinates from center lat-lon and x,y pixels of image.

Is there any way to do this ? Someone please help .

Thanks in advance !

Based on the comments above, if you have a scale of 1 pixel = 1cm ( which seems to be very small, if you have a 4000x2100px image, means you are about 40meters x 21meters )

To then calculate the lat-lon on click or hover of the xy position of the cursor:

const R = 6378160; // Earth Radius in meters
const scale = 0.01; ( in meters 1cm = 0.01m per pixel )
const midX = imageWidth / 2;
const midY = imageHeight / 2;

const dX = x - midX; // Difference for x position in pixel;
const dY = y - midY; // Difference for y position in pixel;

// Get the difference in meters
const dXScaled = dX * scale;
const dYScaled = dY * scale;

// Convert the difference in latitude, longitude
const dLat = ( dXScaled / R ) * Math.PI / 180;
const dLon = ( dYScaled / (R*Cos(Math.PI *lat/180))) * Math.PI / 180;

// Return new position
return {
  lon: lon + dLon,
  lat: lat + dLat,
}

You can verify the above answer with this https://scienceweb.whoi.edu/marine/ndsf/cgi-bin/NDSFutility.cgi?form=0&from=XY&to=LatLon ( if something is incorrect above, let me know I'll correct )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM