【问题标题】:Check if multipolygon contains point in GeoDjango检查多边形是否包含 GeoDjango 中的点
【发布时间】:2015-03-07 03:19:17
【问题描述】:

我有一个 MultiPolygon 字段 preferences.locations 和一个 Point 字段 rental.location。在查询preferences.locations 是否包含租赁的位置时,仅当rental.location 包含在preferences.locations MultiPolygon 中的第一个多边形中时,查询才会成功。

例如,对于这些几何图形:

point1 = (81.20141954209073, -129.891357421875)
point2 = (40.70875101828792, -73.93179774284363)

preferences.locations = MultiPolygon(
    Polygon(((81.14748070499664, -163.289794921875),

              point1, # contains the first point

              (81.14748070499664, -163.289794921875),
              (81.14748070499664, -163.289794921875),)),

    Polygon(((40.70718949655447, -73.98123621940613),

              point2, # contains the second point

              (40.683762276904055, -73.99702906608582),
              (40.70718949655447, -73.98123621940613),)),
)

rental1.location = Point(*point1)

rental2.location = Point(*point2)

在查询preferences.locations 包含哪些出租的位置时,虽然应该返回两个出租,但只返回第一个出租。

>>> Rental.objects.filter(location__contained=preferences.locations)
[<Rental: Rental object>] # rental1

我如何才能成功检查 preferences.locations 包含哪些出租位置(无论它们包含在哪个多边形中)。

【问题讨论】:

    标签: gis postgis geodjango


    【解决方案1】:

    检查点是否包含在 MultiPolygon 中的正确方法是使用point.intersects(multipolygon)

    >>> Rental.objects.filter(location__intersects=preferences.locations)
    [<Rental: Rental object>, <Rental: Rental object>]
    

    【讨论】:

    • 谢谢!我对这种区别感到困惑,但是:为什么积分不是contained 而是intersecting?
    • 查看这个答案以获得详细解释:gis.stackexchange.com/a/108536
    猜你喜欢
    • 2016-09-07
    • 1970-01-01
    • 1970-01-01
    • 2016-12-06
    • 2019-12-26
    • 1970-01-01
    • 2014-08-26
    • 2014-04-26
    相关资源
    最近更新 更多