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 have a minLat, minLong, maxLat and maxLong from a box drawn on a map. Right now, my query to get all the points in the box looks like this:

FROM geomTable
WHERE (longitude BETWEEN minLon AND maxLon)
AND (latitude BETWEEN minLat AND maxLat)

I want to use the geometry column instead of lat/long columns to get the results. I tried this query:

FROM mytable
WHERE mytable.geom && ST_MakeEnvelope(minLon, minLat, maxLon, maxLat, 4326);

from this post: Select bounding box using postgis but it is returning no results.

Does anyone have an example of how to select all the points within a box created by min and max lat/longs using geometry in postgis?

share|improve this question
What version of PostGIS are you using? – Mapperz May 14 '13 at 16:02
My PostGIS is Version 2.0.1 – bl8rchk May 14 '13 at 16:06
are both geom columns in the same SRID? – nickves May 14 '13 at 16:10
I think I might be way off with my approach...I only have one geom column. It's SRID is 2223 – bl8rchk May 14 '13 at 16:29
up vote 9 down vote accepted

Your data is not in lat/lon, so you need to push your box into the coordinate space of your data:

FROM mytable
  mytable.geom && 
  ST_Transform(ST_MakeEnvelope(minLon, minLat, maxLon, maxLat, 4326), 2223);
share|improve this answer
perfect! Thank you! – bl8rchk May 14 '13 at 16:41

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.