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

Converting X Y coords to Lat Long Equirectangular projecton C++

大家好,我正在创建一个新程序,我正在使用地球的等距柱状投影。用户可以围绕放大和缩小地图等正常操作移动地图。

我在尝试找出如何将我的 X(21600 像素)乘以 y(10800 像素)转换为纬度和经度时遇到了一些困难。

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

如果您需要更多信息,我可以向我的 GitHub 存储库提供 link,以便一次查看所有代码。

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

非常感谢大家;

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

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

现在修正了一个非常简单的公式来计算经纬度的 X Y 坐标

"Coded using the QT complier"

我使用了 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 回购协议,请给我发消息