Home > Enterprise >  how to Convert longitude and latitude coordinates for world map image to cordinates (x , y) in pixel
how to Convert longitude and latitude coordinates for world map image to cordinates (x , y) in pixel

Time:01-26

I have a map of world.

I need to create a function that gets two double parameters (longitude and latitude) and that function should draw a small circle on that area in the map image.

I have the following info about the map:

The width of the map in pixels The height of the map in pixels ** I get to pixel X, Y based on that image.

i tried longitude = -106.346771 and latitude = 56.130366;

mapWidth = 3840.0 and mapHeight = 2160.0 ;

double x = (longitude 180) / 360 * mapWidth; double y = (1 - Math.log(Math.tan(Math.toRadians(latitude)) 1 /

Math.cos(Math.toRadians(latitude))) / Math.PI) / 2 * mapHeight;

result : [lon: -106.346771 lat: 56.130366]: X: 785.6344426666666 Y: 671.2084211650845

but not selected in right location

enter image description here

CodePudding user response:

Unfortunately, this problem is way harder than it seems.

That map is a Projection, so it is distorted from the original (roughly) spherical coordinate system your data is in.

(actually, your lat & long values may themselve be in one of several different projections, but that only really matters if you are doing very precise measurements.)

So your first order of business is to find out exactly what projection the map is using, then start looking for GIS libraries you can use in Java (I think there are several) to perform the translation.

CodePudding user response:

Decide on a radius, r, for your globe model. Your map will be 2πr pixels wide. Decide on a a latitude cutoff. You can't project a pole to a plane, and at extreme latitudes things get so distorted as to be unusable. 85 degrees is a common choice.

Express your latitude in radians: lat_r

You X coordinate is r * (lat_r π). So at 180° W your X coordinate is r * (-π π) = 0, and at 180° E your X coordinate is r * (π π) = 2πr

Express your longitude in radians: lon_r

Your Y coordinate is r * tan(lon_r) * (1 - cos(lon_r)). So at 85° N your Y coordinate is r * tan(1.4835) * (1 - cos(1.4835)) = 10.4r

  • Related