0
votes

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
I'm not sure I understand the problem. You have the projection which relates lat/lon to x/y. Is the question you don't know this formula?TreyA
I want to pass the x,y coordinate of the div tag to calculate the actual latitude and longitude on the basemap below it.wuffwuff

1 Answers

0
votes

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;