1

I have a query where I use select ST_Extent(geometries) which returns a box2d object. I would like to cast it back to a geometry object since that is what I need but I was unable to do so with select ST_Extent(geometries)::geometry which returned only a set of numbers. I was also unable to find any alternatives. Also using another ST function would work for me but I was unable to find something suiting

1
  • That set of numbers is the bytea resentation of a GEOMETRY type. Geometries are byte encoded types by design, and all ST functionality is built on top of them - so for all intent and purpose, those numbers are correct. There are functions to deserialize the byte encoding into human readable format, primarily ST_AsText/ST_AsEWKT.
    – geozelot
    Jul 9 at 10:11

1 Answer 1

2

Running this query:

select st_extent(geom) as box,
  st_extent(geom)::geometry as g1,  
  st_asewkt(st_extent(geom)::geometry) as geom 
from osopen_zoomstack.boundaries

gives me the expected results.

"BOX(315261.25 185879.45,398017.01 657601.49)"  
"0103000000010000000500000000000000F53D13419A999999BBB0064100000000F53D1341AE47E1FA82112441A4703D0A044B1841AE47E1FA82112441A4703D0A044B18419A999999BBB0064100000000F53D13419A999999BBB00641"
"POLYGON((315261.25 185879.45,315261.25 657601.49,398017.01 657601.49,398017.01 185879.45,315261.25 185879.45))"
1
  • Thanks a lot :D exactly what I was looking for but wasn't able to find nowhere :)
    – Tenebris
    Jul 9 at 10:05

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.