Convert Cartesian (X,Y) to coordinates GPS (Latitude & Longitude)

南楼画角 提交于 2021-02-11 14:51:18

问题


I need to convert coordinates X, Y into Latitude and Longitude. I've read wikipedia map projections, similar stackoverflow forums, applied my custom solutions and still didn't work.

The coordinates I get from my formula are wrong, Longitude is acceptable but Latitude is not. I don't see where my calculous is wrong.

The X,Y Point is taken from a JLayeredPane with the size of a background Map image, once a smaller image is released on this Map image, the point is taken.

public void mouseReleased(MouseEvent e) {               
    DM.setUpCoordinates(layeredPane.getComponent(index-1).getLocation());       
}

After this, I'm trying to correctly calculate the Latitude and Longitude projection. The data I own is:

  1. X,Y coordinates from the Map
  2. Total width and height from the Map
  3. Latitude and Longitude where the map is centered

What I have tryied so far:

Trying Equirectangular projection

public void setUpCoordinates(Point p) {     
    //Equirectangular projection: optimal for small streets 
    Long = ((p.getX())/(6371000*Math.cos(MG.getLati())))+MG.getLongi(); 
    Lat = (((p.getY())/6371000)+MG.getLati());
}

I also tryied to implement the Mercator projection from this link with very little to no success at all.

I am aware I'm not using total width and height from the Map on my formulas and this might be the error, but I don't know how to use it!

any help how to convert from (x,y) to (latitude, longitude)?

Thanks,


回答1:


You need to shift pixel coordinates by center position and also use map scale - longitude and latitude range (I assume that elongation Math.cos(MG.getLati()) coefficient is accounted in longitude scale)

Long = (p.getX() - MapWidth/2)*LongitudeRange/MapWidth  +MG.getLongi(); 
Lat = (p.getY() - MapHeight/2)*LatitudeRange/MapHeight + MG.getLati());


来源:https://stackoverflow.com/questions/60827507/convert-cartesian-x-y-to-coordinates-gps-latitude-longitude

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