PostGIS  2.5.0dev-r@@SVN_REVISION@@
int lwt_RemIsoEdge ( LWT_TOPOLOGY topo,
LWT_ELEMID  edge 
)

Remove an isolated edge.

For ST_RemIsoEdge

Parameters
topothe topology to operate on
edgethe identifier of the edge to be moved
Returns
0 on success, -1 on error (liblwgeom error handler will be invoked with error message)

Definition at line 3819 of file lwgeom_topo.c.

References 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, lwerror(), lwfree(), lwt_be_deleteEdges(), lwt_be_getEdgeById(), lwt_be_getEdgeByNode(), lwt_be_lastErrorMessage(), lwt_be_updateNodesById(), LWT_COL_EDGE_EDGE_ID, LWT_COL_EDGE_END_NODE, LWT_COL_EDGE_FACE_LEFT, LWT_COL_EDGE_FACE_RIGHT, LWT_COL_EDGE_START_NODE, LWT_COL_NODE_CONTAINING_FACE, LWTFMT_ELEMID, LWT_ISO_NODE::node_id, and LWT_ISO_EDGE::start_node.

3820 {
3821  LWT_ISO_EDGE deledge;
3822  LWT_ISO_EDGE *edge;
3823  LWT_ELEMID nid[2];
3824  LWT_ISO_NODE upd_node[2];
3825  LWT_ELEMID containing_face;
3826  int n = 1;
3827  int i;
3828 
3829  edge = lwt_be_getEdgeById( topo, &id, &n, LWT_COL_EDGE_START_NODE|
3833  if ( ! edge )
3834  {
3835  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3836  return -1;
3837  }
3838  if ( ! n )
3839  {
3840  lwerror("SQL/MM Spatial exception - non-existent edge");
3841  return -1;
3842  }
3843  if ( n > 1 )
3844  {
3845  lwfree(edge);
3846  lwerror("Corrupted topology: more than a single edge have id %"
3847  LWTFMT_ELEMID, id);
3848  return -1;
3849  }
3850 
3851  if ( edge[0].face_left != edge[0].face_right )
3852  {
3853  lwfree(edge);
3854  lwerror("SQL/MM Spatial exception - not isolated edge");
3855  return -1;
3856  }
3857  containing_face = edge[0].face_left;
3858 
3859  nid[0] = edge[0].start_node;
3860  nid[1] = edge[0].end_node;
3861  lwfree(edge);
3862 
3863  n = 2;
3864  edge = lwt_be_getEdgeByNode( topo, nid, &n, LWT_COL_EDGE_EDGE_ID );
3865  if ( n == -1 )
3866  {
3867  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3868  return -1;
3869  }
3870  for ( i=0; i<n; ++i )
3871  {
3872  if ( edge[i].edge_id == id ) continue;
3873  lwfree(edge);
3874  lwerror("SQL/MM Spatial exception - not isolated edge");
3875  return -1;
3876  }
3877  if ( edge ) lwfree(edge);
3878 
3879  deledge.edge_id = id;
3880  n = lwt_be_deleteEdges( topo, &deledge, LWT_COL_EDGE_EDGE_ID );
3881  if ( n == -1 )
3882  {
3883  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3884  return -1;
3885  }
3886  if ( n != 1 )
3887  {
3888  lwerror("Unexpected error: %d edges deleted when expecting 1", n);
3889  return -1;
3890  }
3891 
3892  upd_node[0].node_id = nid[0];
3893  upd_node[0].containing_face = containing_face;
3894  n = 1;
3895  if ( nid[1] != nid[0] ) {
3896  upd_node[1].node_id = nid[1];
3897  upd_node[1].containing_face = containing_face;
3898  ++n;
3899  }
3900  n = lwt_be_updateNodesById(topo, upd_node, n,
3902  if ( n == -1 )
3903  {
3904  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3905  return -1;
3906  }
3907 
3908  /* TODO: notify to caller about edge being removed ?
3909  * See https://trac.osgeo.org/postgis/ticket/3248
3910  */
3911 
3912  return 0; /* success */
3913 }
LWT_ELEMID face_left
#define LWT_COL_NODE_CONTAINING_FACE
#define LWT_COL_EDGE_FACE_LEFT
LWT_ELEMID containing_face
void lwfree(void *mem)
Definition: lwutil.c:244
#define LWT_COL_EDGE_FACE_RIGHT
int lwt_be_deleteEdges(LWT_TOPOLOGY *topo, const LWT_ISO_EDGE *sel_edge, int sel_fields)
Definition: lwgeom_topo.c:322
#define LWT_COL_EDGE_START_NODE
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
#define LWT_COL_EDGE_END_NODE
LWT_ELEMID node_id
LWT_ELEMID edge_id
static int lwt_be_updateNodesById(LWT_TOPOLOGY *topo, const LWT_ISO_NODE *nodes, int numnodes, int upd_fields)
Definition: lwgeom_topo.c:314
#define LWT_COL_EDGE_EDGE_ID
Edge fields.
LWT_ELEMID start_node
LWT_INT64 LWT_ELEMID
Identifier of topology element.
static LWT_ISO_EDGE * lwt_be_getEdgeByNode(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, int *numelems, int fields)
Definition: lwgeom_topo.c:239
LWT_ELEMID end_node
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
#define LWTFMT_ELEMID
Definition: lwgeom_topo.c:44

Here is the call graph for this function: