PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ _lwt_EdgeSplit()

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

Definition at line 966 of file lwgeom_topo.c.

967 {
968  LWGEOM *split;
969  LWCOLLECTION *split_col;
970  uint64_t i;
971 
972  /* Get edge */
973  i = 1;
974  LWDEBUG(1, "calling lwt_be_getEdgeById");
975  *oldedge = lwt_be_getEdgeById(topo, &edge, &i, LWT_COL_EDGE_ALL);
976  LWDEBUGF(1, "lwt_be_getEdgeById returned %p", *oldedge);
977  LWDEBUGG(2, lwline_as_lwgeom(oldedge[0]->geom), "Edge to be split");
978  if ( ! *oldedge )
979  {
980  LWDEBUGF(1, "lwt_be_getEdgeById returned NULL and set i=%llu", i);
981  if (i == UINT64_MAX)
982  {
983  PGTOPO_BE_ERROR();
984  return NULL;
985  }
986  else if ( i == 0 )
987  {
988  lwerror("SQL/MM Spatial exception - non-existent edge");
989  return NULL;
990  }
991  else
992  {
993  lwerror("Backend coding error: getEdgeById callback returned NULL "
994  "but numelements output parameter has value %" PRIu64
995  "(expected 0 or 1)", i);
996  return NULL;
997  }
998  }
999 
1000 
1001  /*
1002  * - check if a coincident node already exists
1003  */
1004  if ( ! skipISOChecks )
1005  {
1006  LWDEBUG(1, "calling lwt_be_ExistsCoincidentNode");
1007  if ( lwt_be_ExistsCoincidentNode(topo, pt) ) /*x*/
1008  {
1009  LWDEBUG(1, "lwt_be_ExistsCoincidentNode returned");
1010  _lwt_release_edges(*oldedge, 1);
1011  lwerror("SQL/MM Spatial exception - coincident node");
1012  return NULL;
1013  }
1014  LWDEBUG(1, "lwt_be_ExistsCoincidentNode returned");
1015  }
1016 
1017  /* Split edge */
1018  split = lwgeom_split((LWGEOM*)(*oldedge)->geom, (LWGEOM*)pt);
1019  if ( ! split )
1020  {
1021  _lwt_release_edges(*oldedge, 1);
1022  lwerror("could not split edge by point ?");
1023  return NULL;
1024  }
1025  split_col = lwgeom_as_lwcollection(split);
1026  if ( ! split_col ) {
1027  _lwt_release_edges(*oldedge, 1);
1028  lwgeom_free(split);
1029  lwerror("lwgeom_as_lwcollection returned NULL");
1030  return NULL;
1031  }
1032  if (split_col->ngeoms < 2) {
1033  LWDEBUGG(1, lwpoint_as_lwgeom(pt), "Unable to split edge by point");
1034  _lwt_release_edges(*oldedge, 1);
1035  lwgeom_free(split);
1036  lwerror("SQL/MM Spatial exception - point not on edge");
1037  return NULL;
1038  }
1039 
1040 #if POSTGIS_DEBUG_LEVEL > 1
1041  {
1042  size_t sz;
1043  char *wkt = lwgeom_to_wkt((LWGEOM*)split_col, WKT_EXTENDED, 2, &sz);
1044  LWDEBUGF(1, "returning split col: %s", wkt);
1045  lwfree(wkt);
1046  }
1047 #endif
1048  return split_col;
1049 }
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:339
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1218
LWGEOM * lwgeom_split(const LWGEOM *lwgeom_in, const LWGEOM *blade_in)
#define WKT_EXTENDED
Definition: liblwgeom.h:2218
void lwfree(void *mem)
Definition: lwutil.c:248
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:344
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:708
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:233
#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)
Definition: lwgeom_topo.c:379
LWT_ISO_EDGE * lwt_be_getEdgeById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields)
Definition: lwgeom_topo.c:215
void _lwt_release_edges(LWT_ISO_EDGE *edges, int num_edges)
Definition: lwgeom_topo.c:460
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: