Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using the following query in my db:

SELECT bg_id, ST_AsGeoJSON(the_geom)
WHERE bg.the_geom && ST_MakeEnvelope(xxx, xxx, xxx, xxx);

It seems to execute alright but when I draw out the geos on my map (I'm using Leaflet for this) it includes a bunch of geos that are not within the bounds I provided.

For a little more detail as to what exactly I'm trying to accomplish... I have a map on a webpage. As the user navigates throughout the map the bounds of the map are sent back to the db and then the db should send back geos for only what is within the current view. This seems to only be working if the map is zoomed in very close. If I zoom out at all it begins to include lots of geos that I am not looking for. I would only like to include geos that are ENTIRELY within the view.


share|improve this question
up vote 2 down vote accepted

The && operator has a specific meaning, and the meaning is this: the bounding box of the left argument and the bounding box of the right argument overlap.

If you only want geometries that are fully contained in the envelope, use a function with that meaning, like ST_Contains:

SELECT bg_id, ST_AsGeoJSON(the_geom)
WHERE ST_Contains(ST_MakeEnvelope(xxx, xxx, xxx, xxx), bg.the_geom);
share|improve this answer
Thank you. This fixed it. I read about the && operator in another question and misunderstood how it worked. – Nick McD. May 1 '13 at 20:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.