我有一个 MultiPolygon 字段,preferences.locations
,和一个 Point 字段,rental.location
。当查询以检查租赁位置是否包含在 preferences.locations
中时,只有当 rental.location
包含在 preferences.locations
的第一个多边形中时,查询才会成功。
例如,使用这些几何图形:
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
中(不管它们包含在哪个多边形中)。