3

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?

4

Use ST_OrientedEnvelope

Returns a mimimum rotated rectangle enclosing a geometry.

select ST_OrientedEnvelope(geom)
from ok_ak_riks

enter image description here

3
  • Brilliant! Thank you very much @BERA – Shana Jul 19 '20 at 8:40
  • would you able to help in answering a similar question but in this case, the rectangle should be within the polygon gis.stackexchange.com/questions/368331/… – Shana Jul 21 '20 at 13:36
  • Thanks for checking @BERA. Really appreciate that. – Shana Jul 21 '20 at 14: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.