I have a bounding box in SRID 3857, web mercator, gotten from a UI where a user is panning and zooming. I need to query points in postGIS within this box. However, my points are all stored in SRID 4326. It is fine if I get some quantity of points that are outside of the view area, but I need to get at least everything in the view area. So, what I would like to do, is to find the SRID 4326 bounding box that bounds my SRID 3857 bounding box.
Viz. my 3857 bounding box is given by:
ST_MakeEnvelope (
xmin, ymin,
xmax, ymax,
3857)
I would like to get a 4326 bounding box of that box so that every point on the surface of the Earth that is within the 3857 bounding box is within my 4326 bounding box. Note that I can't just transform the corner coordinates: In the Northern Hemisphere, the resulting box in 4326 would include the northern boundary of the 3857 box, and exactly coincide with the eastern and western boundaries, but would "cut off" a curved-looking chunk of the 3857 box.
How do I get a bounding box in one SRID of a bounding box in another SRID?
ST_MakeEnvelopein 3857, thenST_Segmentizethe result to an appropriate density, thenST_Transformthat to 4326, thenST_Extentthe result. I will try to put this workflow together and get back to this thread. – Him Dec 12 '23 at 16:07ST_Segmentizedoesn't actually work here, because it densifies the box along a great circle arc, and not in the original projection. So, when I densify my 3857 bbox, the polygon is no longer a "box" in 3857.... From the docs: "Added vertices are created along the spherical great-circle arcs defined by segment endpoints." – Him Dec 12 '23 at 16:40ST_Segmentizeadds vertices along the straight-line segments, as required. – dr_jts Dec 12 '23 at 18:41