C++ 如何将 Lat ,long 转换为 XY 坐标系(例如 UTM),然后将其映射到我的图像的像素空间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6172355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 19:37:45  来源:igfitidea点击:

how to Convert Lat ,long to an XY coordinate system (e.g. UTM) and then map this to pixel space of my Image

c++openstreetmapmercator

提问by Verve Innovation

I have a very small area map , which I downloaded from Openstreet map(PNG) and also its OSM(.osm) file which contains its Lat ,long.

我有一个非常小的区域地图,我从 Openstreet 地图(PNG)下载了它,还有它的 OSM(.osm)文件,其中包含它的经纬度。

Now I want to convert Lat ,long to an XY coordinate system (e.g. UTM) and then map this to pixel space of my Image which is of size (600 x 800 ). I know its a two way process ,like to know how to do this . Thank you

现在我想将 Lat ,long 转换为 XY 坐标系(例如 UTM),然后将其映射到我的 Image 大小(600 x 800)的像素空间。我知道它的双向过程,想知道如何做到这一点。谢谢

采纳答案by Brian Webster

GPS Coordinates to Pixels

GPS 坐标到像素

  • Assuming this map does not cross prime meridian
  • Assuming pixel 0,0 is upper left, and pixel 600,800 is lower right.
  • Assuming map is Northern Hemisphere Only (no part of map is southern hemisphere)

    1. Determine the left-most longitude in your 800x600 image (X)
    2. Determine the east-most longitude in your 800x600 image (Y)
    3. Determine Longitude-Diff (Z = Y - X)
    4. Determine north-most latitude in your 800x600 image (A)
    5. Determine south-most latitude in your 800x600 image (B)
    6. Determine Longitude-Diff (C = A - B)
  • 假设这张地图不跨越本初子午线
  • 假设像素 0,0 在左上角,像素 600,800 在右下角。
  • 假设地图仅是北半球(地图的任何部分都不是南半球)

    1. 确定 800x600 图像中最左侧的经度 (X)
    2. 确定 800x600 图像中的最东经度 (Y)
    3. 确定经度差 (Z = Y - X)
    4. 确定 800x600 图像中最北端的纬度 (A)
    5. 确定 800x600 图像中最南端的纬度 (B)
    6. 确定经度差 (C = A - B)

Given a Latitude and Longitude, to determine which pixel they clicked on:

给定纬度和经度,以确定他们点击了哪个像素:

  1. J = Input Longitude
  2. K = Input Latitude

  3. Calculate X-pixel

    XPixel = CInt(((Y - J) / CDbl(Z)) * 800)

  4. Calculate Y-pixel

    YPixel = CInt(((A - K) / CDbl(C)) * 600)

  1. J = 输入经度
  2. K = 输入纬度

  3. 计算 X 像素

    XPixel = CInt(((Y - J) / CDbl(Z)) * 800)

  4. 计算 Y 像素

    YPixel = CInt(((A - K) / CDbl(C)) * 600)

UTM

UTM

Here is a cartographic librarythat should help with GPS to UTM conversions

这是一个制图库,应该有助于 GPS 到 UTM 的转换