PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ lwtin_from_geos()

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

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

1866 {
1867  int type = GEOSGeomTypeId(geom);
1868  int SRID = GEOSGetSRID(geom);
1869 
1870  /* GEOS's 0 is equivalent to our unknown as for SRID values */
1871  if (SRID == 0) SRID = SRID_UNKNOWN;
1872 
1873  if (want3d && !GEOSHasZ(geom))
1874  {
1875  LWDEBUG(3, "Geometry has no Z, won't provide one");
1876  want3d = 0;
1877  }
1878 
1879  switch (type)
1880  {
1881  LWTRIANGLE** geoms;
1882  uint32_t i, ngeoms;
1883  case GEOS_GEOMETRYCOLLECTION:
1884  LWDEBUG(4, "lwgeom_from_geometry: it's a Collection or Multi");
1885 
1886  ngeoms = GEOSGetNumGeometries(geom);
1887  geoms = NULL;
1888  if (ngeoms)
1889  {
1890  geoms = lwalloc(ngeoms * sizeof *geoms);
1891  if (!geoms)
1892  {
1893  lwerror("lwtin_from_geos: can't allocate geoms");
1894  return NULL;
1895  }
1896  for (i = 0; i < ngeoms; i++)
1897  {
1898  const GEOSGeometry *poly, *ring;
1899  const GEOSCoordSequence* cs;
1900  POINTARRAY* pa;
1901 
1902  poly = GEOSGetGeometryN(geom, i);
1903  ring = GEOSGetExteriorRing(poly);
1904  cs = GEOSGeom_getCoordSeq(ring);
1905  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
1906 
1907  geoms[i] = lwtriangle_construct(SRID, NULL, pa);
1908  }
1909  }
1910  return (LWTIN*)lwcollection_construct(TINTYPE, SRID, NULL, ngeoms, (LWGEOM**)geoms);
1911  case GEOS_POLYGON:
1912  case GEOS_MULTIPOINT:
1913  case GEOS_MULTILINESTRING:
1914  case GEOS_MULTIPOLYGON:
1915  case GEOS_LINESTRING:
1916  case GEOS_LINEARRING:
1917  case GEOS_POINT:
1918  lwerror("lwtin_from_geos: invalid geometry type for tin: %d", type);
1919  break;
1920 
1921  default:
1922  lwerror("GEOS2LWGEOM: unknown geometry type: %d", type);
1923  return NULL;
1924  }
1925 
1926  /* shouldn't get here */
1927  return NULL;
1928 }
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: