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

References LWGEOM::flags, FLAGS_GET_Z, geos_clean(), geos_clean_and_fail(), get_result_srid(), input_lwgeom_to_geos(), LWGEOM_GEOS_buildArea(), lwgeom_geos_error(), lwgeom_is_empty(), lwnotice(), lwpoly_construct_empty(), output_geos_as_lwgeom(), and SRID_INVALID.

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

1189 {
1190  LWGEOM* result;
1191  int32_t srid = get_result_srid(geom, NULL, __func__);
1192  uint8_t is3d = FLAGS_GET_Z(geom->flags);
1193  GEOSGeometry *g1, *g3;
1195  if (srid == SRID_INVALID) return NULL;
1197  /* Can't build an area from an empty! */
1198  if (lwgeom_is_empty(geom)) return (LWGEOM*)lwpoly_construct_empty(srid, is3d, 0);
1200  initGEOS(lwnotice, lwgeom_geos_error);
1202  if (!input_lwgeom_to_geos(&g1, geom, __func__)) return NULL;
1204  g3 = LWGEOM_GEOS_buildArea(g1);
1206  if (!g3) return geos_clean_and_fail(g1, NULL, NULL, __func__);
1208  /* If no geometries are in result collection, return NULL */
1209  if (GEOSGetNumGeometries(g3) == 0) return geos_clean_and_fail(g1, NULL, NULL, __func__);
1211  if (!output_geos_as_lwgeom(&g3, &result, srid, is3d, __func__))
1212  return geos_clean_and_fail(g1, NULL, g3, __func__);
1214  geos_clean(g1, NULL, g3);
1216  return result;
1217 }
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
uint8_t flags
Definition: liblwgeom.h:399
static LWGEOM * geos_clean_and_fail(GEOSGeometry *g1, GEOSGeometry *g2, GEOSGeometry *g3, const char *funcname)
static uint8_t output_geos_as_lwgeom(GEOSGeometry **g, LWGEOM **geom, const int32_t srid, const uint8_t is3d, const char *funcname)
void lwgeom_geos_error(const char *fmt,...)
static void geos_clean(GEOSGeometry *g1, GEOSGeometry *g2, GEOSGeometry *g3)
Definition: liblwgeom.h:191
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:139
static uint8_t input_lwgeom_to_geos(GEOSGeometry **g, const LWGEOM *geom, const char *funcname)
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:161
static int32_t get_result_srid(const LWGEOM *geom1, const LWGEOM *geom2, const char *funcname)
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: