PostGIS  2.2.7dev-r@@SVN_REVISION@@
LWGEOM* lwgeom_delaunay_triangulation ( const LWGEOM geom,
double  tolerance,
int  edgeOnly 
)

Take vertices of a geometry and build a delaunay triangulation on them.

Parameters
geomthe input geometry
tolerancean optional snapping tolerance for improved tolerance
edgeOnlyif non-zero the result will be a MULTILINESTRING, otherwise it'll be a COLLECTION of polygons.

Definition at line 1662 of file liblwgeom/lwgeom_geos.c.

References GEOS2LWGEOM(), lwerror(), LWGEOM2GEOS(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwgeom_get_srid(), lwgeom_has_z(), lwnotice(), and lwtin_from_geos().

Referenced by ST_DelaunayTriangles(), and test_lwgeom_delaunay_triangulation().

1662  {
1663 #if POSTGIS_GEOS_VERSION < 34
1664  lwerror("lwgeom_delaunay_triangulation: GEOS 3.4 or higher required");
1665  return NULL;
1666 #else
1667  GEOSGeometry *g1, *g3;
1668  LWGEOM *lwgeom_result;
1669 
1670  if (output < 0 || output > 2) {
1671  lwerror("lwgeom_delaunay_triangulation: invalid output type specified %d", output);
1672  return NULL;
1673  }
1674 
1675  initGEOS(lwnotice, lwgeom_geos_error);
1676 
1677  g1 = (GEOSGeometry *)LWGEOM2GEOS(lwgeom_in, 0);
1678  if ( ! g1 )
1679  {
1680  lwerror("lwgeom_delaunay_triangulation: Geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
1681  return NULL;
1682  }
1683 
1684  /* if output != 1 we want polys */
1685  g3 = GEOSDelaunayTriangulation(g1, tolerance, output == 1);
1686 
1687  /* Don't need input geometry anymore */
1688  GEOSGeom_destroy(g1);
1689 
1690  if (g3 == NULL)
1691  {
1692  lwerror("GEOSDelaunayTriangulation: %s", lwgeom_geos_errmsg);
1693  return NULL;
1694  }
1695 
1696  /* LWDEBUGF(3, "result: %s", GEOSGeomToWKT(g3)); */
1697 
1698  GEOSSetSRID(g3, lwgeom_get_srid(lwgeom_in));
1699 
1700  if (output == 2) {
1701  lwgeom_result = (LWGEOM *)lwtin_from_geos(g3, lwgeom_has_z(lwgeom_in));
1702  } else {
1703  lwgeom_result = GEOS2LWGEOM(g3, lwgeom_has_z(lwgeom_in));
1704  }
1705 
1706  GEOSGeom_destroy(g3);
1707 
1708  if (lwgeom_result == NULL) {
1709  if (output != 2) {
1710  lwerror("lwgeom_delaunay_triangulation: GEOS2LWGEOM returned null");
1711  } else {
1712  lwerror("lwgeom_delaunay_triangulation: lwtin_from_geos returned null");
1713  }
1714  return NULL;
1715  }
1716 
1717  return lwgeom_result;
1718 
1719 #endif /* POSTGIS_GEOS_VERSION < 34 */
1720 }
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:61
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
Definition: lwgeom.c:822
LWTIN * lwtin_from_geos(const GEOSGeometry *geom, int want3d)
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:836
void lwgeom_geos_error(const char *fmt,...)
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, int autofix)
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, char want3d)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74

Here is the call graph for this function:

Here is the caller graph for this function: