There is a polygon and i want to get the best fitting rectangle.

POLYGON((530298.250279478 162222.258455872,530298.231436834 162222.252144356,530291.717023011 162220.760892999,530291.4 162222.2,530307.3 162226.15,530307.78 162226.28,530310.87 162227.09,530311.081382153 162226.14214151,530298.915241086 162222.434365185,530298.586991142 162222.368630039,530298.26998128 162222.261048055,530298.250279478 162222.258455872))

I tried using ST_SetSRID(ST_Extent(geom),27700) but it would give the following as shown in the image

enter image description here

But i am looking for something as below;

enter image description here

What is the best way to do this?

1 Answer 1


Use ST_OrientedEnvelope

Returns a mimimum rotated rectangle enclosing a geometry.

select ST_OrientedEnvelope(geom)
from ok_ak_riks

enter image description here


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.