How to create a bounding box around a geom (POINT) and find all the intersecting geoms(POINTS) within that bounding box?

  • Is this your homework? – user30184 Aug 31 '15 at 11:24
  • Welcome to gis.stackexchange! Please edit the title of your question to include enough information for future visitors to be able to find this thread when looking for the same problem. – underdark Aug 31 '15 at 21:29

Bounding box is rectangular and therefore ST_DWithin gives wrong result by using a circle for making the selection. Your workflow could be:

  1. Define a point
  2. Buffer the point and create a circle
  3. Make minimum bounding box around the circle
  4. Use this newly build box for selecting the features

Thus, if we forget the trouble with geometric coordinates, the SQL query would be like:

SELECT * from your_table AS a
where ST_Intersects(a.geom,
ST_GeomFromText('POINT (-108 43)',4326),10)));

The buffer of 10 degrees with EPSG:4326 may not make sense but the SQL per se gives an answer to your question as you put it. If your data and the Envelope that you build are in some projected SRS like some UTM zone the result should be fine.

SELECT pt.id
FROM points_table pt
WHERE ST_DWithin(ST_GeomFromText('POINT 0 0', 3857), pt.geom, 500);

This might be one way to solve your problem.

  • Thanks Michal, this is what I wanted, but facing some problem , though I am altering the distance parameter, still I am getting the same result, any solution ? – user1544198 Aug 31 '15 at 12:13
  • 1
    What CRS do you use? – Michal Zimmermann Aug 31 '15 at 15:11
  • try geography if you are using 4326 – Ian Turton Aug 31 '15 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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