PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lwt_RemIsoEdge()

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 3633 of file lwgeom_topo.c.

3634 {
3635  LWT_ISO_EDGE deledge;
3636  LWT_ISO_EDGE *edge;
3637  LWT_ELEMID nid[2];
3638  LWT_ISO_NODE upd_node[2];
3639  LWT_ELEMID containing_face;
3640  int n = 1;
3641  int i;
3642 
3643  edge = lwt_be_getEdgeById( topo, &id, &n, LWT_COL_EDGE_START_NODE|
3647  if ( ! edge )
3648  {
3649  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3650  return -1;
3651  }
3652  if ( ! n )
3653  {
3654  lwerror("SQL/MM Spatial exception - non-existent edge");
3655  return -1;
3656  }
3657  if ( n > 1 )
3658  {
3659  lwfree(edge);
3660  lwerror("Corrupted topology: more than a single edge have id %"
3661  LWTFMT_ELEMID, id);
3662  return -1;
3663  }
3664 
3665  if ( edge[0].face_left != edge[0].face_right )
3666  {
3667  lwfree(edge);
3668  lwerror("SQL/MM Spatial exception - not isolated edge");
3669  return -1;
3670  }
3671  containing_face = edge[0].face_left;
3672 
3673  nid[0] = edge[0].start_node;
3674  nid[1] = edge[0].end_node;
3675  lwfree(edge);
3676 
3677  n = 2;
3678  edge = lwt_be_getEdgeByNode( topo, nid, &n, LWT_COL_EDGE_EDGE_ID );
3679  if ((n == -1) || (edge == NULL))
3680  {
3681  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3682  return -1;
3683  }
3684  for (i = 0; i < n; ++i)
3685  {
3686  if (edge[i].edge_id != id)
3687  {
3688  lwfree(edge);
3689  lwerror("SQL/MM Spatial exception - not isolated edge");
3690  return -1;
3691  }
3692  }
3693  lwfree(edge);
3694 
3695  deledge.edge_id = id;
3696  n = lwt_be_deleteEdges( topo, &deledge, LWT_COL_EDGE_EDGE_ID );
3697  if ( n == -1 )
3698  {
3699  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3700  return -1;
3701  }
3702  if ( n != 1 )
3703  {
3704  lwerror("Unexpected error: %d edges deleted when expecting 1", n);
3705  return -1;
3706  }
3707 
3708  upd_node[0].node_id = nid[0];
3709  upd_node[0].containing_face = containing_face;
3710  n = 1;
3711  if ( nid[1] != nid[0] ) {
3712  upd_node[1].node_id = nid[1];
3713  upd_node[1].containing_face = containing_face;
3714  ++n;
3715  }
3716  n = lwt_be_updateNodesById(topo, upd_node, n,
3718  if ( n == -1 )
3719  {
3720  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3721  return -1;
3722  }
3723 
3724  /* TODO: notify to caller about edge being removed ?
3725  * See https://trac.osgeo.org/postgis/ticket/3248
3726  */
3727 
3728  return 0; /* success */
3729 }
void lwfree(void *mem)
Definition: lwutil.c:244
#define LWT_COL_EDGE_FACE_RIGHT
LWT_INT64 LWT_ELEMID
Identifier of topology element.
#define LWT_COL_EDGE_START_NODE
#define LWT_COL_EDGE_FACE_LEFT
#define LWT_COL_NODE_CONTAINING_FACE
#define LWT_COL_EDGE_EDGE_ID
Edge fields.
#define LWT_COL_EDGE_END_NODE
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
const char * lwt_be_lastErrorMessage(const LWT_BE_IFACE *be)
Definition: lwgeom_topo.c:120
LWT_ISO_EDGE * lwt_be_getEdgeById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, int *numelems, int fields)
Definition: lwgeom_topo.c:225
static int lwt_be_updateNodesById(LWT_TOPOLOGY *topo, const LWT_ISO_NODE *nodes, int numnodes, int upd_fields)
Definition: lwgeom_topo.c:314
int lwt_be_deleteEdges(LWT_TOPOLOGY *topo, const LWT_ISO_EDGE *sel_edge, int sel_fields)
Definition: lwgeom_topo.c:322
static LWT_ISO_EDGE * lwt_be_getEdgeByNode(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, int *numelems, int fields)
Definition: lwgeom_topo.c:239
#define LWTFMT_ELEMID
Definition: lwgeom_topo.c:44
LWT_ELEMID end_node
LWT_ELEMID face_left
LWT_ELEMID edge_id
LWT_ELEMID start_node
LWT_ELEMID node_id
LWT_ELEMID containing_face
const LWT_BE_IFACE * be_iface

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.

Here is the call graph for this function: