ST_OrientedEnvelope returning parallelogram

Erik Wienhold ewie at ewie.name
Fri Mar 8 10:29:55 PST 2024


On 2024-03-07 07:05 +0100, Ricardo Mayerhofer wrote:
> I have a GIS application with multiple polygons where I'd like to get the
> rotated bounding box of the polygons. ST_OrientedEnvelope seems to be the
> right function, but in my case, is returning a parallelogram instead of a
> rectangle.
> 
> I've created a simple example where the original polygon is a rectangle
> just to demonstrate the issue:
> 
> CREATE TABLE geometries (
>   geometry geometry
> );
> INSERT INTO geometries(geometry)
> values(ST_GeomFromText('POLYGON((-71.25961696926942
> 42.470522973159675,-71.25978846747648
> 42.470624424600906,-71.25973918365264
> 42.47066975346566,-71.25956768540266
> 42.47056830210077,-71.25961696926942 42.470522973159675))'))
> SELECT ST_AsGeoJson(st_collect(ST_OrientedEnvelope(geometry),
> geometry)) FROM geometries
> 
> [image: Screenshot 2024-03-07 at 02.59.37.png]
> 
> Image link:
>  https://www.dropbox.com/scl/fi/xoi87e06mtfsnc1qzw3wu/oriented_2.png?rlkey=37ajuo6lwdnynk9gi8hpmoolq&dl=0
> <https://www.dropbox.com/scl/fi/xoi87e06mtfsnc1qzw3wu/oriented_2.png?rlkey=37ajuo6lwdnynk9gi8hpmoolq&dl=0>
> 
> Any help is appreciated, thanks!

What is your PostGIS and GEOS version?  Please provide the output of

	SELECT postgis_full_version();

I can confirm this bug on 3.4.1 with GEOS 3.12.0.  Could be a regression
in GEOS 3.12.0:

	"CAPI: GEOSMinimumRotatedRectangle now uses MinimumAreaRectangle (Paul Ramsey)" [1]

[1] https://github.com/libgeos/geos/blob/main/NEWS.md#changes-in-3120

-- 
Erik


More information about the postgis-users mailing list