PostGIS  2.1.10dev-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 1385 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().

1385  {
1386 #if POSTGIS_GEOS_VERSION < 34
1387  lwerror("lwgeom_delaunay_triangulation: GEOS 3.4 or higher required");
1388  return NULL;
1389 #else
1390  GEOSGeometry *g1, *g3;
1391  LWGEOM *lwgeom_result;
1392 
1393  if (output < 0 || output > 2) {
1394  lwerror("lwgeom_delaunay_triangulation: invalid output type specified %d", output);
1395  return NULL;
1396  }
1397 
1398  initGEOS(lwnotice, lwgeom_geos_error);
1399 
1400  g1 = (GEOSGeometry *)LWGEOM2GEOS(lwgeom_in);
1401  if ( ! g1 )
1402  {
1403  lwerror("lwgeom_delaunay_triangulation: Geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
1404  return NULL;
1405  }
1406 
1407  /* if output != 1 we want polys */
1408  g3 = GEOSDelaunayTriangulation(g1, tolerance, output == 1);
1409 
1410  /* Don't need input geometry anymore */
1411  GEOSGeom_destroy(g1);
1412 
1413  if (g3 == NULL)
1414  {
1415  lwerror("GEOSDelaunayTriangulation: %s", lwgeom_geos_errmsg);
1416  return NULL;
1417  }
1418 
1419  /* LWDEBUGF(3, "result: %s", GEOSGeomToWKT(g3)); */
1420 
1421  GEOSSetSRID(g3, lwgeom_get_srid(lwgeom_in));
1422 
1423  if (output == 2) {
1424  lwgeom_result = (LWGEOM *)lwtin_from_geos(g3, lwgeom_has_z(lwgeom_in));
1425  } else {
1426  lwgeom_result = GEOS2LWGEOM(g3, lwgeom_has_z(lwgeom_in));
1427  }
1428 
1429  GEOSGeom_destroy(g3);
1430 
1431  if (lwgeom_result == NULL) {
1432  if (output != 2) {
1433  lwerror("lwgeom_delaunay_triangulation: GEOS2LWGEOM returned null");
1434  } else {
1435  lwerror("lwgeom_delaunay_triangulation: lwtin_from_geos returned null");
1436  }
1437  return NULL;
1438  }
1439 
1440  return lwgeom_result;
1441 
1442 #endif /* POSTGIS_GEOS_VERSION < 34 */
1443 }
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
Definition: lwgeom.c:778
LWTIN * lwtin_from_geos(const GEOSGeometry *geom, int want3d)
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom)
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:792
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:54
void lwgeom_geos_error(const char *fmt,...)
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, char want3d)

Here is the call graph for this function:

Here is the caller graph for this function: