PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ lwtin_from_geos()

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

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

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