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

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

1907  {
1908  int type = GEOSGeomTypeId(geom);
1909  int hasZ;
1910  int SRID = GEOSGetSRID(geom);
1911 
1912  /* GEOS's 0 is equivalent to our unknown as for SRID values */
1913  if ( SRID == 0 ) SRID = SRID_UNKNOWN;
1914 
1915  if ( want3d ) {
1916  hasZ = GEOSHasZ(geom);
1917  if ( ! hasZ ) {
1918  LWDEBUG(3, "Geometry has no Z, won't provide one");
1919  want3d = 0;
1920  }
1921  }
1922 
1923  switch (type) {
1924  LWTRIANGLE **geoms;
1925  uint32_t i, ngeoms;
1926  case GEOS_GEOMETRYCOLLECTION:
1927  LWDEBUG(4, "lwgeom_from_geometry: it's a Collection or Multi");
1928 
1929  ngeoms = GEOSGetNumGeometries(geom);
1930  geoms = NULL;
1931  if ( ngeoms ) {
1932  geoms = lwalloc(ngeoms * sizeof *geoms);
1933  if (!geoms) {
1934  lwerror("lwtin_from_geos: can't allocate geoms");
1935  return NULL;
1936  }
1937  for (i=0; i<ngeoms; i++) {
1938  const GEOSGeometry *poly, *ring;
1939  const GEOSCoordSequence *cs;
1940  POINTARRAY *pa;
1941 
1942  poly = GEOSGetGeometryN(geom, i);
1943  ring = GEOSGetExteriorRing(poly);
1944  cs = GEOSGeom_getCoordSeq(ring);
1945  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
1946 
1947  geoms[i] = lwtriangle_construct(SRID, NULL, pa);
1948  }
1949  }
1950  return (LWTIN *)lwcollection_construct(TINTYPE, SRID, NULL, ngeoms, (LWGEOM **)geoms);
1951  case GEOS_POLYGON:
1952  case GEOS_MULTIPOINT:
1953  case GEOS_MULTILINESTRING:
1954  case GEOS_MULTIPOLYGON:
1955  case GEOS_LINESTRING:
1956  case GEOS_LINEARRING:
1957  case GEOS_POINT:
1958  lwerror("lwtin_from_geos: invalid geometry type for tin: %d", type);
1959  break;
1960 
1961  default:
1962  lwerror("GEOS2LWGEOM: unknown geometry type: %d", type);
1963  return NULL;
1964  }
1965 
1966  /* shouldn't get here */
1967  return NULL;
1968 }
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
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:227
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:102

Here is the call graph for this function:

Here is the caller graph for this function: