【问题标题】:Latitude and Longitude to X and Y in pythonpython中X和Y的纬度和经度
【发布时间】:2018-04-17 21:45:06
【问题描述】:

我使用的是来自 Google 地图的图片,大小约为 200x200 英尺(房屋大小及其财产)。我的目标是有一个输入坐标(例如[37.211817,-86.682670]),可以使用我自己的数学在我拍摄的谷歌地图图片上放置一个标记。我看过并尝试了很多方法。我只是想取一个纬度/经度,然后按比例将它放在一个 X 和 Y 大的正方形中。

【问题讨论】:

  • 我不确定我是否理解这个问题。谷歌(和网络地图)将地球分割成瓷砖。 X、Y 取决于缩放级别。顺便说一句,这不是关于编程,而是关于公式:您可以在姊妹网站上获得更多帮助:gis.stackexchange.com。那里回答了类似的问题。检查前。 maptiler.org/google-maps-coordinates-tile-bounds-projection

标签: python gps coordinates transform


【解决方案1】:

好的,我找到了答案,我将分享它,因为它似乎比我预期的要复杂。解决方案是将 GPS 坐标顺时针旋转 90°,然后在 Y 轴上进行反射。 -> (y, -x) +> (x, -y)。

编辑

所以是的,所要做的就是翻转 x 和 y。是经纬度,不是经度纬度。

然后,这是一个适合您屏幕的简单缩放公式。代码如下:

top_left_raw = GPS_COORD
bottom_right_raw = GPS_COORD
maprect = [0,0,400,500] # Picture of map's width and height

def translate(pos):
    #rot = (pos[1], pos[0]*-1)
    #reflect = (rot[0], rot[1]*-1)
    #return reflect
    return (pos[1], pos[0])

def gps_to_coord(pos):
    pos1 = translate((pos[0]-top_left_raw[0], pos[1]-top_left_raw[1]))
    pos2 = translate((bottom_right_raw[0] - top_left_raw[0], bottom_right_raw[1] - top_left_raw[1]))
    x = (maprect[2]*pos1[0]) / pos2[0]
    y = (maprect[3]*pos1[1]) / pos2[1]
    return (x,y)

gps_to_coord(GPS_COORD)

【讨论】:

    【解决方案2】:

    为了简单起见,我们假设 GPS 坐标可以线性缩放到另一个坐标系。您需要图像左上角和右下角的 GPS 坐标:

    伪代码:

    input: gps_marker
    
    let gps1 = lat/lon of location corresponding to top left of image.
    let gps2 = lat/lon of location corresponding to bottom right of image.
    
    let x_offset = (gps_marker.lon - gps1.lon)/(gps2.lon - gps1.lon) * image.width
    let y_offset = (gps_marker.lat - gps1.lat)/(gps2.lat - gps1.lat) * image.height
    
    // x_offset and y_offset are the x,y for your marker within the image.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-02
      • 1970-01-01
      • 1970-01-01
      • 2011-12-05
      • 1970-01-01
      • 2011-10-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多