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

Definition at line 1934 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().

1934  {
1935  int type = GEOSGeomTypeId(geom);
1936  int hasZ;
1937  int SRID = GEOSGetSRID(geom);
1938 
1939  /* GEOS's 0 is equivalent to our unknown as for SRID values */
1940  if ( SRID == 0 ) SRID = SRID_UNKNOWN;
1941 
1942  if ( want3d ) {
1943  hasZ = GEOSHasZ(geom);
1944  if ( ! hasZ ) {
1945  LWDEBUG(3, "Geometry has no Z, won't provide one");
1946  want3d = 0;
1947  }
1948  }
1949 
1950  switch (type) {
1951  LWTRIANGLE **geoms;
1952  uint32_t i, ngeoms;
1953  case GEOS_GEOMETRYCOLLECTION:
1954  LWDEBUG(4, "lwgeom_from_geometry: it's a Collection or Multi");
1955 
1956  ngeoms = GEOSGetNumGeometries(geom);
1957  geoms = NULL;
1958  if ( ngeoms ) {
1959  geoms = lwalloc(ngeoms * sizeof *geoms);
1960  if (!geoms) {
1961  lwerror("lwtin_from_geos: can't allocate geoms");
1962  return NULL;
1963  }
1964  for (i=0; i<ngeoms; i++) {
1965  const GEOSGeometry *poly, *ring;
1966  const GEOSCoordSequence *cs;
1967  POINTARRAY *pa;
1968 
1969  poly = GEOSGetGeometryN(geom, i);
1970  ring = GEOSGetExteriorRing(poly);
1971  cs = GEOSGeom_getCoordSeq(ring);
1972  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
1973 
1974  geoms[i] = lwtriangle_construct(SRID, NULL, pa);
1975  }
1976  }
1977  return (LWTIN *)lwcollection_construct(TINTYPE, SRID, NULL, ngeoms, (LWGEOM **)geoms);
1978  case GEOS_POLYGON:
1979  case GEOS_MULTIPOINT:
1980  case GEOS_MULTILINESTRING:
1981  case GEOS_MULTIPOLYGON:
1982  case GEOS_LINESTRING:
1983  case GEOS_LINEARRING:
1984  case GEOS_POINT:
1985  lwerror("lwtin_from_geos: invalid geometry type for tin: %d", type);
1986  break;
1987 
1988  default:
1989  lwerror("GEOS2LWGEOM: unknown geometry type: %d", type);
1990  return NULL;
1991  }
1992 
1993  /* shouldn't get here */
1994  return NULL;
1995 }
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:43
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
unsigned int uint32_t
Definition: uthash.h:78
LWGEOM * geom
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:187
#define TINTYPE
Definition: liblwgeom.h:98
LWTRIANGLE * lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwtriangle.c:40
void * lwalloc(size_t size)
Definition: lwutil.c:229
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:190

Here is the call graph for this function:

Here is the caller graph for this function: