将X Y坐标转换为Lat Long Equirectangular投影C ++

时间:2015-01-30 14:55:08

标签: c++ google-maps latitude-longitude

大家都在使用地球的Equirectangular Projection创建一个新程序。用户可以将地图放大和缩小等常规内容。

我试图找出如何将我的X(21600像素)转换为y(10800像素)到纬度和经度的方法。

我一直在阅读将其转换为Lat Long的一些方法,而我的大脑刚刚融化,我的数学技能仍然很好,仍在学习什么不是。

如果您需要更多信息,我可以提供指向我的GitHub存储库的链接,以便立即查看所有代码。

使其工作的一段代码将是王牌,但学习经验可以解释它是如何工作的,转换是什么,以及什么不是。

非常感谢;

2 个答案:

答案 0 :(得分:1)

因为它的 Equirectangular Projection 你的(x, y)坐标直接映射到经度和纬度。您需要做的就是缩放它们,例如:

longitude = x * longitude_per_pixel;
latitude  = y * latitude_per_pixel;

答案 1 :(得分:0)

修正了现在非常简单的公式来计算X Y坐标到Lat Long

“使用QT编码器进行编码”

我使用了QGraphicsView小部件,然后在其中放置了一个场景,其中的图像是我的世界。

然后使用这样做来创建X和Y的确切值

//make this in your initalizer
//this gets the exact value of the scene you are using
double map_height{0}
double map_width{0}
map_height = ui->m_graphicsview->scene()->height();
map_width = ui->m_graphicsview->scene()->width();

then create a mouse_event -  and set the mouse_move
set 2 varibles like this
double x = mouse_event->pos(); //This isnt exact but you get the idea
double y = moue_event->pos();

then using these two varibles call up a function

double getLat(double x)
{
   double lon =(x * 360) /(m_map_width)-180;
   return lon;
}
double getLon(double y)
{
double lat = (y * 180) / (m_map_height)-90;
return lat;
}

非常简单,如果您想查看我的GitHub回购,请给我留言