]> granicus.if.org Git - postgis/commitdiff
Add ST_OrientedEnvelope
authorDaniel Baston <dbaston@gmail.com>
Fri, 2 Feb 2018 17:10:07 +0000 (17:10 +0000)
committerDaniel Baston <dbaston@gmail.com>
Fri, 2 Feb 2018 17:10:07 +0000 (17:10 +0000)
Resolves #3176

git-svn-id: http://svn.osgeo.org/postgis/trunk@16368 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
doc/reference_processing.xml
postgis/lwgeom_geos.c
postgis/postgis.sql.in
regress/Makefile.in

diff --git a/NEWS b/NEWS
index 30cbacd51c6ca59f6b98e10113636630e4440d3d..cc526e4da2ad132152e40f8e2703046553fc7260 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ PostGIS 2.5.0
   - #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
index 57d6e296211d237ac5dfbb2687d349ba51cbda6e..834e954ea4034e08c7493789e105f2ba100406f2 100644 (file)
@@ -2170,6 +2170,57 @@ POLYGON((135.59714732062 115,134.384753327498 102.690357210921,130.79416296937 9
 
        </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>
index 3c74e3c61d71935a6ca39bf73796e0aea00ed16e..856bc3ab6a843d72c28f0b3b3d8f924bc9575966 100644 (file)
@@ -3627,3 +3627,46 @@ Datum ST_MinimumClearanceLine(PG_FUNCTION_ARGS)
 #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
+}
index 68ceec2fe33b6b92e7b6c010b6fd8b4b5890a1bf..1b8d2e20f7d2fa2776a6060637592e71d4d98a10 100644 (file)
@@ -3324,6 +3324,12 @@ CREATE OR REPLACE FUNCTION ST_MinimumBoundingCircle(inputgeom geometry, segs_per
     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
index cbee4e869b13b1382fa7c6cfdd79dcf13a071d98..516a7015c3a016f149ec241745e9f0e08e082f9d 100644 (file)
@@ -229,7 +229,8 @@ ifeq ($(shell expr $(POSTGIS_GEOS_VERSION) ">=" 36),1)
        # GEOS-3.6 adds:
        # ST_MinimumClearance
        TESTS += \
-               minimum_clearance
+               minimum_clearance \
+               oriented_envelope
 endif
 
 ifeq ($(HAVE_JSON),yes)