PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ lwtin_from_geos()

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

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

1683 {
1684  int type = GEOSGeomTypeId(geom);
1685  int SRID = GEOSGetSRID(geom);
1686 
1687  /* GEOS's 0 is equivalent to our unknown as for SRID values */
1688  if (SRID == 0) SRID = SRID_UNKNOWN;
1689 
1690  if (want3d && !GEOSHasZ(geom))
1691  {
1692  LWDEBUG(3, "Geometry has no Z, won't provide one");
1693  want3d = 0;
1694  }
1695 
1696  switch (type)
1697  {
1698  LWTRIANGLE** geoms;
1699  uint32_t i, ngeoms;
1700  case GEOS_GEOMETRYCOLLECTION:
1701  LWDEBUG(4, "lwgeom_from_geometry: it's a Collection or Multi");
1702 
1703  ngeoms = GEOSGetNumGeometries(geom);
1704  geoms = NULL;
1705  if (ngeoms)
1706  {
1707  geoms = lwalloc(ngeoms * sizeof *geoms);
1708  if (!geoms)
1709  {
1710  lwerror("lwtin_from_geos: can't allocate geoms");
1711  return NULL;
1712  }
1713  for (i = 0; i < ngeoms; i++)
1714  {
1715  const GEOSGeometry *poly, *ring;
1716  const GEOSCoordSequence* cs;
1717  POINTARRAY* pa;
1718 
1719  poly = GEOSGetGeometryN(geom, i);
1720  ring = GEOSGetExteriorRing(poly);
1721  cs = GEOSGeom_getCoordSeq(ring);
1722  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
1723 
1724  geoms[i] = lwtriangle_construct(SRID, NULL, pa);
1725  }
1726  }
1727  return (LWTIN*)lwcollection_construct(TINTYPE, SRID, NULL, ngeoms, (LWGEOM**)geoms);
1728  case GEOS_POLYGON:
1729  case GEOS_MULTIPOINT:
1730  case GEOS_MULTILINESTRING:
1731  case GEOS_MULTIPOLYGON:
1732  case GEOS_LINESTRING:
1733  case GEOS_LINEARRING:
1734  case GEOS_POINT:
1735  lwerror("lwtin_from_geos: invalid geometry type for tin: %d", type);
1736  break;
1737 
1738  default:
1739  lwerror("GEOS2LWGEOM: unknown geometry type: %d", type);
1740  return NULL;
1741  }
1742 
1743  /* shouldn't get here */
1744  return NULL;
1745 }
POINTARRAY * ptarray_from_GEOSCoordSeq(const GEOSCoordSequence *cs, uint8_t want3d)
#define TINTYPE
Definition: liblwgeom.h:116
void * lwalloc(size_t size)
Definition: lwutil.c:227
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:42
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:215
LWTRIANGLE * lwtriangle_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition: lwtriangle.c:40
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:101
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
type
Definition: ovdump.py:42

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

Referenced by lwgeom_delaunay_triangulation().

Here is the call graph for this function:
Here is the caller graph for this function: