PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ _lwt_EdgeSplit()

static LWCOLLECTION * _lwt_EdgeSplit ( LWT_TOPOLOGY topo,
LWT_ELEMID  edge,
LWPOINT pt,
int  skipISOChecks,
LWT_ISO_EDGE **  oldedge 
)
static

Definition at line 1083 of file lwgeom_topo.c.

1084{
1085 LWGEOM *split;
1086 LWCOLLECTION *split_col;
1087 uint64_t i;
1088
1089 /* Get edge */
1090 i = 1;
1091 LWDEBUG(1, "calling lwt_be_getEdgeById");
1092 *oldedge = lwt_be_getEdgeById(topo, &edge, &i, LWT_COL_EDGE_ALL);
1093 LWDEBUGF(1, "lwt_be_getEdgeById returned %p", *oldedge);
1094 LWDEBUGG(2, lwline_as_lwgeom(oldedge[0]->geom), "Edge to be split");
1095 if ( ! *oldedge )
1096 {
1097 LWDEBUGF(1, "lwt_be_getEdgeById returned NULL and set i=%llu", i);
1098 if (i == UINT64_MAX)
1099 {
1101 return NULL;
1102 }
1103 else if ( i == 0 )
1104 {
1105 lwerror("SQL/MM Spatial exception - non-existent edge");
1106 return NULL;
1107 }
1108 else
1109 {
1110 lwerror("Backend coding error: getEdgeById callback returned NULL "
1111 "but numelements output parameter has value %" PRIu64
1112 "(expected 0 or 1)", i);
1113 return NULL;
1114 }
1115 }
1116
1117
1118 /*
1119 * - check if a coincident node already exists
1120 */
1121 if ( ! skipISOChecks )
1122 {
1123 LWDEBUG(1, "calling lwt_be_ExistsCoincidentNode");
1124 if ( lwt_be_ExistsCoincidentNode(topo, pt) ) /*x*/
1125 {
1126 LWDEBUG(1, "lwt_be_ExistsCoincidentNode returned");
1127 _lwt_release_edges(*oldedge, 1);
1128 lwerror("SQL/MM Spatial exception - coincident node");
1129 return NULL;
1130 }
1131 LWDEBUG(1, "lwt_be_ExistsCoincidentNode returned");
1132 }
1133
1134 /* Split edge */
1135 split = lwgeom_split((LWGEOM*)(*oldedge)->geom, (LWGEOM*)pt);
1136 if ( ! split )
1137 {
1138 _lwt_release_edges(*oldedge, 1);
1139 lwerror("could not split edge by point ?");
1140 return NULL;
1141 }
1142 split_col = lwgeom_as_lwcollection(split);
1143 if ( ! split_col ) {
1144 _lwt_release_edges(*oldedge, 1);
1145 lwgeom_free(split);
1146 lwerror("lwgeom_as_lwcollection returned NULL");
1147 return NULL;
1148 }
1149 if (split_col->ngeoms < 2) {
1150 LWDEBUGG(1, lwpoint_as_lwgeom(pt), "Unable to split edge by point");
1151 _lwt_release_edges(*oldedge, 1);
1152 lwgeom_free(split);
1153 lwerror("SQL/MM Spatial exception - point not on edge");
1154 return NULL;
1155 }
1156
1157#if POSTGIS_DEBUG_LEVEL > 1
1158 {
1159 size_t sz;
1160 char *wkt = lwgeom_to_wkt((LWGEOM*)split_col, WKT_EXTENDED, 2, &sz);
1161 LWDEBUGF(1, "returning split col: %s", wkt);
1162 lwfree(wkt);
1163 }
1164#endif
1165 return split_col;
1166}
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition lwgeom.c:372
LWGEOM * lwgeom_split(const LWGEOM *lwgeom_in, const LWGEOM *blade_in)
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition lwgeom.c:261
#define WKT_EXTENDED
Definition liblwgeom.h:2221
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition lwout_wkt.c:708
void lwfree(void *mem)
Definition lwutil.c:248
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition lwgeom.c:367
#define LWT_COL_EDGE_ALL
#define PGTOPO_BE_ERROR()
#define LWDEBUG(level, msg)
Definition lwgeom_log.h:101
#define LWDEBUGF(level, msg,...)
Definition lwgeom_log.h:106
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
#define LWDEBUGG(level, geom, msg)
Definition lwgeom_log.h:111
LWT_ELEMID lwt_be_ExistsCoincidentNode(LWT_TOPOLOGY *topo, const LWPOINT *pt)
LWT_ISO_EDGE * lwt_be_getEdgeById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields)
void _lwt_release_edges(LWT_ISO_EDGE *edges, int num_edges)
uint32_t ngeoms
Definition liblwgeom.h:580

References _lwt_release_edges(), LWDEBUG, LWDEBUGF, LWDEBUGG, lwerror(), lwfree(), lwgeom_as_lwcollection(), lwgeom_free(), lwgeom_split(), lwgeom_to_wkt(), lwline_as_lwgeom(), lwpoint_as_lwgeom(), lwt_be_ExistsCoincidentNode(), lwt_be_getEdgeById(), LWT_COL_EDGE_ALL, LWCOLLECTION::ngeoms, PGTOPO_BE_ERROR, and WKT_EXTENDED.

Referenced by lwt_ModEdgeSplit(), and lwt_NewEdgesSplit().

Here is the call graph for this function:
Here is the caller graph for this function: