PostGIS  2.5.0beta2dev-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 1232 of file liblwgeom/lwgeom_geos.c.

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

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

1233 {
1234  LWGEOM* result;
1235  int32_t srid = RESULT_SRID(geom);
1236  uint8_t is3d = FLAGS_GET_Z(geom->flags);
1237  GEOSGeometry *g1, *g3;
1239  if (srid == SRID_INVALID) return NULL;
1241  /* Can't build an area from an empty! */
1242  if (lwgeom_is_empty(geom)) return (LWGEOM*)lwpoly_construct_empty(srid, is3d, 0);
1244  initGEOS(lwnotice, lwgeom_geos_error);
1246  if (!(g1 = LWGEOM2GEOS(geom, AUTOFIX))) GEOS_FAIL();
1248  g3 = LWGEOM_GEOS_buildArea(g1);
1250  if (!g3) GEOS_FREE_AND_FAIL(g1);
1251  GEOSSetSRID(g3, srid);
1253  /* If no geometries are in result collection, return NULL */
1254  if (GEOSGetNumGeometries(g3) == 0)
1255  {
1256  GEOS_FREE(g1);
1257  return NULL;
1258  }
1260  if (!(result = GEOS2LWGEOM(g3, is3d)))
1261  GEOS_FREE_AND_FAIL(g1, g3);
1263  GEOS_FREE(g1, g3);
1265  return result;
1266 }
#define GEOS_FAIL()
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, uint8_t want3d)
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
uint8_t flags
Definition: liblwgeom.h:399
#define GEOS_FREE_AND_FAIL(...)
#define GEOS_FREE(...)
#define RESULT_SRID(...)
#define AUTOFIX
void lwgeom_geos_error(const char *fmt,...)
Definition: liblwgeom.h:191
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:139
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:161
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1393
unsigned char uint8_t
Definition: uthash.h:79
GEOSGeometry * LWGEOM_GEOS_buildArea(const GEOSGeometry *geom_in)
Here is the call graph for this function:
Here is the caller graph for this function: