PostGIS  2.5.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 962 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().

963 {
964  LWGEOM *split;
965  LWCOLLECTION *split_col;
966  int i;
967 
968  /* Get edge */
969  i = 1;
970  LWDEBUG(1, "calling lwt_be_getEdgeById");
971  *oldedge = lwt_be_getEdgeById(topo, &edge, &i, LWT_COL_EDGE_ALL);
972  LWDEBUGF(1, "lwt_be_getEdgeById returned %p", *oldedge);
973  if ( ! *oldedge )
974  {
975  LWDEBUGF(1, "lwt_be_getEdgeById returned NULL and set i=%d", i);
976  if ( i == -1 )
977  {
978  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
979  return NULL;
980  }
981  else if ( i == 0 )
982  {
983  lwerror("SQL/MM Spatial exception - non-existent edge");
984  return NULL;
985  }
986  else
987  {
988  lwerror("Backend coding error: getEdgeById callback returned NULL "
989  "but numelements output parameter has value %d "
990  "(expected 0 or 1)", i);
991  return NULL;
992  }
993  }
994 
995 
996  /*
997  * - check if a coincident node already exists
998  */
999  if ( ! skipISOChecks )
1000  {
1001  LWDEBUG(1, "calling lwt_be_ExistsCoincidentNode");
1002  if ( lwt_be_ExistsCoincidentNode(topo, pt) ) /*x*/
1003  {
1004  LWDEBUG(1, "lwt_be_ExistsCoincidentNode returned");
1005  _lwt_release_edges(*oldedge, 1);
1006  lwerror("SQL/MM Spatial exception - coincident node");
1007  return NULL;
1008  }
1009  LWDEBUG(1, "lwt_be_ExistsCoincidentNode returned");
1010  }
1011 
1012  /* Split edge */
1013  split = lwgeom_split((LWGEOM*)(*oldedge)->geom, (LWGEOM*)pt);
1014  if ( ! split )
1015  {
1016  _lwt_release_edges(*oldedge, 1);
1017  lwerror("could not split edge by point ?");
1018  return NULL;
1019  }
1020  split_col = lwgeom_as_lwcollection(split);
1021  if ( ! split_col ) {
1022  _lwt_release_edges(*oldedge, 1);
1023  lwgeom_free(split);
1024  lwerror("lwgeom_as_lwcollection returned NULL");
1025  return NULL;
1026  }
1027  if (split_col->ngeoms < 2) {
1028  _lwt_release_edges(*oldedge, 1);
1029  lwgeom_free(split);
1030  lwerror("SQL/MM Spatial exception - point not on edge");
1031  return NULL;
1032  }
1033 
1034 #if 0
1035  {
1036  size_t sz;
1037  char *wkt = lwgeom_to_wkt((LWGEOM*)split_col, WKT_EXTENDED, 2, &sz);
1038  LWDEBUGF(1, "returning split col: %s", wkt);
1039  lwfree(wkt);
1040  }
1041 #endif
1042  return split_col;
1043 }
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:675
void lwfree(void *mem)
Definition: lwutil.c:244
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#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
uint32_t ngeoms
Definition: liblwgeom.h:509
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:2076
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:224
static void _lwt_release_edges(LWT_ISO_EDGE *edges, int num_edges)
Definition: lwgeom_topo.c:457
#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:190
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: