PostGIS  2.3.8dev-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 950 of file lwgeom_topo.c.

References _lwt_release_edges(), LWT_TOPOLOGY_T::be_iface, LWDEBUG, LWDEBUGF, lwerror(), lwfree(), lwgeom_as_lwcollection(), lwgeom_free(), lwgeom_split(), lwgeom_to_wkt(), lwt_be_ExistsCoincidentNode(), lwt_be_getEdgeById(), lwt_be_lastErrorMessage(), LWT_COL_EDGE_ALL, LWCOLLECTION::ngeoms, and WKT_EXTENDED.

Referenced by lwt_ModEdgeSplit(), and lwt_NewEdgesSplit().

951 {
952  LWGEOM *split;
953  LWCOLLECTION *split_col;
954  int i;
955 
956  /* Get edge */
957  i = 1;
958  LWDEBUG(1, "calling lwt_be_getEdgeById");
959  *oldedge = lwt_be_getEdgeById(topo, &edge, &i, LWT_COL_EDGE_ALL);
960  LWDEBUGF(1, "lwt_be_getEdgeById returned %p", *oldedge);
961  if ( ! *oldedge )
962  {
963  LWDEBUGF(1, "lwt_be_getEdgeById returned NULL and set i=%d", i);
964  if ( i == -1 )
965  {
966  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
967  return NULL;
968  }
969  else if ( i == 0 )
970  {
971  lwerror("SQL/MM Spatial exception - non-existent edge");
972  return NULL;
973  }
974  else
975  {
976  lwerror("Backend coding error: getEdgeById callback returned NULL "
977  "but numelements output parameter has value %d "
978  "(expected 0 or 1)", i);
979  return NULL;
980  }
981  }
982 
983 
984  /*
985  * - check if a coincident node already exists
986  */
987  if ( ! skipISOChecks )
988  {
989  LWDEBUG(1, "calling lwt_be_ExistsCoincidentNode");
990  if ( lwt_be_ExistsCoincidentNode(topo, pt) ) /*x*/
991  {
992  LWDEBUG(1, "lwt_be_ExistsCoincidentNode returned");
993  _lwt_release_edges(*oldedge, 1);
994  lwerror("SQL/MM Spatial exception - coincident node");
995  return NULL;
996  }
997  LWDEBUG(1, "lwt_be_ExistsCoincidentNode returned");
998  }
999 
1000  /* Split edge */
1001  split = lwgeom_split((LWGEOM*)(*oldedge)->geom, (LWGEOM*)pt);
1002  if ( ! split )
1003  {
1004  _lwt_release_edges(*oldedge, 1);
1005  lwerror("could not split edge by point ?");
1006  return NULL;
1007  }
1008  split_col = lwgeom_as_lwcollection(split);
1009  if ( ! split_col ) {
1010  _lwt_release_edges(*oldedge, 1);
1011  lwgeom_free(split);
1012  lwerror("lwgeom_as_lwcollection returned NULL");
1013  return NULL;
1014  }
1015  if (split_col->ngeoms < 2) {
1016  _lwt_release_edges(*oldedge, 1);
1017  lwgeom_free(split);
1018  lwerror("SQL/MM Spatial exception - point not on edge");
1019  return NULL;
1020  }
1021 
1022 #if 0
1023  {
1024  size_t sz;
1025  char *wkt = lwgeom_to_wkt((LWGEOM*)split_col, WKT_EXTENDED, 2, &sz);
1026  LWDEBUGF(1, "returning split col: %s", wkt);
1027  lwfree(wkt);
1028  }
1029 #endif
1030  return split_col;
1031 }
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:669
void lwfree(void *mem)
Definition: lwutil.c:242
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
LWT_ISO_EDGE * lwt_be_getEdgeById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, int *numelems, int fields)
Definition: lwgeom_topo.c:225
const LWT_BE_IFACE * be_iface
int lwt_be_ExistsCoincidentNode(LWT_TOPOLOGY *topo, LWPOINT *pt)
Definition: lwgeom_topo.c:390
#define LWT_COL_EDGE_ALL
#define WKT_EXTENDED
Definition: liblwgeom.h:2057
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:156
static void _lwt_release_edges(LWT_ISO_EDGE *edges, int num_edges)
Definition: lwgeom_topo.c:467
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
const char * lwt_be_lastErrorMessage(const LWT_BE_IFACE *be)
Definition: lwgeom_topo.c:120
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
LWGEOM * lwgeom_split(const LWGEOM *lwgeom_in, const LWGEOM *blade_in)
Here is the call graph for this function:
Here is the caller graph for this function: