PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ lwtin_from_geos()

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

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

1942 {
1943  int type = GEOSGeomTypeId(geom);
1944  int SRID = GEOSGetSRID(geom);
1945 
1946  /* GEOS's 0 is equivalent to our unknown as for SRID values */
1947  if (SRID == 0) SRID = SRID_UNKNOWN;
1948 
1949  if (want3d && !GEOSHasZ(geom))
1950  {
1951  LWDEBUG(3, "Geometry has no Z, won't provide one");
1952  want3d = 0;
1953  }
1954 
1955  switch (type)
1956  {
1957  LWTRIANGLE** geoms;
1958  uint32_t i, ngeoms;
1959  case GEOS_GEOMETRYCOLLECTION:
1960  LWDEBUG(4, "lwgeom_from_geometry: it's a Collection or Multi");
1961 
1962  ngeoms = GEOSGetNumGeometries(geom);
1963  geoms = NULL;
1964  if (ngeoms)
1965  {
1966  geoms = lwalloc(ngeoms * sizeof *geoms);
1967  if (!geoms)
1968  {
1969  lwerror("lwtin_from_geos: can't allocate geoms");
1970  return NULL;
1971  }
1972  for (i = 0; i < ngeoms; i++)
1973  {
1974  const GEOSGeometry *poly, *ring;
1975  const GEOSCoordSequence* cs;
1976  POINTARRAY* pa;
1977 
1978  poly = GEOSGetGeometryN(geom, i);
1979  ring = GEOSGetExteriorRing(poly);
1980  cs = GEOSGeom_getCoordSeq(ring);
1981  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
1982 
1983  geoms[i] = lwtriangle_construct(SRID, NULL, pa);
1984  }
1985  }
1986  return (LWTIN*)lwcollection_construct(TINTYPE, SRID, NULL, ngeoms, (LWGEOM**)geoms);
1987  case GEOS_POLYGON:
1988  case GEOS_MULTIPOINT:
1989  case GEOS_MULTILINESTRING:
1990  case GEOS_MULTIPOLYGON:
1991  case GEOS_LINESTRING:
1992  case GEOS_LINEARRING:
1993  case GEOS_POINT:
1994  lwerror("lwtin_from_geos: invalid geometry type for tin: %d", type);
1995  break;
1996 
1997  default:
1998  lwerror("GEOS2LWGEOM: unknown geometry type: %d", type);
1999  return NULL;
2000  }
2001 
2002  /* shouldn't get here */
2003  return NULL;
2004 }
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: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: