PostGIS  3.2.2dev-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 3730 of file lwgeom_topo.c.

3731 {
3732  LWT_ISO_EDGE deledge;
3733  LWT_ISO_EDGE *edge;
3734  LWT_ELEMID nid[2];
3735  LWT_ISO_NODE upd_node[2];
3736  LWT_ELEMID containing_face;
3737  uint64_t n = 1;
3738  uint64_t i;
3739 
3740  edge = lwt_be_getEdgeById( topo, &id, &n, LWT_COL_EDGE_START_NODE|
3744  if ( ! edge )
3745  {
3746  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3747  return -1;
3748  }
3749  if ( ! n )
3750  {
3751  lwerror("SQL/MM Spatial exception - non-existent edge");
3752  return -1;
3753  }
3754  if ( n > 1 )
3755  {
3756  lwfree(edge);
3757  lwerror("Corrupted topology: more than a single edge have id %"
3758  LWTFMT_ELEMID, id);
3759  return -1;
3760  }
3761 
3762  if ( edge[0].face_left != edge[0].face_right )
3763  {
3764  lwfree(edge);
3765  lwerror("SQL/MM Spatial exception - not isolated edge");
3766  return -1;
3767  }
3768  containing_face = edge[0].face_left;
3769 
3770  nid[0] = edge[0].start_node;
3771  nid[1] = edge[0].end_node;
3772  lwfree(edge);
3773 
3774  n = 2;
3775  edge = lwt_be_getEdgeByNode( topo, nid, &n, LWT_COL_EDGE_EDGE_ID );
3776  if ((n == UINT64_MAX) || (edge == NULL))
3777  {
3778  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3779  return -1;
3780  }
3781  for (i = 0; i < n; ++i)
3782  {
3783  if (edge[i].edge_id != id)
3784  {
3785  lwfree(edge);
3786  lwerror("SQL/MM Spatial exception - not isolated edge");
3787  return -1;
3788  }
3789  }
3790  lwfree(edge);
3791 
3792  deledge.edge_id = id;
3793  n = lwt_be_deleteEdges( topo, &deledge, LWT_COL_EDGE_EDGE_ID );
3794  if (n == UINT64_MAX)
3795  {
3796  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3797  return -1;
3798  }
3799  if ( n != 1 )
3800  {
3801  lwerror("Unexpected error: %d edges deleted when expecting 1", n);
3802  return -1;
3803  }
3804 
3805  upd_node[0].node_id = nid[0];
3806  upd_node[0].containing_face = containing_face;
3807  n = 1;
3808  if ( nid[1] != nid[0] ) {
3809  upd_node[1].node_id = nid[1];
3810  upd_node[1].containing_face = containing_face;
3811  ++n;
3812  }
3813  n = lwt_be_updateNodesById(topo, upd_node, n,
3815  if (n == UINT64_MAX)
3816  {
3817  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3818  return -1;
3819  }
3820 
3821  /* Check that the edge can be safely removed
3822  * See https://trac.osgeo.org/postgis/ticket/3248
3823  */
3824  if ( ! lwt_be_checkTopoGeomRemIsoEdge(topo, id) )
3825  {
3827  return -1;
3828  }
3829 
3830  return 0; /* success */
3831 }
void lwfree(void *mem)
Definition: lwutil.c:242
#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:119
LWT_ISO_EDGE * lwt_be_getEdgeById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields)
Definition: lwgeom_topo.c:220
static int lwt_be_checkTopoGeomRemIsoEdge(LWT_TOPOLOGY *topo, LWT_ELEMID edge_id)
Definition: lwgeom_topo.c:343
static LWT_ISO_EDGE * lwt_be_getEdgeByNode(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields)
Definition: lwgeom_topo.c:232
static int lwt_be_updateNodesById(LWT_TOPOLOGY *topo, const LWT_ISO_NODE *nodes, int numnodes, int upd_fields)
Definition: lwgeom_topo.c:307
int lwt_be_deleteEdges(LWT_TOPOLOGY *topo, const LWT_ISO_EDGE *sel_edge, int sel_fields)
Definition: lwgeom_topo.c:315
#define LWTFMT_ELEMID
Definition: lwgeom_topo.c:43
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_checkTopoGeomRemIsoEdge(), 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: