PostGIS  2.5.0dev-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 1999 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().

1999  {
2000 #if POSTGIS_GEOS_VERSION < 34
2001  lwerror("lwgeom_delaunay_triangulation: GEOS 3.4 or higher required");
2002  return NULL;
2003 #else
2004  GEOSGeometry *g1, *g3;
2005  LWGEOM *lwgeom_result;
2006 
2007  if (output < 0 || output > 2) {
2008  lwerror("lwgeom_delaunay_triangulation: invalid output type specified %d", output);
2009  return NULL;
2010  }
2011 
2012  initGEOS(lwnotice, lwgeom_geos_error);
2013 
2014  g1 = (GEOSGeometry *)LWGEOM2GEOS(lwgeom_in, 0);
2015  if ( ! g1 )
2016  {
2017  lwerror("lwgeom_delaunay_triangulation: Geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
2018  return NULL;
2019  }
2020 
2021  /* if output != 1 we want polys */
2022  g3 = GEOSDelaunayTriangulation(g1, tolerance, output == 1);
2023 
2024  /* Don't need input geometry anymore */
2025  GEOSGeom_destroy(g1);
2026 
2027  if (g3 == NULL)
2028  {
2029  lwerror("GEOSDelaunayTriangulation: %s", lwgeom_geos_errmsg);
2030  return NULL;
2031  }
2032 
2033  /* LWDEBUGF(3, "result: %s", GEOSGeomToWKT(g3)); */
2034 
2035  GEOSSetSRID(g3, lwgeom_get_srid(lwgeom_in));
2036 
2037  if (output == 2) {
2038  lwgeom_result = (LWGEOM *)lwtin_from_geos(g3, lwgeom_has_z(lwgeom_in));
2039  } else {
2040  lwgeom_result = GEOS2LWGEOM(g3, lwgeom_has_z(lwgeom_in));
2041  }
2042 
2043  GEOSGeom_destroy(g3);
2044 
2045  if (lwgeom_result == NULL) {
2046  if (output != 2) {
2047  lwerror("lwgeom_delaunay_triangulation: GEOS2LWGEOM returned null");
2048  } else {
2049  lwerror("lwgeom_delaunay_triangulation: lwtin_from_geos returned null");
2050  }
2051  return NULL;
2052  }
2053 
2054  return lwgeom_result;
2055 
2056 #endif /* POSTGIS_GEOS_VERSION < 34 */
2057 }
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
Definition: lwgeom.c:909
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:923
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:190

Here is the call graph for this function:

Here is the caller graph for this function: