I have the following model:
class Item(Model):
lat_lng = PointField(geography=True, null=True)
Item.objects.create(lat_lng=Point(-95.864468, 36.075450))
bbox1 = (-168.3984375, 25.16517336866393, -52.03125, 75.32002523220804)
bbox2 = (-145.1953125, 25.16517336866393, -52.03125, 63.07486569058663)
bbox1 contains bbox2, but Item.objects.filter(lat_lng__coveredby=Polygon.from_bbox(bbox1)) doesn't return the item, while Item.objects.filter(lat_lng__coveredby=Polygon.from_bbox(bbox2)) returns it.
Am I missing something?
UPDATE:
If I remove geographic=True, then everything works. What does this flag stands for?
When using geography, great circle arcs are used instead of straight lines. This remains true for the lines connecting the bounding box corners.
The premise that box1 contains box2 is false. They may intersect, but one is not wholly contained in the other.
Box1 is wider than box 2, so its southern boundary, represented as a great circle arc, will go norther than box 2 boundary, and therefore the point is located south of box 1 but within box 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With