PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwtin_from_geos()

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

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

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