【问题标题】:get_bounds() returns [[None, None], [None, None]]get_bounds() 返回 [[None, None], [None, None]]
【发布时间】:2019-04-03 05:03:57
【问题描述】:

使用以下代码,我希望获得可见地图角的纬度/经度对:

import folium

testmap = folium.Map(location=[-23.52, 115.5]
                  , zoom_start=7
                  , prefer_canvas=True
                  )

testmap.get_bounds()

相反,我得到:

[[None, None], [None, None]]

我做错了什么?如果这有助于解决这个问题,我正在使用来自 master 分支的 Folium。

【问题讨论】:

    标签: python-3.x folium


    【解决方案1】:

    我也遇到了这个问题,我没有解决方案,但是我知道在查看 get_bounds() 函数的实现时会发生什么。

    def get_bounds(self):
        """Computes the bounds of the object and all it's children
        in the form [[lat_min, lon_min], [lat_max, lon_max]].
        """
        bounds = self._get_self_bounds()
    
        for child in self._children.values():
            child_bounds = child.get_bounds()
    
    def _get_self_bounds(self):
        """Computes the bounds of the object itself (not including it's children)
        in the form [[lat_min, lon_min], [lat_max, lon_max]]
        """
        return [[None, None], [None, None]]
    

    因此,首先计算地图本身的边界(返回 None 值),然后计算子节点的边界。由于在您的示例中没有子级,get_bounds() 函数返回 [[None, None], [None, None]]

    【讨论】:

      【解决方案2】:

      看看这是否对你有帮助:https://nbviewer.jupyter.org/gist/ocefpaf/815b267199a1c1d4ac43f37cf8b8d4a8

      这为您提供了如何正确使用 get_bounds 的示例

      【讨论】:

      • 谢谢。从笔记本中,我看到color_line.get_bounds 给出了color_line 的边界,但我不明白为什么m.get_bounds 也返回相同的边界。从 [docs] (python-visualization.github.io/folium/modules.html) 中,我希望 m.get_bounds 给出所显示地图的 4 个角的最小和最大纬度,这是我正在寻找的行为。
      猜你喜欢
      • 2018-01-04
      • 2018-11-29
      • 1970-01-01
      • 1970-01-01
      • 2022-11-21
      • 2020-11-19
      • 1970-01-01
      • 2013-08-14
      相关资源
      最近更新 更多