PostGIS  2.2.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 954 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().

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