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.

The table that i want to perform this query has 3 columns: id, the_geom and seen_count.

The query i've been using to get points inside a bounding box is as follows:

SELECT id, ST_AsGeoJSON(the_geom) FROM table WHERE ST_Contains(ST_MakeEnvelope({0}, {1}, {2}, {3}, 4326), table.the_geom)

What i want to do is: selecting points, which are transformed to circles using their seen_count as radius, intersect with bounding box. Is it possible? If so, would it be an expensive query? Thanks in advance.

share|improve this question
1  
Wrap the table.geom in ST_Buffer() using the seen_count column as buffer distance, like so: SELECT id, ST_AsGeoJSON(the_geom) FROM table WHERE ST_Contains(ST_MakeEnvelope({0}, {1}, {2}, {3}, 4326), ST_Buffer(table.the_geom, table.seen_count)). I guess you realize that ST_Contains will return the ids only of points where the buffered circle it totally within the bounding box. –  Micha Jun 23 '13 at 11:41
    
Thank you for showing me a starting point. I found the answer! –  onatm Jun 23 '13 at 19:48

1 Answer 1

up vote 0 down vote accepted

Thanks to Micha, i found the answer:

SELECT id, ST_AsGeoJSON(the_geom) FROM table WHERE ST_INTERSECTS(ST_MakeEnvelope({0}, {1}, {3}, {4}, 4326), 
ST_Buffer(the_geom::geography, 1000*(seen_count+1))::geometry);
share|improve this answer

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.