PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ lwtin_from_geos()

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

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

1740 {
1741  int type = GEOSGeomTypeId(geom);
1742  int SRID = GEOSGetSRID(geom);
1743 
1744  /* GEOS's 0 is equivalent to our unknown as for SRID values */
1745  if (SRID == 0) SRID = SRID_UNKNOWN;
1746 
1747  if (want3d && !GEOSHasZ(geom))
1748  {
1749  LWDEBUG(3, "Geometry has no Z, won't provide one");
1750  want3d = 0;
1751  }
1752 
1753  switch (type)
1754  {
1755  LWTRIANGLE** geoms;
1756  uint32_t i, ngeoms;
1757  case GEOS_GEOMETRYCOLLECTION:
1758  LWDEBUG(4, "lwgeom_from_geometry: it's a Collection or Multi");
1759 
1760  ngeoms = GEOSGetNumGeometries(geom);
1761  geoms = NULL;
1762  if (ngeoms)
1763  {
1764  geoms = lwalloc(ngeoms * sizeof *geoms);
1765  if (!geoms)
1766  {
1767  lwerror("lwtin_from_geos: can't allocate geoms");
1768  return NULL;
1769  }
1770  for (i = 0; i < ngeoms; i++)
1771  {
1772  const GEOSGeometry *poly, *ring;
1773  const GEOSCoordSequence* cs;
1774  POINTARRAY* pa;
1775 
1776  poly = GEOSGetGeometryN(geom, i);
1777  ring = GEOSGetExteriorRing(poly);
1778  cs = GEOSGeom_getCoordSeq(ring);
1779  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
1780 
1781  geoms[i] = lwtriangle_construct(SRID, NULL, pa);
1782  }
1783  }
1784  return (LWTIN*)lwcollection_construct(TINTYPE, SRID, NULL, ngeoms, (LWGEOM**)geoms);
1785  case GEOS_POLYGON:
1786  case GEOS_MULTIPOINT:
1787  case GEOS_MULTILINESTRING:
1788  case GEOS_MULTIPOLYGON:
1789  case GEOS_LINESTRING:
1790  case GEOS_LINEARRING:
1791  case GEOS_POINT:
1792  lwerror("lwtin_from_geos: invalid geometry type for tin: %d", type);
1793  break;
1794 
1795  default:
1796  lwerror("GEOS2LWGEOM: unknown geometry type: %d", type);
1797  return NULL;
1798  }
1799 
1800  /* shouldn't get here */
1801  return NULL;
1802 }
POINTARRAY * ptarray_from_GEOSCoordSeq(const GEOSCoordSequence *cs, uint8_t want3d)
#define TINTYPE
Definition: liblwgeom.h:130
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:229
LWTRIANGLE * lwtriangle_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition: lwtriangle.c:40
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
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: