PostGIS  2.1.10dev-r@@SVN_REVISION@@
LWTIN * lwtin_from_geos ( const GEOSGeometry *  geom,
int  want3d 
)

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

References lwalloc(), lwcollection_construct(), LWDEBUG, lwerror(), lwtriangle_construct(), ptarray_from_GEOSCoordSeq(), SRID_UNKNOWN, and TINTYPE.

Referenced by lwgeom_delaunay_triangulation().

1320  {
1321  int type = GEOSGeomTypeId(geom);
1322  int hasZ;
1323  int SRID = GEOSGetSRID(geom);
1324 
1325  /* GEOS's 0 is equivalent to our unknown as for SRID values */
1326  if ( SRID == 0 ) SRID = SRID_UNKNOWN;
1327 
1328  if ( want3d ) {
1329  hasZ = GEOSHasZ(geom);
1330  if ( ! hasZ ) {
1331  LWDEBUG(3, "Geometry has no Z, won't provide one");
1332  want3d = 0;
1333  }
1334  }
1335 
1336  switch (type) {
1337  LWTRIANGLE **geoms;
1338  uint32_t i, ngeoms;
1339  case GEOS_GEOMETRYCOLLECTION:
1340  LWDEBUG(4, "lwgeom_from_geometry: it's a Collection or Multi");
1341 
1342  ngeoms = GEOSGetNumGeometries(geom);
1343  geoms = NULL;
1344  if ( ngeoms ) {
1345  geoms = lwalloc(ngeoms * sizeof *geoms);
1346  if (!geoms) {
1347  lwerror("lwtin_from_geos: can't allocate geoms");
1348  return NULL;
1349  }
1350  for (i=0; i<ngeoms; i++) {
1351  const GEOSGeometry *poly, *ring;
1352  const GEOSCoordSequence *cs;
1353  POINTARRAY *pa;
1354 
1355  poly = GEOSGetGeometryN(geom, i);
1356  ring = GEOSGetExteriorRing(poly);
1357  cs = GEOSGeom_getCoordSeq(ring);
1358  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
1359 
1360  geoms[i] = lwtriangle_construct(SRID, NULL, pa);
1361  }
1362  }
1363  return (LWTIN *)lwcollection_construct(TINTYPE, SRID, NULL, ngeoms, (LWGEOM **)geoms);
1364  case GEOS_POLYGON:
1365  case GEOS_MULTIPOINT:
1366  case GEOS_MULTILINESTRING:
1367  case GEOS_MULTIPOLYGON:
1368  case GEOS_LINESTRING:
1369  case GEOS_LINEARRING:
1370  case GEOS_POINT:
1371  lwerror("lwtin_from_geos: invalid geometry type for tin: %d", type);
1372  break;
1373 
1374  default:
1375  lwerror("GEOS2LWGEOM: unknown geometry type: %d", type);
1376  return NULL;
1377  }
1378 
1379  /* shouldn't get here */
1380  return NULL;
1381 }
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:30
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
LWGEOM * geom
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:154
#define TINTYPE
Definition: liblwgeom.h:74
LWTRIANGLE * lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwtriangle.c:27
void * lwalloc(size_t size)
Definition: lwutil.c:175
POINTARRAY * ptarray_from_GEOSCoordSeq(const GEOSCoordSequence *cs, char want3d)

Here is the call graph for this function:

Here is the caller graph for this function: