PostGIS  2.5.0dev-r@@SVN_REVISION@@
LWT_ELEMID lwt_ModEdgeSplit ( LWT_TOPOLOGY topo,
LWT_ELEMID  edge,
LWPOINT pt,
int  skipChecks 
)

Split an edge by a node, modifying the original edge and adding a new one.

For ST_ModEdgeSplit

Parameters
topothe topology to operate on
edgeidentifier of the edge to be split
ptgeometry of the new node
skipChecksif non-zero skips consistency checks (coincident node, point not on edge...)
Returns
the id of newly created node, or -1 on error (liblwgeom error handler will be invoked with error message)

Definition at line 1046 of file lwgeom_topo.c.

References _lwt_EdgeSplit(), _lwt_release_edges(), LWT_TOPOLOGY_T::be_iface, LWT_ISO_NODE::containing_face, LWT_ISO_EDGE::edge_id, LWT_ISO_EDGE::end_node, LWT_ISO_EDGE::face_left, LWT_ISO_EDGE::face_right, LWT_ISO_NODE::geom, LWT_ISO_EDGE::geom, LWCOLLECTION::geoms, lwcollection_free(), lwerror(), lwgeom_as_lwline(), lwt_be_getNextEdgeId(), lwt_be_insertEdges(), lwt_be_insertNodes(), lwt_be_lastErrorMessage(), lwt_be_updateEdges(), lwt_be_updateTopoGeomEdgeSplit(), LWT_COL_EDGE_EDGE_ID, LWT_COL_EDGE_END_NODE, LWT_COL_EDGE_GEOM, LWT_COL_EDGE_NEXT_LEFT, LWT_COL_EDGE_NEXT_RIGHT, LWT_COL_EDGE_START_NODE, LWT_ISO_EDGE::next_left, LWT_ISO_EDGE::next_right, LWT_ISO_NODE::node_id, LWGEOM::srid, LWCOLLECTION::srid, and LWT_ISO_EDGE::start_node.

Referenced by _lwt_AddPoint().

1048 {
1049  LWT_ISO_NODE node;
1050  LWT_ISO_EDGE* oldedge = NULL;
1051  LWCOLLECTION *split_col;
1052  const LWGEOM *oldedge_geom;
1053  const LWGEOM *newedge_geom;
1054  LWT_ISO_EDGE newedge1;
1055  LWT_ISO_EDGE seledge, updedge, excedge;
1056  int ret;
1057 
1058  split_col = _lwt_EdgeSplit( topo, edge, pt, skipISOChecks, &oldedge );
1059  if ( ! split_col ) return -1; /* should have raised an exception */
1060  oldedge_geom = split_col->geoms[0];
1061  newedge_geom = split_col->geoms[1];
1062  /* Make sure the SRID is set on the subgeom */
1063  ((LWGEOM*)oldedge_geom)->srid = split_col->srid;
1064  ((LWGEOM*)newedge_geom)->srid = split_col->srid;
1065 
1066  /* Add new node, getting new id back */
1067  node.node_id = -1;
1068  node.containing_face = -1; /* means not-isolated */
1069  node.geom = pt;
1070  if ( ! lwt_be_insertNodes(topo, &node, 1) )
1071  {
1072  _lwt_release_edges(oldedge, 1);
1073  lwcollection_free(split_col);
1074  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
1075  return -1;
1076  }
1077  if (node.node_id == -1) {
1078  /* should have been set by backend */
1079  _lwt_release_edges(oldedge, 1);
1080  lwcollection_free(split_col);
1081  lwerror("Backend coding error: "
1082  "insertNodes callback did not return node_id");
1083  return -1;
1084  }
1085 
1086  /* Insert the new edge */
1087  newedge1.edge_id = lwt_be_getNextEdgeId(topo);
1088  if ( newedge1.edge_id == -1 ) {
1089  _lwt_release_edges(oldedge, 1);
1090  lwcollection_free(split_col);
1091  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
1092  return -1;
1093  }
1094  newedge1.start_node = node.node_id;
1095  newedge1.end_node = oldedge->end_node;
1096  newedge1.face_left = oldedge->face_left;
1097  newedge1.face_right = oldedge->face_right;
1098  newedge1.next_left = oldedge->next_left == -oldedge->edge_id ?
1099  -newedge1.edge_id : oldedge->next_left;
1100  newedge1.next_right = -oldedge->edge_id;
1101  newedge1.geom = lwgeom_as_lwline(newedge_geom);
1102  /* lwgeom_split of a line should only return lines ... */
1103  if ( ! newedge1.geom ) {
1104  _lwt_release_edges(oldedge, 1);
1105  lwcollection_free(split_col);
1106  lwerror("first geometry in lwgeom_split output is not a line");
1107  return -1;
1108  }
1109  ret = lwt_be_insertEdges(topo, &newedge1, 1);
1110  if ( ret == -1 ) {
1111  _lwt_release_edges(oldedge, 1);
1112  lwcollection_free(split_col);
1113  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
1114  return -1;
1115  } else if ( ret == 0 ) {
1116  _lwt_release_edges(oldedge, 1);
1117  lwcollection_free(split_col);
1118  lwerror("Insertion of split edge failed (no reason)");
1119  return -1;
1120  }
1121 
1122  /* Update the old edge */
1123  updedge.geom = lwgeom_as_lwline(oldedge_geom);
1124  /* lwgeom_split of a line should only return lines ... */
1125  if ( ! updedge.geom ) {
1126  _lwt_release_edges(oldedge, 1);
1127  lwcollection_free(split_col);
1128  lwerror("second geometry in lwgeom_split output is not a line");
1129  return -1;
1130  }
1131  updedge.next_left = newedge1.edge_id;
1132  updedge.end_node = node.node_id;
1133  ret = lwt_be_updateEdges(topo,
1134  oldedge, LWT_COL_EDGE_EDGE_ID,
1136  NULL, 0);
1137  if ( ret == -1 ) {
1138  _lwt_release_edges(oldedge, 1);
1139  lwcollection_free(split_col);
1140  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
1141  return -1;
1142  } else if ( ret == 0 ) {
1143  _lwt_release_edges(oldedge, 1);
1144  lwcollection_free(split_col);
1145  lwerror("Edge being split (%d) disappeared during operations?", oldedge->edge_id);
1146  return -1;
1147  } else if ( ret > 1 ) {
1148  _lwt_release_edges(oldedge, 1);
1149  lwcollection_free(split_col);
1150  lwerror("More than a single edge found with id %d !", oldedge->edge_id);
1151  return -1;
1152  }
1153 
1154  /* Update all next edge references to match new layout (ST_ModEdgeSplit) */
1155 
1156  updedge.next_right = -newedge1.edge_id;
1157  excedge.edge_id = newedge1.edge_id;
1158  seledge.next_right = -oldedge->edge_id;
1159  seledge.start_node = oldedge->end_node;
1160  ret = lwt_be_updateEdges(topo,
1162  &updedge, LWT_COL_EDGE_NEXT_RIGHT,
1163  &excedge, LWT_COL_EDGE_EDGE_ID);
1164  if ( ret == -1 ) {
1165  _lwt_release_edges(oldedge, 1);
1166  lwcollection_free(split_col);
1167  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
1168  return -1;
1169  }
1170 
1171  updedge.next_left = -newedge1.edge_id;
1172  excedge.edge_id = newedge1.edge_id;
1173  seledge.next_left = -oldedge->edge_id;
1174  seledge.end_node = oldedge->end_node;
1175  ret = lwt_be_updateEdges(topo,
1177  &updedge, LWT_COL_EDGE_NEXT_LEFT,
1178  &excedge, LWT_COL_EDGE_EDGE_ID);
1179  if ( ret == -1 ) {
1180  _lwt_release_edges(oldedge, 1);
1181  lwcollection_free(split_col);
1182  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
1183  return -1;
1184  }
1185 
1186  /* Update TopoGeometries composition */
1187  ret = lwt_be_updateTopoGeomEdgeSplit(topo, oldedge->edge_id, newedge1.edge_id, -1);
1188  if ( ! ret ) {
1189  _lwt_release_edges(oldedge, 1);
1190  lwcollection_free(split_col);
1191  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
1192  return -1;
1193  }
1194 
1195  _lwt_release_edges(oldedge, 1);
1196  lwcollection_free(split_col);
1197 
1198  /* return new node id */
1199  return node.node_id;
1200 }
LWT_ELEMID face_left
LWT_ELEMID containing_face
LWPOINT * geom
int lwt_be_insertNodes(LWT_TOPOLOGY *topo, LWT_ISO_NODE *node, int numelems)
Definition: lwgeom_topo.c:195
#define LWT_COL_EDGE_START_NODE
LWLINE * geom
int32_t srid
Definition: liblwgeom.h:398
LWT_ELEMID next_left
static LWCOLLECTION * _lwt_EdgeSplit(LWT_TOPOLOGY *topo, LWT_ELEMID edge, LWPOINT *pt, int skipISOChecks, LWT_ISO_EDGE **oldedge)
Definition: lwgeom_topo.c:962
int lwt_be_updateEdges(LWT_TOPOLOGY *topo, const LWT_ISO_EDGE *sel_edge, int sel_fields, const LWT_ISO_EDGE *upd_edge, int upd_fields, const LWT_ISO_EDGE *exc_edge, int exc_fields)
Definition: lwgeom_topo.c:274
const LWT_BE_IFACE * be_iface
LWGEOM ** geoms
Definition: liblwgeom.h:508
#define LWT_COL_EDGE_END_NODE
LWT_ELEMID face_right
int32_t srid
Definition: liblwgeom.h:505
LWT_ELEMID node_id
LWT_ELEMID edge_id
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:169
LWT_ELEMID lwt_be_getNextEdgeId(LWT_TOPOLOGY *topo)
Definition: lwgeom_topo.c:219
#define LWT_COL_EDGE_EDGE_ID
Edge fields.
#define LWT_COL_EDGE_NEXT_LEFT
int lwt_be_insertEdges(LWT_TOPOLOGY *topo, LWT_ISO_EDGE *edge, int numelems)
Definition: lwgeom_topo.c:268
#define LWT_COL_EDGE_NEXT_RIGHT
LWT_ELEMID start_node
static void _lwt_release_edges(LWT_ISO_EDGE *edges, int num_edges)
Definition: lwgeom_topo.c:457
LWT_ELEMID next_right
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:342
#define LWT_COL_EDGE_GEOM
LWT_ELEMID end_node
int lwt_be_updateTopoGeomEdgeSplit(LWT_TOPOLOGY *topo, LWT_ELEMID split_edge, LWT_ELEMID new_edge1, LWT_ELEMID new_edge2)
Definition: lwgeom_topo.c:337
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

Here is the call graph for this function:

Here is the caller graph for this function: