[postgis-tickets] r16368 - Add ST_OrientedEnvelope

Daniel Baston dbaston at gmail.com
Fri Feb 2 09:10:07 PST 2018


Author: dbaston
Date: 2018-02-02 09:10:07 -0800 (Fri, 02 Feb 2018)
New Revision: 16368

Modified:
   trunk/NEWS
   trunk/doc/reference_processing.xml
   trunk/postgis/lwgeom_geos.c
   trunk/postgis/postgis.sql.in
   trunk/regress/Makefile.in
Log:
Add ST_OrientedEnvelope

Resolves #3176



Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2018-02-01 02:32:33 UTC (rev 16367)
+++ trunk/NEWS	2018-02-02 17:10:07 UTC (rev 16368)
@@ -7,6 +7,7 @@
   - #3896, PostGIS_Extensions_Upgrade()
   - #3913, Upgrade when creating extension from unpackaged (Sandro Santilli)
   - #2256, _postgis_index_extent() for extent from index (Paul Ramsey)
+  - #3176, Add ST_OrientedEnvelope (Dan Baston)
 
 * Breaking Changes *
   - #3885, version number removed from address_standardize lib file

Modified: trunk/doc/reference_processing.xml
===================================================================
--- trunk/doc/reference_processing.xml	2018-02-01 02:32:33 UTC (rev 16367)
+++ trunk/doc/reference_processing.xml	2018-02-02 17:10:07 UTC (rev 16368)
@@ -2170,6 +2170,57 @@
 
 	</refentry>
 
+	<refentry id="ST_OrientedEnvelope">
+		<refnamediv>
+			<refname>ST_OrientedEnvelope</refname>
+			<refpurpose>Returns a minimum rotated rectangle enclosing a geometry.</refpurpose>
+		</refnamediv>
+
+		<refsynopsisdiv>
+			<funcsynopsis>
+				<funcprototype>
+					<funcdef>geometry<function>ST_OrientedEnvelope</function></funcdef>
+					<paramdef>
+						<type>geometry</type>
+						<parameter>geom</parameter>
+					</paramdef>
+				</funcprototype>
+			</funcsynopsis>
+		</refsynopsisdiv>
+
+		<refsection>
+			<title>Description</title>
+			<para>
+				Returns a mimimum rotated rectangle enclosing a geometry.
+				Note that more than one minimum rotated rectangle may exist.
+				May return a Point or LineString in the case of degenerate inputs.	
+			</para>
+			<para>
+				Availability - 2.5.0
+			</para>
+		</refsection>
+
+		<refsection>
+			<title>See Also</title>
+			<para>
+				<xref linkend="ST_Envelope" />
+				<xref linkend="ST_MinimumBoundingCircle" />
+			</para>
+		</refsection>
+
+		<refsection>
+			<title>Examples</title>
+			<programlisting>
+				SELECT ST_AsText(ST_OrientedEnvelope('MULTIPOINT ((0 0), (-1 -1), (3 2))'));
+
+				st_astext                    
+				------------------------------------------------
+				POLYGON((3 2,2.88 2.16,-1.12 -0.84,-1 -1,3 2))
+			</programlisting>
+
+		</refsection>
+	</refentry>
+
 	<refentry id="ST_Polygonize">
 		<refnamediv>
 			<refname>ST_Polygonize</refname>

Modified: trunk/postgis/lwgeom_geos.c
===================================================================
--- trunk/postgis/lwgeom_geos.c	2018-02-01 02:32:33 UTC (rev 16367)
+++ trunk/postgis/lwgeom_geos.c	2018-02-02 17:10:07 UTC (rev 16368)
@@ -3627,3 +3627,46 @@
 #endif
 }
 
+/******************************************
+ *
+ * ST_OrientedEnvelope
+ *
+ ******************************************/
+Datum ST_OrientedEnvelope(PG_FUNCTION_ARGS);
+PG_FUNCTION_INFO_V1(ST_OrientedEnvelope);
+Datum ST_OrientedEnvelope(PG_FUNCTION_ARGS)
+{
+#if POSTGIS_GEOS_VERSION < 36
+	lwpgerror("The GEOS version this PostGIS binary "
+			"was compiled against (%d) doesn't support "
+			"'ST_OrientedEnvelope' function (3.6.0+ required)",
+			POSTGIS_GEOS_VERSION);
+	PG_RETURN_NULL();
+#else
+	GSERIALIZED* input;
+	GSERIALIZED* result;
+	GEOSGeometry* input_geos;
+	GEOSGeometry* result_geos;
+	int srid;
+
+	initGEOS(lwpgnotice, lwgeom_geos_error);
+
+	input = PG_GETARG_GSERIALIZED_P(0);
+	srid = gserialized_get_srid(input);
+	input_geos = POSTGIS2GEOS(input);
+	if (!input_geos)
+		HANDLE_GEOS_ERROR("Geometry could not be converted to GEOS");
+
+	result_geos = GEOSMinimumRotatedRectangle(input_geos);
+	GEOSGeom_destroy(input_geos);
+	if (!result_geos)
+		HANDLE_GEOS_ERROR("Error computing oriented envelope");
+
+	GEOSSetSRID(result_geos, srid);
+	result = GEOS2POSTGIS(result_geos, LW_FALSE);
+	GEOSGeom_destroy(result_geos);
+
+	PG_FREE_IF_COPY(input, 0);
+	PG_RETURN_POINTER(result);
+#endif
+}

Modified: trunk/postgis/postgis.sql.in
===================================================================
--- trunk/postgis/postgis.sql.in	2018-02-01 02:32:33 UTC (rev 16367)
+++ trunk/postgis/postgis.sql.in	2018-02-02 17:10:07 UTC (rev 16368)
@@ -3324,6 +3324,12 @@
     AS 'MODULE_PATHNAME', 'ST_MinimumBoundingCircle'
     LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL;
 
+-- Availability: 2.5.0
+CREATE OR REPLACE FUNCTION ST_OrientedEnvelope(geometry)
+    RETURNS geometry
+    AS 'MODULE_PATHNAME', 'ST_OrientedEnvelope'
+    LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL;
+
 -- Availability: 2.0.0 - requires GEOS-3.2 or higher
 CREATE OR REPLACE FUNCTION ST_OffsetCurve(line geometry, distance float8, params text DEFAULT '')
        RETURNS geometry

Modified: trunk/regress/Makefile.in
===================================================================
--- trunk/regress/Makefile.in	2018-02-01 02:32:33 UTC (rev 16367)
+++ trunk/regress/Makefile.in	2018-02-02 17:10:07 UTC (rev 16368)
@@ -229,7 +229,8 @@
 	# GEOS-3.6 adds:
 	# ST_MinimumClearance
 	TESTS += \
-		minimum_clearance
+		minimum_clearance \
+		oriented_envelope
 endif
 
 ifeq ($(HAVE_JSON),yes)



More information about the postgis-tickets mailing list