PostGIS  2.4.9dev-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 3779 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.

3780 {
3781  LWT_ISO_EDGE deledge;
3782  LWT_ISO_EDGE *edge;
3783  LWT_ELEMID nid[2];
3784  LWT_ISO_NODE upd_node[2];
3785  LWT_ELEMID containing_face;
3786  int n = 1;
3787  int i;
3788 
3789  edge = lwt_be_getEdgeById( topo, &id, &n, LWT_COL_EDGE_START_NODE|
3793  if ( ! edge )
3794  {
3795  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3796  return -1;
3797  }
3798  if ( ! n )
3799  {
3800  lwerror("SQL/MM Spatial exception - non-existent edge");
3801  return -1;
3802  }
3803  if ( n > 1 )
3804  {
3805  lwfree(edge);
3806  lwerror("Corrupted topology: more than a single edge have id %"
3807  LWTFMT_ELEMID, id);
3808  return -1;
3809  }
3810 
3811  if ( edge[0].face_left != edge[0].face_right )
3812  {
3813  lwfree(edge);
3814  lwerror("SQL/MM Spatial exception - not isolated edge");
3815  return -1;
3816  }
3817  containing_face = edge[0].face_left;
3818 
3819  nid[0] = edge[0].start_node;
3820  nid[1] = edge[0].end_node;
3821  lwfree(edge);
3822 
3823  n = 2;
3824  edge = lwt_be_getEdgeByNode( topo, nid, &n, LWT_COL_EDGE_EDGE_ID );
3825  if ( n == -1 )
3826  {
3827  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3828  return -1;
3829  }
3830  for ( i=0; i<n; ++i )
3831  {
3832  if ( edge[i].edge_id == id ) continue;
3833  lwfree(edge);
3834  lwerror("SQL/MM Spatial exception - not isolated edge");
3835  return -1;
3836  }
3837  if ( edge ) lwfree(edge);
3838 
3839  deledge.edge_id = id;
3840  n = lwt_be_deleteEdges( topo, &deledge, LWT_COL_EDGE_EDGE_ID );
3841  if ( n == -1 )
3842  {
3843  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3844  return -1;
3845  }
3846  if ( n != 1 )
3847  {
3848  lwerror("Unexpected error: %d edges deleted when expecting 1", n);
3849  return -1;
3850  }
3851 
3852  upd_node[0].node_id = nid[0];
3853  upd_node[0].containing_face = containing_face;
3854  n = 1;
3855  if ( nid[1] != nid[0] ) {
3856  upd_node[1].node_id = nid[1];
3857  upd_node[1].containing_face = containing_face;
3858  ++n;
3859  }
3860  n = lwt_be_updateNodesById(topo, upd_node, n,
3862  if ( n == -1 )
3863  {
3864  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3865  return -1;
3866  }
3867 
3868  /* TODO: notify to caller about edge being removed ?
3869  * See https://trac.osgeo.org/postgis/ticket/3248
3870  */
3871 
3872  return 0; /* success */
3873 }
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: