7147 uint64_t num, numedges = 0, numnodes = 0;
7148 int num_new_edges = 0;
7152 int input_was_closed = 0;
7163 input_was_closed = 1;
7165 LWDEBUGF(1,
"Input line is closed, original point is %g,%g", originalStartPoint.
x, originalStartPoint.
y);
7172 LWDEBUGF(1,
"Working tolerance:%.15g", tol);
7180 LWDEBUGG(1, tmp,
"Repeated-point removed");
7181 }}
else tmp=(
LWGEOM*)line;
7186 if ( ! noded )
return NULL;
7193 LWDEBUGF(1,
"BOX expanded by %g is %.15g %.15g, %.15g %.15g",
7197 int nearbyindex = 0;
7198 int nearbycount = 0;
7202 if (numedges == UINT64_MAX)
7208 LWDEBUGF(1,
"Line has %u points, its bbox intersects %llu edges bboxes",
7209 line->points->npoints, numedges);
7215 nearbycount += numedges;
7217 for (i=0; i<numedges; ++i)
7225 if ( 0 == GEOSDistanceIndexed(edge_g, noded_g, &dist) ) {
7226 GEOSGeom_destroy(edge_g);
7227 GEOSGeom_destroy(noded_g);
7232 GEOSGeom_destroy(edge_g);
7233 if ( dist && dist >= tol )
continue;
7234 nearby[nearbyindex++] = g;
7236 LWDEBUGF(1,
"Found %d edges closer than tolerance (%g)", nearbyindex, tol);
7237 GEOSGeom_destroy(noded_g);
7239 int nearbyedgecount = nearbyindex;
7246 if (numnodes == UINT64_MAX)
7252 LWDEBUGF(1,
"Line bbox intersects %llu nodes bboxes", numnodes);
7256 nearbycount = nearbyedgecount + numnodes;
7263 for (i=0; i<numnodes; ++i)
7270 if ( dist && dist >= tol )
7275 nearby[nearbyindex++] = g;
7278 LWDEBUGF(1,
"Found %d isolated nodes closer than tolerance (%g)", nn, tol);
7280 int nearbynodecount = nearbyindex - nearbyedgecount;
7281 nearbycount = nearbyindex;
7283 LWDEBUGF(1,
"Number of nearby elements is %d", nearbycount);
7292 NULL, nearbycount, nearby);
7295 LWDEBUGG(1, elems,
"Collected nearby elements");
7300 LWDEBUGG(1, noded,
"Elements-snapped");
7301 if ( input_was_closed )
7308 LWDEBUGF(1,
"Closed input line start point after snap %g,%g", originalStartPoint.
x, originalStartPoint.
y);
7323 LWDEBUGG(1, noded,
"Unary-unioned");
7327 if ( nearbyedgecount )
7333 LWDEBUGF(1,
"Line intersects %d edges", nearbyedgecount);
7336 NULL, nearbyedgecount, nearby);
7338 LWDEBUGG(1, iedges,
"Collected edges");
7340 LWDEBUGF(1,
"Diffing noded, with srid=%d "
7341 "and intersecting edges, with srid=%d",
7346 LWDEBUGF(1,
"Intersecting noded, with srid=%d "
7347 "and intersecting edges, with srid=%d",
7367 LWDEBUG(1,
"Linemerging intersection");
7377 LWDEBUG(1,
"Unioning difference and (linemerged) intersection");
7379 LWDEBUGG(1, noded,
"Diff-Xset Unioned");
7386 if ( input_was_closed )
7398 LWDEBUGG(1, noded,
"Diff-Xset Unioned cannot be scrolled");
7411 if ( nearbyedgecount )
7413 nearbycount += nearbyedgecount * 2;
7415 for (
int i=0; i<nearbyedgecount; i++)
7427 if ( nearbynodecount )
7430 NULL, nearbynodecount,
7431 nearby + nearbyedgecount);
7443 LWDEBUG(1,
"Freeing up nearby elements");
7446 if ( nearby )
lwfree(nearby);
7450 LWDEBUGG(2, noded,
"Finally-noded");
7456 LWDEBUG(1,
"Noded line was a collection");
7462 LWDEBUG(1,
"Noded line was a single geom");
7463 geomsbuf[0] = noded;
7468 LWDEBUGF(1,
"Line was split into %d edges", ngeoms);
7476 for ( i=0; i<ngeoms; ++i )
7483 #if POSTGIS_DEBUG_LEVEL > 0
7487 LWDEBUGF(1,
"Component %llu of split line is: %s", i, wkt1);
7494 num_new_edges += edgeNewEdges;
7496 if ( forward == -1 )
7502 " (forward ? %d), reported to create %d new edges (total new edges: %d)",
7503 id, forward, edgeNewEdges, num_new_edges);
7511 if ( maxNewEdges >= 0 && num_new_edges > maxNewEdges )
7515 lwerror(
"Adding line to topology requires creating more edges than the requested limit of %d", maxNewEdges);
7521 LWDEBUGF(1,
"Component %llu of split line collapsed", i);
7526 i, forward ?
"forward" :
"backward",
id);
7527 ids[num++] = forward ? id : -id;
7530 LWDEBUGG(2, noded,
"Noded before free");
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)
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
LWGEOM * lwgeom_node(const LWGEOM *lwgeom_in)
void lwgeom_free(LWGEOM *geom)
LWGEOM * lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2)
LWGEOM * lwgeom_difference(const LWGEOM *geom1, const LWGEOM *geom2)
void * lwrealloc(void *mem, size_t size)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
LWGEOM * lwgeom_unaryunion(const LWGEOM *geom1)
void lwcollection_release(LWCOLLECTION *lwcollection)
double lwgeom_mindistance2d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing min distance calculation.
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
const GBOX * lwgeom_get_bbox(const LWGEOM *lwgeom)
Get a non-empty geometry bounding box, computing and caching it if not already there.
LWGEOM * lwgeom_linemerge(const LWGEOM *geom1)
void * lwalloc(size_t size)
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
LWGEOM * lwgeom_union(const LWGEOM *geom1, const LWGEOM *geom2)
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
LWGEOM * lwline_remove_repeated_points(const LWLINE *in, double tolerance)
int lwline_is_empty(const LWLINE *line)
#define LW_ON_INTERRUPT(x)
int lwline_is_closed(const LWLINE *line)
int ptarray_scroll_in_place(POINTARRAY *pa, const POINT4D *newbase)
LWT_INT64 LWT_ELEMID
Identifier of topology element.
#define PGTOPO_BE_ERROR()
#define LWDEBUG(level, msg)
#define LWDEBUGF(level, msg,...)
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
#define LWDEBUGG(level, geom, msg)
static LWGEOM * _lwt_split_by_nodes(const LWGEOM *g, const LWGEOM *nodes)
static void _lwt_release_nodes(LWT_ISO_NODE *nodes, int num_nodes)
LWT_ISO_EDGE * lwt_be_getEdgeWithinBox2D(const LWT_TOPOLOGY *topo, const GBOX *box, uint64_t *numelems, int fields, uint64_t limit)
void _lwt_release_edges(LWT_ISO_EDGE *edges, int num_edges)
static LWT_ISO_NODE * lwt_be_getNodeWithinBox2D(const LWT_TOPOLOGY *topo, const GBOX *box, uint64_t *numelems, int fields, uint64_t limit)
#define _LWT_MINTOLERANCE(topo, geom)
static LWGEOM * _lwt_toposnap(LWGEOM *src, LWGEOM *tgt, double tol)
static LWT_ELEMID _lwt_AddLineEdge(LWT_TOPOLOGY *topo, LWLINE *edge, double tol, int handleFaceSplit, int *forward, int *numNewEdges)
LWT_ELEMID containing_face