Just some context first, I have a postgres database with PostGIS extension, running under a GeoDjango wrapper. I have a weird bug that hopefully someone can shed some light on.

I'm running a query like this

geom = Polygon.from_bbox(bbox)
query = Venue.objects.filter(location__within=geom)

This works fine for most cases and is doing exactly what I want, except for in one specific situation where I get a result that looks like this

example of query bug

(for reference, the bbox param above is always defined by the SW and NE corners of the map which in this case are



I've been trying to narrow down the problem, and I'm starting to think it might be something to do with crossing from negative to positive longitude, but I'm not sure. Or maybe it is something to do with indexing on the database level?

Here is the SQL that is generated:

SELECT * FROM "web_venue" WHERE ST_Within("web_venue"."location", ST_GeomFromEWKB('\001\003\000\000 \346\020\000\000\001\000\000\000\005\000\000\000(\366\304G\026|I@\000(\\\317C\266\362\277(\366\304G\026|I@\000@\341z\036\272\305\277y\006C\216\230\021J@\000@\341z\036\272\305\277y\006C\216\230\021J@\000(\\\317C\266\362\277(\366\304G\026|I@\000(\\\317C\266\362\277'::bytea)) LIMIT 50

(I took out all the explicit select statements and just put '*' for brevity.)

closed as off-topic by PolyGeo Aug 14 '16 at 10:47

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Is there a limit on the query? You might only be seeing the first 100 results? – Ian Turton Jun 27 '15 at 18:55
  • Yes there is a limit on the query, set to 50 at the moment. But in all other queries, the results come back as a scattering of points, spread roughly evenly inside the bbox, not all in a line like this. – Peter Matev Jun 27 '15 at 19:11
  • You are probably near a split in the index. – Ian Turton Jun 27 '15 at 19:25
  • There is a way to get Geodjango to print out the actual raw query it is running, but I forget what this is. This might be useful? – John Powell Jun 28 '15 at 7:08
  • Edited the original post with the SQL output. – Peter Matev Jun 28 '15 at 9:24