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,

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?

  • 2
    Not exactly sure what your goal is, but would densifying the bounding box, then reprojecting help? See gis.stackexchange.com/a/392248/88814
    – Babel
    Dec 12, 2023 at 16:00
  • @Babel I think so, yes. So, I think you're proposing a process that would be to ST_MakeEnvelope in 3857, then ST_Segmentize the result to an appropriate density, then ST_Transform that to 4326, then ST_Extent the result. I will try to put this workflow together and get back to this thread.
    – Him
    Dec 12, 2023 at 16:07
  • 1
    ST_Segmentize doesn'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, 2023 at 16:40
  • 2
    If the object is a geometry (which a polygon in 3847 is) then ST_Segmentize adds vertices along the straight-line segments, as required.
    – dr_jts
    Dec 12, 2023 at 18:41
  • 1
    @dr_jts ah, I see that you're correct. I was incorrectly assuming that 4326 segmentations and boxes would be along great circles, because 4326 is a "3D projection". Apparently this isn't the case, and the 3857 bbox and the 4326 bbox are identical in postGIS.
    – Him
    Dec 12, 2023 at 18:57


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.