【问题标题】:Calculate (x,y) from (Lat,Lon) in a cropped equirectangular projection在裁剪的 equirectangular 投影中从 (Lat,Lon) 计算 (x,y)
【发布时间】:2015-09-25 07:38:07
【问题描述】:

我在 equirectangular 投影中有一个地图。我知道 (lat,lon) 在左上角和右下角的位置。现在我知道我可以像这样计算 (x,y):

x = ((lon + 180) * (map_width  / 360))
y = (((lat * -1) + 90) * (map_height  / 180))

但是,这似乎会产生错误的坐标。我的猜测是我必须考虑我的图像的左上角和右下角(纬度,经度)。

所以我尝试了这种方式(left、top、right、bottom_lon 代表我的图像边界):

x = ((lon + left_lon) * (map_width  / (right_lon - left_lon)))
y = (((lat * -1) + top_lat) * (map_height  / (top_lat - bottom_lat)))

但我仍然没有得到正确的结果。我做错了什么?

【问题讨论】:

    标签: gis latitude-longitude projection


    【解决方案1】:

    用这两个 Python 函数回答我自己的问题:

    def lon2x(lon, w):
        return int(img_w * ((lon - start_lon) / (end_lon - start_lon)))
    
    def lat2y(lat, h):
        return int(img_h * ((lat - start_lat) / (end_lat - start_lat)))
    

    【讨论】:

      【解决方案2】:

      在接受的答案中,忘记了从高度减去。所以,一定是这样的:

      def lon2x(lon, w):
          return int(img_w * ((lon - start_lon) / (end_lon - start_lon)))
      
      def lat2y(lat, h):
          return int(img_h) - int(img_h * ((lat - start_lat) / (end_lat - start_lat)))
      

      编辑:它们是近似正确的结果,但对于非常准确的结果,您应该使用 投影方法 用于创建地图的任何方法(如墨卡托或 Equirectangular)。

      【讨论】:

        猜你喜欢
        • 2020-10-02
        • 2017-07-03
        • 2019-01-07
        • 2018-12-10
        • 2011-03-31
        • 1970-01-01
        • 1970-01-01
        • 2022-12-14
        • 1970-01-01
        相关资源
        最近更新 更多