]> granicus.if.org Git - postgis/commitdiff
#3424, ST_MinimumClearance
authorDaniel Baston <dbaston@gmail.com>
Mon, 25 Apr 2016 21:02:23 +0000 (21:02 +0000)
committerDaniel Baston <dbaston@gmail.com>
Mon, 25 Apr 2016 21:02:23 +0000 (21:02 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@14856 b70326c6-7e19-0410-871a-916f4a2858ee

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

diff --git a/NEWS b/NEWS
index 016785e0b7f5fb4391b63b92f6bbddf24a89ddf2..bf8c34375eb90291208725935687ef0ab0a6f081 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,7 @@ PostGIS 2.3.0
   - #3339 ST_GeneratePoints (Paul Ramsey)
   - #3362 ST_ClusterDBSCAN (Dan Baston) 
   - #3364 ST_GeometricMedian (Dan Baston)
+  - #3424 ST_MinimumClearance (Dan Baston)
   - #3428 ST_Points (Dan Baston)
   - #3465 ST_ClusterKMeans (Paul Ramsey)
   - #3469 ST_MakeLine with MULTIPOINTs (Paul Norman)
index 35194c0c8c3c8048e38d4491149642a300fcc507..829ee79b69dec7ab6980f851ca98dd9fb6319465 100644 (file)
@@ -264,6 +264,7 @@ Hunter Systems Group,
 Lidwala Consulting Engineers,
 LisaSoft,
 Logical Tracking &amp; Tracing International AG,
+Maponics,
 Michigan Tech Research Institute,
 Natural Resources Canada,
 Norwegian Forest and Landscape Institute,
index b817a5dd06ad495cbcde098610cad972f1983a68..cfd2e29003adb39ab3ec130c3628616af813a089 100644 (file)
@@ -2361,6 +2361,133 @@ FROM (SELECT
          </refsection>
        </refentry>
 
+       <refentry id="ST_MinimumClearance">
+               <refnamediv>
+                       <refname>ST_MinimumClearance</refname>
+                       <refpurpose>Returns the minimum clearance of a geometry, a measure a geometry's robustness.</refpurpose>
+               </refnamediv>
+
+               <refsynopsisdiv>
+                       <funcsynopsis>
+                               <funcprototype>
+                                       <funcdef>float <function>ST_MinimumClearance</function></funcdef>
+                                       <paramdef><type>geometry </type><parameter>g</parameter></paramdef>
+                               </funcprototype>
+                       </funcsynopsis>
+               </refsynopsisdiv>
+
+         <refsection>
+               <title>Description</title>
+
+               <para>
+                       It is not uncommon to have a geometry that, while meeting the criteria for validity according to ST_IsValid (polygons)
+                       or ST_IsSimple (lines), would become invalid if one of the vertices moved by a slight distance, as can happen during 
+                       conversion to text-based formats (such as WKT, KML, GML GeoJSON), or binary formats that do not use double-precision 
+                       floating point coordinates (MapInfo TAB).
+               </para>
+
+               <para>
+                       A geometry's "minimum clearance" is the smallest distance by which a vertex of the geometry could be moved to produce
+                       an invalid geometry.  It can be thought of as a quantitative measure of a geometry's robustness, where increasing values
+                       of minimum clearance indicate increasing robustness.
+               </para>
+
+               <para>
+                       If a geometry has a minimum clearance of <varname>e</varname>, it can be said that:
+                       <itemizedlist>
+                               <listitem>
+                                       <para>
+                                               No two distinct vertices in the geometry are separated by less than <varname>e</varname>.
+                                       </para>
+                               </listitem>
+                               <listitem>
+                                       <para>
+                                               No vertex is closer than <varname>e</varname> to a line segement of which it is not an endpoint.
+                                       </para>
+                               </listitem>
+                       </itemizedlist>
+               </para>
+
+               <para>
+                       If no minimum clearance exists for a geometry (for example, a single point, or a multipoint whose points are identical), then
+                       ST_MinimumClearance will return Infinity.
+               </para>
+
+               <para>Availability: 2.3.0 - requires GEOS &gt;= 3.6.0</para>
+
+         </refsection>
+
+         <refsection>
+               <title>Examples</title>
+               <programlisting>
+SELECT ST_MinimumClearance('POLYGON ((0 0, 1 0, 1 1, 0.5 3.2e-4, 0 0))');
+ st_minimumclearance 
+---------------------
+             0.00032
+     </programlisting> 
+
+         </refsection>
+
+         <refsection>
+               <title>See Also</title>
+
+               <para>
+                       <xref linkend="ST_MinimumClearanceLine" /> 
+               </para>
+         </refsection>
+       </refentry>
+
+       <refentry id="ST_MinimumClearanceLine">
+               <refnamediv>
+                       <refname>ST_MinimumClearanceLine</refname>
+                       <refpurpose>Returns the two-point LineString spanning a geometry's minimum clearance.</refpurpose>
+               </refnamediv>
+
+         <refsynopsisdiv>
+               <funcsynopsis>
+                 <funcprototype>
+                       <funcdef>Geometry <function>ST_MinimumClearanceLine</function></funcdef>
+
+                       <paramdef><type>geometry </type>
+                       <parameter>g</parameter></paramdef>
+
+                 </funcprototype>
+               </funcsynopsis>
+         </refsynopsisdiv>
+
+         <refsection>
+               <title>Description</title>
+
+               <para>
+                       Returns the two-point LineString spanning a geometry's minimum clearance.  If the geometry does not have a minimum
+                       clearance, <varname>LINESTRING EMPTY</varname> will be returned.
+               </para>
+
+               <para>Availability: 2.3.0 - requires GEOS &gt;= 3.6.0</para>
+
+         </refsection>
+
+         <refsection>
+                 <title>Examples</title>
+                 <programlisting>
+SELECT ST_AsText(ST_MinimumClearanceLine('POLYGON ((0 0, 1 0, 1 1, 0.5 3.2e-4, 0 0))'));
+st_astext           
+-------------------------------
+LINESTRING(0.5 0.00032,0.5 0)
+                 </programlisting>
+         </refsection>
+
+         <refsection>
+               <title>See Also</title>
+
+               <para>
+                       <xref linkend="ST_MinimumClearance" /> 
+               </para>
+         </refsection>
+
+       </refentry>
+
+
        <refentry id="ST_HausdorffDistance">
          <refnamediv>
                <refname>ST_HausdorffDistance</refname>
index 61079bce6fc9db3ba4d1bcfd066604ae6112efc3..6678a9c12c8654bddd9bd6893a7d65f37730342a 100644 (file)
@@ -3662,3 +3662,98 @@ Datum ST_Voronoi(PG_FUNCTION_ARGS)
 
 #endif /* POSTGIS_GEOS_VERSION >= 35 */
 }
+
+/******************************************
+ *
+ * ST_MinimumClearance
+ *
+ * Returns the minimum clearance of a geometry.
+ *
+ ******************************************/
+Datum ST_MinimumClearance(PG_FUNCTION_ARGS);
+PG_FUNCTION_INFO_V1(ST_MinimumClearance);
+Datum ST_MinimumClearance(PG_FUNCTION_ARGS)
+{
+#if POSTGIS_GEOS_VERSION < 36
+       lwpgerror("The GEOS version this PostGIS binary "
+               "was compiled against (%d) doesn't support "
+               "'ST_MinimumClearance' function (3.6.0+ required)",
+               POSTGIS_GEOS_VERSION);
+       PG_RETURN_NULL();
+#else /* POSTGIS_GEOS_VERSION >= 36 */
+       GSERIALIZED* input;
+       GEOSGeometry* input_geos;
+       int error;
+       double result;
+
+       initGEOS(lwpgnotice, lwgeom_geos_error);
+
+       input = PG_GETARG_GSERIALIZED_P(0);
+       input_geos = POSTGIS2GEOS(input);
+       if (!input_geos)   /* exception thrown at construction */
+       {
+               HANDLE_GEOS_ERROR("Geometry could not be converted to GEOS");
+               PG_RETURN_NULL();
+       }
+
+       error = GEOSMinimumClearance(input_geos, &result);
+       GEOSGeom_destroy(input_geos);
+       if (error)
+       {
+               HANDLE_GEOS_ERROR("Error computing minimum clearance");
+               PG_RETURN_NULL();
+       }
+
+       PG_FREE_IF_COPY(input, 0);
+       PG_RETURN_FLOAT8(result);
+#endif
+}
+
+/******************************************
+ *
+ * ST_MinimumClearanceLine
+ *
+ * Returns the minimum clearance line of a geometry.
+ *
+ ******************************************/
+Datum ST_MinimumClearanceLine(PG_FUNCTION_ARGS);
+PG_FUNCTION_INFO_V1(ST_MinimumClearanceLine);
+Datum ST_MinimumClearanceLine(PG_FUNCTION_ARGS)
+{
+#if POSTGIS_GEOS_VERSION < 36
+       lwpgerror("The GEOS version this PostGIS binary "
+               "was compiled against (%d) doesn't support "
+               "'ST_MinimumClearanceLine' function (3.6.0+ required)",
+               POSTGIS_GEOS_VERSION);
+       PG_RETURN_NULL();
+#else /* POSTGIS_GEOS_VERSION >= 36 */
+       GSERIALIZED* input;
+       GSERIALIZED* result;
+       GEOSGeometry* input_geos;
+       GEOSGeometry* result_geos;
+
+       initGEOS(lwpgnotice, lwgeom_geos_error);
+
+       input = PG_GETARG_GSERIALIZED_P(0);
+       input_geos = POSTGIS2GEOS(input);
+       if (!input_geos)   /* exception thrown at construction */
+       {
+               HANDLE_GEOS_ERROR("Geometry could not be converted to GEOS");
+               PG_RETURN_NULL();
+       }
+
+       result_geos = GEOSMinimumClearanceLine(input_geos);
+       GEOSGeom_destroy(input_geos);
+       if (!result_geos)
+       {
+               HANDLE_GEOS_ERROR("Error computing minimum clearance");
+               PG_RETURN_NULL();
+       }
+
+       result = GEOS2POSTGIS(result_geos, LW_FALSE);
+       GEOSGeom_destroy(result_geos);
+
+       PG_FREE_IF_COPY(input, 0);
+       PG_RETURN_POINTER(result);
+#endif
+}
index a01d0bc09795d9bdae01d139138de221ded23315..8fdcc3e7bc1600fbc5fe46630a1d3ee585998a73 100644 (file)
@@ -4001,6 +4001,18 @@ CREATE OR REPLACE FUNCTION ST_IsValid(geometry)
        LANGUAGE 'c' IMMUTABLE STRICT
        COST 100;
 
+-- Availability: 2.3.0
+CREATE OR REPLACE FUNCTION ST_MinimumClearance(geometry)
+       RETURNS float8
+       AS 'MODULE_PATHNAME', 'ST_MinimumClearance'
+       LANGUAGE 'c' IMMUTABLE STRICT;
+
+-- Availability: 2.3.0
+CREATE OR REPLACE FUNCTION ST_MinimumClearanceLine(geometry)
+       RETURNS geometry
+       AS 'MODULE_PATHNAME', 'ST_MinimumClearanceLine'
+       LANGUAGE 'c' IMMUTABLE STRICT;
+
 -- PostGIS equivalent function: Centroid(geometry)
 CREATE OR REPLACE FUNCTION ST_Centroid(geometry)
        RETURNS geometry
index 0fb564bbc1f26f0f5391844019a4ee352b7c7a13..defdcfe8be4925438821157d25963c200ab1b998 100644 (file)
@@ -216,6 +216,12 @@ ifeq ($(shell expr $(POSTGIS_GEOS_VERSION) ">=" 35),1)
                voronoi
 endif
 
+ifeq ($(shell expr $(POSTGIS_GEOS_VERSION) ">=" 36),1)
+       # GEOS-3.6 adds:
+       # ST_MinimumClearance
+       TESTS += \
+               minimum_clearance
+endif
 
 ifeq ($(HAVE_JSON),yes)
        # JSON-C adds: