TransWikia.com

Get best fitting rectangle polygon in PostGIS

Geographic Information Systems Asked on August 23, 2021

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?

One Answer

Use ST_OrientedEnvelope

Returns a mimimum rotated rectangle enclosing a geometry.

select ST_OrientedEnvelope(geom)
from ok_ak_riks

enter image description here

Correct answer by BERA on August 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP