PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ lwtin_from_geos()

LWTIN * lwtin_from_geos ( const GEOSGeometry *  geom,
int  want3d 
)

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

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

Referenced by lwgeom_delaunay_triangulation().

1597  {
1598  int type = GEOSGeomTypeId(geom);
1599  int hasZ;
1600  int SRID = GEOSGetSRID(geom);
1601 
1602  /* GEOS's 0 is equivalent to our unknown as for SRID values */
1603  if ( SRID == 0 ) SRID = SRID_UNKNOWN;
1604 
1605  if ( want3d ) {
1606  hasZ = GEOSHasZ(geom);
1607  if ( ! hasZ ) {
1608  LWDEBUG(3, "Geometry has no Z, won't provide one");
1609  want3d = 0;
1610  }
1611  }
1612 
1613  switch (type) {
1614  LWTRIANGLE **geoms;
1615  uint32_t i, ngeoms;
1616  case GEOS_GEOMETRYCOLLECTION:
1617  LWDEBUG(4, "lwgeom_from_geometry: it's a Collection or Multi");
1618 
1619  ngeoms = GEOSGetNumGeometries(geom);
1620  geoms = NULL;
1621  if ( ngeoms ) {
1622  geoms = lwalloc(ngeoms * sizeof *geoms);
1623  if (!geoms) {
1624  lwerror("lwtin_from_geos: can't allocate geoms");
1625  return NULL;
1626  }
1627  for (i=0; i<ngeoms; i++) {
1628  const GEOSGeometry *poly, *ring;
1629  const GEOSCoordSequence *cs;
1630  POINTARRAY *pa;
1631 
1632  poly = GEOSGetGeometryN(geom, i);
1633  ring = GEOSGetExteriorRing(poly);
1634  cs = GEOSGeom_getCoordSeq(ring);
1635  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
1636 
1637  geoms[i] = lwtriangle_construct(SRID, NULL, pa);
1638  }
1639  }
1640  return (LWTIN *)lwcollection_construct(TINTYPE, SRID, NULL, ngeoms, (LWGEOM **)geoms);
1641  case GEOS_POLYGON:
1642  case GEOS_MULTIPOINT:
1643  case GEOS_MULTILINESTRING:
1644  case GEOS_MULTIPOLYGON:
1645  case GEOS_LINESTRING:
1646  case GEOS_LINEARRING:
1647  case GEOS_POINT:
1648  lwerror("lwtin_from_geos: invalid geometry type for tin: %d", type);
1649  break;
1650 
1651  default:
1652  lwerror("GEOS2LWGEOM: unknown geometry type: %d", type);
1653  return NULL;
1654  }
1655 
1656  /* shouldn't get here */
1657  return NULL;
1658 }
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
LWGEOM * geom
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:172
#define TINTYPE
Definition: liblwgeom.h:84
LWTRIANGLE * lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwtriangle.c:27
type
Definition: ovdump.py:41
void * lwalloc(size_t size)
Definition: lwutil.c:199
POINTARRAY * ptarray_from_GEOSCoordSeq(const GEOSCoordSequence *cs, char want3d)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
Here is the call graph for this function:
Here is the caller graph for this function: