Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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:

SELECT *
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:

SELECT *
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
1  
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
add comment

1 Answer 1

up vote 6 down vote accepted

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

SELECT *
FROM mytable
WHERE 
  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
add comment

Your Answer

 
discard

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.