【发布时间】: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 包含哪些出租位置(无论它们包含在哪个多边形中)。
【问题讨论】: