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?

  • What version of PostGIS are you using?
    – Mapperz
    Commented May 14, 2013 at 16:02
  • My PostGIS is Version 2.0.1
    – bl8rchk
    Commented May 14, 2013 at 16:06
  • 2
    are both geom columns in the same SRID?
    – nickves
    Commented May 14, 2013 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
    Commented May 14, 2013 at 16:29
  • @bl8rchk what is the table geomTable and field mytable.geom? Commented Jan 9, 2017 at 19:43

1 Answer 1


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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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