PostGIS  2.5.1dev-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 3613 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.

3614 {
3615  LWT_ISO_EDGE deledge;
3616  LWT_ISO_EDGE *edge;
3617  LWT_ELEMID nid[2];
3618  LWT_ISO_NODE upd_node[2];
3619  LWT_ELEMID containing_face;
3620  int n = 1;
3621  int i;
3622 
3623  edge = lwt_be_getEdgeById( topo, &id, &n, LWT_COL_EDGE_START_NODE|
3627  if ( ! edge )
3628  {
3629  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3630  return -1;
3631  }
3632  if ( ! n )
3633  {
3634  lwerror("SQL/MM Spatial exception - non-existent edge");
3635  return -1;
3636  }
3637  if ( n > 1 )
3638  {
3639  lwfree(edge);
3640  lwerror("Corrupted topology: more than a single edge have id %"
3641  LWTFMT_ELEMID, id);
3642  return -1;
3643  }
3644 
3645  if ( edge[0].face_left != edge[0].face_right )
3646  {
3647  lwfree(edge);
3648  lwerror("SQL/MM Spatial exception - not isolated edge");
3649  return -1;
3650  }
3651  containing_face = edge[0].face_left;
3652 
3653  nid[0] = edge[0].start_node;
3654  nid[1] = edge[0].end_node;
3655  lwfree(edge);
3656 
3657  n = 2;
3658  edge = lwt_be_getEdgeByNode( topo, nid, &n, LWT_COL_EDGE_EDGE_ID );
3659  if ((n == -1) || (edge == NULL))
3660  {
3661  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3662  return -1;
3663  }
3664  for (i = 0; i < n; ++i)
3665  {
3666  if (edge[i].edge_id != id)
3667  {
3668  lwfree(edge);
3669  lwerror("SQL/MM Spatial exception - not isolated edge");
3670  return -1;
3671  }
3672  }
3673  lwfree(edge);
3674 
3675  deledge.edge_id = id;
3676  n = lwt_be_deleteEdges( topo, &deledge, LWT_COL_EDGE_EDGE_ID );
3677  if ( n == -1 )
3678  {
3679  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3680  return -1;
3681  }
3682  if ( n != 1 )
3683  {
3684  lwerror("Unexpected error: %d edges deleted when expecting 1", n);
3685  return -1;
3686  }
3687 
3688  upd_node[0].node_id = nid[0];
3689  upd_node[0].containing_face = containing_face;
3690  n = 1;
3691  if ( nid[1] != nid[0] ) {
3692  upd_node[1].node_id = nid[1];
3693  upd_node[1].containing_face = containing_face;
3694  ++n;
3695  }
3696  n = lwt_be_updateNodesById(topo, upd_node, n,
3698  if ( n == -1 )
3699  {
3700  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3701  return -1;
3702  }
3703 
3704  /* TODO: notify to caller about edge being removed ?
3705  * See https://trac.osgeo.org/postgis/ticket/3248
3706  */
3707 
3708  return 0; /* success */
3709 }
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: