PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwgeom_delaunay_triangulation()

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 2004 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().

2004  {
2005 #if POSTGIS_GEOS_VERSION < 34
2006  lwerror("lwgeom_delaunay_triangulation: GEOS 3.4 or higher required");
2007  return NULL;
2008 #else
2009  GEOSGeometry *g1, *g3;
2010  LWGEOM *lwgeom_result;
2011 
2012  if (output < 0 || output > 2) {
2013  lwerror("lwgeom_delaunay_triangulation: invalid output type specified %d", output);
2014  return NULL;
2015  }
2016 
2017  initGEOS(lwnotice, lwgeom_geos_error);
2018 
2019  g1 = (GEOSGeometry *)LWGEOM2GEOS(lwgeom_in, 0);
2020  if ( ! g1 )
2021  {
2022  lwerror("lwgeom_delaunay_triangulation: Geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
2023  return NULL;
2024  }
2025 
2026  /* if output != 1 we want polys */
2027  g3 = GEOSDelaunayTriangulation(g1, tolerance, output == 1);
2028 
2029  /* Don't need input geometry anymore */
2030  GEOSGeom_destroy(g1);
2031 
2032  if (g3 == NULL)
2033  {
2034  lwerror("GEOSDelaunayTriangulation: %s", lwgeom_geos_errmsg);
2035  return NULL;
2036  }
2037 
2038  /* LWDEBUGF(3, "result: %s", GEOSGeomToWKT(g3)); */
2039 
2040  GEOSSetSRID(g3, lwgeom_get_srid(lwgeom_in));
2041 
2042  if (output == 2) {
2043  lwgeom_result = (LWGEOM *)lwtin_from_geos(g3, lwgeom_has_z(lwgeom_in));
2044  } else {
2045  lwgeom_result = GEOS2LWGEOM(g3, lwgeom_has_z(lwgeom_in));
2046  }
2047 
2048  GEOSGeom_destroy(g3);
2049 
2050  if (lwgeom_result == NULL) {
2051  if (output != 2) {
2052  lwerror("lwgeom_delaunay_triangulation: GEOS2LWGEOM returned null");
2053  } else {
2054  lwerror("lwgeom_delaunay_triangulation: lwtin_from_geos returned null");
2055  }
2056  return NULL;
2057  }
2058 
2059  return lwgeom_result;
2060 
2061 #endif /* POSTGIS_GEOS_VERSION < 34 */
2062 }
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:871
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:885
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: