PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ lwtin_from_geos()

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

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

1889 {
1890  int type = GEOSGeomTypeId(geom);
1891  int SRID = GEOSGetSRID(geom);
1892 
1893  /* GEOS's 0 is equivalent to our unknown as for SRID values */
1894  if (SRID == 0) SRID = SRID_UNKNOWN;
1895 
1896  if (want3d && !GEOSHasZ(geom))
1897  {
1898  LWDEBUG(3, "Geometry has no Z, won't provide one");
1899  want3d = 0;
1900  }
1901 
1902  switch (type)
1903  {
1904  LWTRIANGLE** geoms;
1905  uint32_t i, ngeoms;
1906  case GEOS_GEOMETRYCOLLECTION:
1907  LWDEBUG(4, "lwgeom_from_geometry: it's a Collection or Multi");
1908 
1909  ngeoms = GEOSGetNumGeometries(geom);
1910  geoms = NULL;
1911  if (ngeoms)
1912  {
1913  geoms = lwalloc(ngeoms * sizeof *geoms);
1914  if (!geoms)
1915  {
1916  lwerror("lwtin_from_geos: can't allocate geoms");
1917  return NULL;
1918  }
1919  for (i = 0; i < ngeoms; i++)
1920  {
1921  const GEOSGeometry *poly, *ring;
1922  const GEOSCoordSequence* cs;
1923  POINTARRAY* pa;
1924 
1925  poly = GEOSGetGeometryN(geom, i);
1926  ring = GEOSGetExteriorRing(poly);
1927  cs = GEOSGeom_getCoordSeq(ring);
1928  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
1929 
1930  geoms[i] = lwtriangle_construct(SRID, NULL, pa);
1931  }
1932  }
1933  return (LWTIN*)lwcollection_construct(TINTYPE, SRID, NULL, ngeoms, (LWGEOM**)geoms);
1934  case GEOS_POLYGON:
1935  case GEOS_MULTIPOINT:
1936  case GEOS_MULTILINESTRING:
1937  case GEOS_MULTIPOLYGON:
1938  case GEOS_LINESTRING:
1939  case GEOS_LINEARRING:
1940  case GEOS_POINT:
1941  lwerror("lwtin_from_geos: invalid geometry type for tin: %d", type);
1942  break;
1943 
1944  default:
1945  lwerror("GEOS2LWGEOM: unknown geometry type: %d", type);
1946  return NULL;
1947  }
1948 
1949  /* shouldn't get here */
1950  return NULL;
1951 }
POINTARRAY * ptarray_from_GEOSCoordSeq(const GEOSCoordSequence *cs, uint8_t want3d)
#define TINTYPE
Definition: liblwgeom.h:130
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:229
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: