PostGIS  2.4.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 1411 of file liblwgeom/lwgeom_geos.c.

References LWGEOM::flags, FLAGS_GET_Z, GEOS2LWGEOM(), LWDEBUG, LWDEBUGF, lwerror(), LWGEOM2GEOS(), LWGEOM_GEOS_buildArea(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwgeom_is_empty(), lwnotice(), lwpoly_construct_empty(), and LWGEOM::srid.

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

1412 {
1413  GEOSGeometry* geos_in;
1414  GEOSGeometry* geos_out;
1415  LWGEOM* geom_out;
1416  int SRID = (int)(geom->srid);
1417  int is3d = FLAGS_GET_Z(geom->flags);
1418 
1419  /* Can't build an area from an empty! */
1420  if ( lwgeom_is_empty(geom) )
1421  {
1422  return (LWGEOM*)lwpoly_construct_empty(SRID, is3d, 0);
1423  }
1424 
1425  LWDEBUG(3, "buildarea called");
1426 
1427  LWDEBUGF(3, "ST_BuildArea got geom @ %p", geom);
1428 
1429  initGEOS(lwnotice, lwgeom_geos_error);
1430 
1431  geos_in = LWGEOM2GEOS(geom, 0);
1432 
1433  if ( 0 == geos_in ) /* exception thrown at construction */
1434  {
1435  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
1436  return NULL;
1437  }
1438  geos_out = LWGEOM_GEOS_buildArea(geos_in);
1439  GEOSGeom_destroy(geos_in);
1440 
1441  if ( ! geos_out ) /* exception thrown.. */
1442  {
1443  lwerror("LWGEOM_GEOS_buildArea: %s", lwgeom_geos_errmsg);
1444  return NULL;
1445  }
1446 
1447  /* If no geometries are in result collection, return NULL */
1448  if ( GEOSGetNumGeometries(geos_out) == 0 )
1449  {
1450  GEOSGeom_destroy(geos_out);
1451  return NULL;
1452  }
1453 
1454  geom_out = GEOS2LWGEOM(geos_out, is3d);
1455  GEOSGeom_destroy(geos_out);
1456 
1457 #if PARANOIA_LEVEL > 0
1458  if ( geom_out == NULL )
1459  {
1460  lwerror("%s [%s] serialization error", __FILE__, __LINE__);
1461  return NULL;
1462  }
1463 
1464 #endif
1465 
1466  return geom_out;
1467 }
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
uint8_t flags
Definition: liblwgeom.h:397
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
int32_t srid
Definition: liblwgeom.h:399
void lwgeom_geos_error(const char *fmt,...)
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, int autofix)
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:161
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, char want3d)
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:1346
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
GEOSGeometry * LWGEOM_GEOS_buildArea(const GEOSGeometry *geom_in)
Here is the call graph for this function:
Here is the caller graph for this function: