PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ lwt_ModEdgeSplit()

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 1038 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().

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