Get min/max POINTs from a POLYGON object

877 views Asked by At

I have a table with a geom column containing polygons. e.g.:

POLYGON((-104.98075 25.83706,-84.659531 25.83706,-84.659531 49.38449,-104.98075 49.38449,-104.98075 25.83706)),4326

How can I extract the minimum and maximum latitude and longitude values from that object, as floats? The idea would be to create minLat, maxLat, etc., columns in the DB to make searching a bit quicker.

1

There are 1 answers

1
JoeGalind On

I resolved it by using ST_Envelope(poly)

select ST_Envelope(poly) from table WHERE id=1;

This returns a polygon with the corners of the contained polygon.

POLYGON((
-90.79440777754286 14.37717780192112,
-90.78941725049431 14.37717780192112,
-90.78941725049431 14.3808399138696,
-90.79440777754286 14.3808399138696,
-90.79440777754286 14.37717780192112))