Adds a polygon to the topology.
The boundary of the given polygon will snap to existing nodes or edges within given tolerance. Existing edges or faces may be split by the boundary of the polygon.
5875{
5876 uint32_t i;
5877 *nfaces = -1;
5878 int num;
5880 uint64_t nfacesinbox;
5881 uint64_t j;
5884 const GEOSPreparedGeometry *ppoly;
5885 GEOSGeometry *polyg;
5886
5887
5889 {
5890 *nfaces = 0;
5891 return NULL;
5892 }
5893
5894
5896 LWDEBUGF(1,
"Working tolerance:%.15g", tol);
5897
5898
5899 for ( i=0; i<poly->
nrings; ++i )
5900 {
5904 int nedges;
5905
5909 if ( nedges < 0 ) {
5910
5912 lwerror(
"Error adding ring %d of polygon", i);
5913 return NULL;
5914 }
5917 }
5918
5919
5920
5921
5922
5927 if (nfacesinbox == UINT64_MAX)
5928 {
5931 return NULL;
5932 }
5933
5934 num = 0;
5935 if ( nfacesinbox )
5936 {
5938 if ( ! polyg )
5939 {
5942 return NULL;
5943 }
5944 ppoly = GEOSPrepare(polyg);
5946 for ( j=0; j<nfacesinbox; ++j )
5947 {
5950 GEOSGeometry *fgg, *sp;
5952
5953
5955 if ( ! fg )
5956 {
5958 GEOSPreparedGeom_destroy(ppoly);
5959 GEOSGeom_destroy(polyg);
5963 return NULL;
5964 }
5965
5968 if ( ! fgg )
5969 {
5970 GEOSPreparedGeom_destroy(ppoly);
5971 GEOSGeom_destroy(polyg);
5974 return NULL;
5975 }
5976 sp = GEOSPointOnSurface(fgg);
5977 GEOSGeom_destroy(fgg);
5978 if ( ! sp )
5979 {
5980 GEOSPreparedGeom_destroy(ppoly);
5981 GEOSGeom_destroy(polyg);
5984 return NULL;
5985 }
5986 covers = GEOSPreparedCovers( ppoly, sp );
5987 GEOSGeom_destroy(sp);
5989 {
5990 GEOSPreparedGeom_destroy(ppoly);
5991 GEOSGeom_destroy(polyg);
5994 return NULL;
5995 }
5997 {
5998 continue;
5999 }
6000
6001
6003 }
6004 GEOSPreparedGeom_destroy(ppoly);
6005 GEOSGeom_destroy(polyg);
6007 }
6008
6009
6010
6011 *nfaces = num;
6012
6013 return ids;
6014}
void gbox_expand(GBOX *g, double d)
Move the box minimums down and the maximums up by the distance provided.
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
void lwgeom_free(LWGEOM *geom)
void * lwalloc(size_t size)
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
const GBOX * lwgeom_get_bbox(const LWGEOM *lwgeom)
Get a non-empty geometry bounding box, computing and caching it if not already there.
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
void lwline_free(LWLINE *line)
int lwpoly_is_empty(const LWPOLY *poly)
POINTARRAY * ptarray_clone(const POINTARRAY *ptarray)
Clone a POINTARRAY object.
LWT_INT64 LWT_ELEMID
Identifier of topology element.
#define LWDEBUGF(level, msg,...)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
LWT_ELEMID * lwt_AddLine(LWT_TOPOLOGY *topo, LWLINE *line, double tol, int *nedges)
Adds a linestring to the topology.
static LWT_ISO_FACE * lwt_be_getFaceWithinBox2D(const LWT_TOPOLOGY *topo, const GBOX *box, uint64_t *numelems, int fields, uint64_t limit)
static void _lwt_release_faces(LWT_ISO_FACE *faces, int num_faces)
#define _LWT_MINTOLERANCE(topo, geom)
const char * lwt_be_lastErrorMessage(const LWT_BE_IFACE *be)
LWGEOM * lwt_GetFaceGeometry(LWT_TOPOLOGY *topo, LWT_ELEMID faceid)
Return the geometry of a face.
Datum covers(PG_FUNCTION_ARGS)
const LWT_BE_IFACE * be_iface