PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ lwgeom_buildarea()

LWGEOM* lwgeom_buildarea ( const LWGEOM geom)

Take a geometry and return an areal geometry (Polygon or MultiPolygon).

Actually a wrapper around GEOSpolygonize, transforming the resulting collection into a valid polygon Geometry.

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

1388 {
1389  LWGEOM* result;
1390  int32_t srid = RESULT_SRID(geom);
1391  uint8_t is3d = FLAGS_GET_Z(geom->flags);
1392  GEOSGeometry *g1, *g3;
1393 
1394  if (srid == SRID_INVALID) return NULL;
1395 
1396  /* Can't build an area from an empty! */
1397  if (lwgeom_is_empty(geom)) return (LWGEOM*)lwpoly_construct_empty(srid, is3d, 0);
1398 
1399  initGEOS(lwnotice, lwgeom_geos_error);
1400 
1401  if (!(g1 = LWGEOM2GEOS(geom, AUTOFIX))) GEOS_FAIL();
1402 
1403 #if POSTGIS_GEOS_VERSION < 30800
1404  g3 = LWGEOM_GEOS_buildArea(g1);
1405 #else
1406  g3 = GEOSBuildArea(g1);
1407 #endif
1408 
1409  if (!g3) GEOS_FREE_AND_FAIL(g1);
1410  GEOSSetSRID(g3, srid);
1411 
1412  /* If no geometries are in result collection, return NULL */
1413  if (GEOSGetNumGeometries(g3) == 0)
1414  {
1415  GEOS_FREE(g1);
1416  return NULL;
1417  }
1418 
1419  if (!(result = GEOS2LWGEOM(g3, is3d)))
1420  GEOS_FREE_AND_FAIL(g1, g3);
1421 
1422  GEOS_FREE(g1, g3);
1423 
1424  return result;
1425 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
#define GEOS_FREE(...)
#define AUTOFIX
#define RESULT_SRID(...)
#define GEOS_FAIL()
#define GEOS_FREE_AND_FAIL(...)
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, uint8_t want3d)
void lwgeom_geos_error(const char *fmt,...)
#define SRID_INVALID
Definition: liblwgeom.h:234
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:180
LWPOLY * lwpoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwpoly.c:161
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwinline.h:203
lwflags_t flags
Definition: liblwgeom.h:476

References AUTOFIX, LWGEOM::flags, FLAGS_GET_Z, GEOS2LWGEOM(), GEOS_FAIL, GEOS_FREE, GEOS_FREE_AND_FAIL, LWGEOM2GEOS(), lwgeom_geos_error(), lwgeom_is_empty(), lwnotice(), lwpoly_construct_empty(), result, RESULT_SRID, and SRID_INVALID.

Referenced by _lwt_FaceByEdges(), buildarea1(), buildarea2(), buildarea3(), buildarea4(), buildarea4b(), buildarea5(), buildarea6(), buildarea7(), and ST_BuildArea().

Here is the call graph for this function:
Here is the caller graph for this function: