1

I have zoom level 4 polygons of the world (in EPSG 3857) and I am trying to get the bounding box of each tiles. enter image description here

this is the query that I used but this is not working. select title, id, st_extent(geom) from world_tile4; enter image description here

ST_Extent brings me the entire table (feature) and this is not what I wanted to have enter image description here

I am assuming that I might have to use for loop to get this?

  • What you want is ST_Envelope or box2D - not ST_Extent. – Ralph Tee Dec 4 '18 at 7:01
  • @RalphTee Oh.. my mistake. Thank you so much for your tip. – Pil Kwon Dec 4 '18 at 7:08
2

select *, st_asText(ST_Envelope(wkb_geometry)) as bound from world_tile4;

ST_Extent -> St_Envelope this was the key.

enter image description here

  • 1
    This should work as well select *, ST_AsText(ST_SetSRID(ST_Extent(wkb_geometry),3857)) as bound from world_tile4 group by ogc_fid; – user30184 Dec 4 '18 at 7:25
  • @user30184 why do you have to group by the feature id? – Pil Kwon Dec 4 '18 at 7:26
  • 1
    Because as you saw in the initial error message, ST_Extent is an aggregate function. Using "group by" with any unique field makes each row to be an own aggregate. – user30184 Dec 4 '18 at 7:39

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.