Image Pixel X,Y coordinates to Lat/Lon

南笙酒味 提交于 2020-01-17 07:03:54

问题


I have a unique problem re: projections and obtaining lat/lon coordinates from an image.

I have an 800 x 600 pixel image of the U.S., and I know the projection (Polar Sterographic with a -75 lon center of origin), lower left lat/lon, and upper right lat/lon of the image. I've put the image into a webpage and I am able to mouse over the image and obtain the x and y "pixel" coordinates from the image in the div tag. Is there a simple formula to help obtain the lat and lon of the x/y pixel coordinates?

I would like a streamlined process because I have multiple map projections and image sizes.


回答1:


Here's the commented js code for how to do it:

//these define lat/lon at the bounds of the image
var geo_left=-75;
var geo_right=75;
var geo_top=-75;
var geo_bottom=75;

//dimensions of the canvas
//i set it to 400x400 for example purposes
var canvas_width=400;
var canvas_height=400;

//get relative coordinate of pixel, should be on a scale of 0 to 1
var rel_x = pixel_x/canvas_width;
var rel_y = pixel_y/canvas_height;

//linear interpolate to find latitude and longitude
var latitude = geo_left+(geo_right-geo_left)*rel_x;
var longitude = geo_top+(geo_bottom-geo_top)*rel_y;


来源:https://stackoverflow.com/questions/15285940/image-pixel-x-y-coordinates-to-lat-lon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!