【问题标题】:Get all lat/lon points inside a bounding box area获取边界框区域内的所有纬度/经度点
【发布时间】:2022-08-21 04:27:26
【问题描述】:

我能够从纬度、经度和半径生成一个西南-东北边界框。 我怎么可能得到那个边界框区域内的所有点?

我尝试创建一个shapely.geometry.polygon.Polygon 对象,认为我可以使用polygon.coordspolygon.interiors 提取点。我生成了这样的多边形:

import shapely.geometry as sg

bbox = (55.74341900255196, 37.5950436686672, 55.79737829890708, 37.69096949784429)
polygon = sg.box(*bbox, ccw=True)

但是没有什么可以给出盒子内的所有分数。

  • 该区域的所有点是什么意思?多边形内有无数个点。

标签: python python-3.x latitude-longitude bounding-box shapely


【解决方案1】:

有几个选项:

天真的解决方案- 将你的 bbox 传递给一个函数,如果一个点的 lat、lng 值在 bbox 值之间,则该函数返回 True

- 计算便宜

骗局- 不准确(不考虑地球的曲线)

def isin_box(lat, lng, bbox):

    x1, x2, x3, x4 = bbox

    within = False

    if x2 < lat < x4:
        if x1 < lng < x3:
            within = True

    return within

准确的解决方案- 在操作中使用 shapely 来检查点对象是否位于 bbox 多边形中:

bbox = (55.74341900255196, 37.5950436686672, 55.79737829890708, 37.69096949784429)
polygon = sg.box(*bbox, ccw=True)
Point(55.77037811279297,37.64223791838213).within(polygon)
True

- 准确的

骗局- 计算成本高

【讨论】:

    猜你喜欢
    • 2013-01-16
    • 2021-04-16
    • 2016-11-21
    • 2011-07-29
    • 2020-02-19
    • 2014-08-29
    • 1970-01-01
    • 2011-03-17
    • 2012-11-17
    相关资源
    最近更新 更多