PostGIS  2.2.8dev-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 3749 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.

3750 {
3751  LWT_ISO_EDGE deledge;
3752  LWT_ISO_EDGE *edge;
3753  LWT_ELEMID nid[2];
3754  LWT_ISO_NODE upd_node[2];
3755  LWT_ELEMID containing_face;
3756  int n = 1;
3757  int i;
3758 
3759  edge = lwt_be_getEdgeById( topo, &id, &n, LWT_COL_EDGE_START_NODE|
3763  if ( ! edge )
3764  {
3765  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3766  return -1;
3767  }
3768  if ( ! n )
3769  {
3770  lwerror("SQL/MM Spatial exception - non-existent edge");
3771  return -1;
3772  }
3773  if ( n > 1 )
3774  {
3775  lwfree(edge);
3776  lwerror("Corrupted topology: more than a single edge have id %"
3777  LWTFMT_ELEMID, id);
3778  return -1;
3779  }
3780 
3781  if ( edge[0].face_left != edge[0].face_right )
3782  {
3783  lwfree(edge);
3784  lwerror("SQL/MM Spatial exception - not isolated edge");
3785  return -1;
3786  }
3787  containing_face = edge[0].face_left;
3788 
3789  nid[0] = edge[0].start_node;
3790  nid[1] = edge[0].end_node;
3791  lwfree(edge);
3792 
3793  n = 2;
3794  edge = lwt_be_getEdgeByNode( topo, nid, &n, LWT_COL_EDGE_EDGE_ID );
3795  if ( n == -1 )
3796  {
3797  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3798  return -1;
3799  }
3800  for ( i=0; i<n; ++i )
3801  {
3802  if ( edge[i].edge_id == id ) continue;
3803  lwfree(edge);
3804  lwerror("SQL/MM Spatial exception - not isolated edge");
3805  return -1;
3806  }
3807  if ( edge ) lwfree(edge);
3808 
3809  deledge.edge_id = id;
3810  n = lwt_be_deleteEdges( topo, &deledge, LWT_COL_EDGE_EDGE_ID );
3811  if ( n == -1 )
3812  {
3813  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3814  return -1;
3815  }
3816  if ( n != 1 )
3817  {
3818  lwerror("Unexpected error: %d edges deleted when expecting 1", n);
3819  return -1;
3820  }
3821 
3822  upd_node[0].node_id = nid[0];
3823  upd_node[0].containing_face = containing_face;
3824  n = 1;
3825  if ( nid[1] != nid[0] ) {
3826  upd_node[1].node_id = nid[1];
3827  upd_node[1].containing_face = containing_face;
3828  ++n;
3829  }
3830  n = lwt_be_updateNodesById(topo, upd_node, n,
3832  if ( n == -1 )
3833  {
3834  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3835  return -1;
3836  }
3837 
3838  /* TODO: notify to caller about edge being removed ?
3839  * See https://trac.osgeo.org/postgis/ticket/3248
3840  */
3841 
3842  return 0; /* success */
3843 }
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:214
#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:326
#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:229
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:318
#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:243
LWT_ELEMID end_node
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
#define LWTFMT_ELEMID
Definition: lwgeom_topo.c:36
Here is the call graph for this function: