PostGIS  2.3.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 robustness
edgeOnlyif non-zero the result will be a MULTILINESTRING, otherwise it'll be a COLLECTION of polygons.

Definition at line 1972 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().

1972  {
1973 #if POSTGIS_GEOS_VERSION < 34
1974  lwerror("lwgeom_delaunay_triangulation: GEOS 3.4 or higher required");
1975  return NULL;
1976 #else
1977  GEOSGeometry *g1, *g3;
1978  LWGEOM *lwgeom_result;
1979 
1980  if (output < 0 || output > 2) {
1981  lwerror("lwgeom_delaunay_triangulation: invalid output type specified %d", output);
1982  return NULL;
1983  }
1984 
1985  initGEOS(lwnotice, lwgeom_geos_error);
1986 
1987  g1 = (GEOSGeometry *)LWGEOM2GEOS(lwgeom_in, 0);
1988  if ( ! g1 )
1989  {
1990  lwerror("lwgeom_delaunay_triangulation: Geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
1991  return NULL;
1992  }
1993 
1994  /* if output != 1 we want polys */
1995  g3 = GEOSDelaunayTriangulation(g1, tolerance, output == 1);
1996 
1997  /* Don't need input geometry anymore */
1998  GEOSGeom_destroy(g1);
1999 
2000  if (g3 == NULL)
2001  {
2002  lwerror("GEOSDelaunayTriangulation: %s", lwgeom_geos_errmsg);
2003  return NULL;
2004  }
2005 
2006  /* LWDEBUGF(3, "result: %s", GEOSGeomToWKT(g3)); */
2007 
2008  GEOSSetSRID(g3, lwgeom_get_srid(lwgeom_in));
2009 
2010  if (output == 2) {
2011  lwgeom_result = (LWGEOM *)lwtin_from_geos(g3, lwgeom_has_z(lwgeom_in));
2012  } else {
2013  lwgeom_result = GEOS2LWGEOM(g3, lwgeom_has_z(lwgeom_in));
2014  }
2015 
2016  GEOSGeom_destroy(g3);
2017 
2018  if (lwgeom_result == NULL) {
2019  if (output != 2) {
2020  lwerror("lwgeom_delaunay_triangulation: GEOS2LWGEOM returned null");
2021  } else {
2022  lwerror("lwgeom_delaunay_triangulation: lwtin_from_geos returned null");
2023  }
2024  return NULL;
2025  }
2026 
2027  return lwgeom_result;
2028 
2029 #endif /* POSTGIS_GEOS_VERSION < 34 */
2030 }
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:89
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
Definition: lwgeom.c:835
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:849
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:102

Here is the call graph for this function:

Here is the caller graph for this function: