How to create a bounding box around a geom (POINT) and find all the intersecting geoms(POINTS) within that bounding box?
Bounding box is rectangular and therefore ST_DWithin gives wrong result by using a circle for making the selection. Your workflow could be:
- Define a point
- Buffer the point and create a circle
- Make minimum bounding box around the circle
- 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_Envelope( ST_Buffer( 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.