]> granicus.if.org Git - postgis/commitdiff
Add ST_DelaunayTriangles (#1215)
authorSandro Santilli <strk@keybit.net>
Wed, 27 Jun 2012 15:53:53 +0000 (15:53 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 27 Jun 2012 15:53:53 +0000 (15:53 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9994 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
doc/reference_processing.xml
postgis/lwgeom_geos.c
postgis/postgis.sql.in.c
regress/Makefile.in
regress/delaunaytriangles.sql [new file with mode: 0644]
regress/delaunaytriangles_expected [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 02d5aaf435b9e60e3ca64d15753a04a632f3b4ef..8704a81e2952b0ef7f3f081b2259881c43093f3a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ PostGIS 2.1.0
 
 * New Features *
 
+  - ST_DelaunayTriangles (Sandro Santilli / Vizzuality)
   - ST_NearestValue, ST_Neighborhood (Bborie Park / UC Davis)
   - ST_Raster2WorldCoord, ST_World2RasterCoord (Bborie Park / UC Davis)
   - #1643, Tiger Geocoder - Tiger 2011 loader (Regina Obe / Paragon Corporation) 
index 871057265b80e1273c0538c8814c1e44e4ccbd15..eb7fdced9765a606cb9cc21314d247ad06618f93 100644 (file)
@@ -870,6 +870,50 @@ st_astext
          </refsection>
        </refentry>
 
+       <refentry id="ST_DelaunayTriangles">
+               <refnamediv>
+                       <refname>ST_DelaunayTriangles</refname>
+
+                       <refpurpose>
+Return a Delaunay triangulation around the given input points.
+                       </refpurpose>
+               </refnamediv>
+
+               <refsynopsisdiv>
+                       <funcsynopsis>
+                         <funcprototype>
+                               <funcdef>geometry <function>ST_DelaunayTriangles</function></funcdef>
+                               <paramdef><type>geometry </type> <parameter>g1</parameter></paramdef>
+                               <paramdef><type>float </type> <parameter>tolerance</parameter></paramdef>
+                               <paramdef><type>int4 </type> <parameter>flags</parameter></paramdef>
+                         </funcprototype>
+                       </funcsynopsis>
+               </refsynopsisdiv>
+
+                 <refsection>
+                       <title>Description</title>
+
+                       <para>
+Return a <ulink
+url="http://en.wikipedia.org/wiki/Delaunay_triangulation">Delaunay
+triangulation</ulink> around the vertices of the input geometry.
+Output is a COLLECTION of polygons (for flags=0) or a MULTILINESTRING
+(for flags=1).  The tolerance, if any, is used to snap input vertices
+togheter.
+                       </para>
+
+                       <para>Availability: 2.1.0 - requires GEOS &gt;= 3.4.0.</para>
+
+               </refsection>
+
+               <refsection>
+                       <title>See Also</title>
+                       <para>
+<xref linkend="ST_Dump" />
+                       </para>
+               </refsection>
+       </refentry>
+
        <refentry id="ST_Difference">
          <refnamediv>
                <refname>ST_Difference</refname>
index b54535739510ddecd42621c1f994345fd0964351..cd31cf64309502161f236e659e7dd78be768359f 100644 (file)
@@ -72,6 +72,7 @@ Datum hausdorffdistancedensify(PG_FUNCTION_ARGS);
 Datum ST_UnaryUnion(PG_FUNCTION_ARGS);
 Datum ST_Equals(PG_FUNCTION_ARGS);
 Datum ST_BuildArea(PG_FUNCTION_ARGS);
+Datum ST_DelaunayTriangles(PG_FUNCTION_ARGS);
 
 Datum pgis_union_geometry_array(PG_FUNCTION_ARGS);
 
@@ -3374,6 +3375,39 @@ Datum ST_BuildArea(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(result);
 }
 
+/*
+ * Take the vertices of a geometry and builds
+ * Delaunay triangles around them.
+ */
+PG_FUNCTION_INFO_V1(ST_DelaunayTriangles);
+Datum ST_DelaunayTriangles(PG_FUNCTION_ARGS)
+{
+       GSERIALIZED *result;
+       GSERIALIZED *geom;
+       LWGEOM *lwgeom_in, *lwgeom_out;
+       double  tolerance = 0.0;
+       int flags = 0;
+
+       geom = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+       tolerance = PG_GETARG_FLOAT8(1);
+       flags = PG_GETARG_INT32(2);
+
+       lwgeom_in = lwgeom_from_gserialized(geom);
+       lwgeom_out = lwgeom_delaunay_triangulation(lwgeom_in, tolerance, flags);
+       lwgeom_free(lwgeom_in) ;
+       
+       if ( ! lwgeom_out ) {
+               PG_FREE_IF_COPY(geom, 0);
+               PG_RETURN_NULL();
+       }
+
+       result = geometry_serialize(lwgeom_out) ;
+       lwgeom_free(lwgeom_out) ;
+
+       PG_FREE_IF_COPY(geom, 0);
+       PG_RETURN_POINTER(result);
+}
+
 /*
  * ST_Snap
  *
index e9541e0b87ee2daadd846524ffcdc8f5f8caa184..021ba0572300bc078ea75ebc05db93959f86f332 100644 (file)
@@ -2965,6 +2965,30 @@ CREATE OR REPLACE FUNCTION ST_Node(g geometry)
        LANGUAGE 'c' IMMUTABLE STRICT
        COST 100;
 
+--------------------------------------------------------------------------------
+-- ST_DelaunayTriangles
+--------------------------------------------------------------------------------
+
+-- ST_DelaunayTriangles(g1 geometry, tolerance float8, flags int4)
+--
+-- Builds Delaunay triangulation out of geometry vertices.
+--
+-- Returns a collection of triangular polygons with flags=0
+-- or a multilinestring with flags=1
+--
+-- If a tolerance is given it will be used to snap the input points
+-- each-other.
+-- 
+--
+-- Availability: 2.1.0
+-- Requires GEOS >= 3.4.0
+--
+CREATE OR REPLACE FUNCTION ST_DelaunayTriangles(g1 geometry, tolerance float8 DEFAULT 0.0, flags int4 DEFAULT 0)
+       RETURNS geometry
+       AS 'MODULE_PATHNAME', 'ST_DelaunayTriangles'
+       LANGUAGE 'c' IMMUTABLE STRICT
+       COST 100;
+
 
 --------------------------------------------------------------------------------
 -- Aggregates and their supporting functions
index 33648990638ccfbd6cc6a62d5bb93ac6e10558a7..a454f5f5f95181eda6572655093b1be7c4378b49 100644 (file)
@@ -140,6 +140,13 @@ ifeq ($(shell expr $(POSTGIS_GEOS_VERSION) ">=" 33),1)
                relate_bnr
 endif
 
+ifeq ($(shell expr $(POSTGIS_GEOS_VERSION) ">=" 34),1)
+       # GEOS-3.4 adds:
+       # ST_DelaunayTriangles
+       TESTS += \
+               delaunaytriangles
+endif
+
 ifeq ($(HAVE_JSON),yes)
        # JSON-C adds:
        # ST_GeomFromGeoJSON()
diff --git a/regress/delaunaytriangles.sql b/regress/delaunaytriangles.sql
new file mode 100644 (file)
index 0000000..f87cdc6
--- /dev/null
@@ -0,0 +1,5 @@
+-- TODO: normalize !
+SELECT 1,  ST_AsText(ST_DelaunayTriangles('MULTIPOINT(5 5, 6 0, 7 9)'::geometry));
+SELECT 2,  ST_AsText(ST_DelaunayTriangles('MULTIPOINT(5 5, 6 0, 7 9, 8 9)'::geometry));
+SELECT 3,  ST_AsText(ST_DelaunayTriangles('MULTIPOINT(5 5, 6 0, 7 9, 8 9)'::geometry, 2));
+SELECT 4,  ST_AsText(ST_DelaunayTriangles('MULTIPOINT(5 5, 6 0, 7 9, 8 9)'::geometry, 2, 1));
diff --git a/regress/delaunaytriangles_expected b/regress/delaunaytriangles_expected
new file mode 100644 (file)
index 0000000..78e5c6d
--- /dev/null
@@ -0,0 +1,4 @@
+1|GEOMETRYCOLLECTION(POLYGON((5 5,6 0,7 9,5 5)))
+2|GEOMETRYCOLLECTION(POLYGON((5 5,6 0,8 9,5 5)),POLYGON((5 5,8 9,7 9,5 5)))
+3|GEOMETRYCOLLECTION(POLYGON((5 5,6 0,7 9,5 5)))
+4|MULTILINESTRING((5 5,7 9),(5 5,6 0),(6 0,7 9))