PostGIS  3.0.0dev-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 3612 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.

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