PostGIS  3.3.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 3811 of file lwgeom_topo.c.

3812 {
3813  LWT_ISO_EDGE deledge;
3814  LWT_ISO_EDGE *edge;
3815  LWT_ELEMID nid[2];
3816  LWT_ISO_NODE upd_node[2];
3817  LWT_ELEMID containing_face;
3818  uint64_t n = 1;
3819  uint64_t i;
3820 
3821  edge = lwt_be_getEdgeById( topo, &id, &n, LWT_COL_EDGE_START_NODE|
3825  if ( ! edge )
3826  {
3827  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3828  return -1;
3829  }
3830  if ( ! n )
3831  {
3832  lwerror("SQL/MM Spatial exception - non-existent edge");
3833  return -1;
3834  }
3835  if ( n > 1 )
3836  {
3837  lwfree(edge);
3838  lwerror("Corrupted topology: more than a single edge have id %"
3839  LWTFMT_ELEMID, id);
3840  return -1;
3841  }
3842 
3843  if ( edge[0].face_left != edge[0].face_right )
3844  {
3845  lwfree(edge);
3846  lwerror("SQL/MM Spatial exception - not isolated edge");
3847  return -1;
3848  }
3849  containing_face = edge[0].face_left;
3850 
3851  nid[0] = edge[0].start_node;
3852  nid[1] = edge[0].end_node;
3853  lwfree(edge);
3854 
3855  n = 2;
3856  edge = lwt_be_getEdgeByNode( topo, nid, &n, LWT_COL_EDGE_EDGE_ID );
3857  if ((n == UINT64_MAX) || (edge == NULL))
3858  {
3859  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3860  return -1;
3861  }
3862  for (i = 0; i < n; ++i)
3863  {
3864  if (edge[i].edge_id != id)
3865  {
3866  lwfree(edge);
3867  lwerror("SQL/MM Spatial exception - not isolated edge");
3868  return -1;
3869  }
3870  }
3871  lwfree(edge);
3872 
3873  deledge.edge_id = id;
3874  n = lwt_be_deleteEdges( topo, &deledge, LWT_COL_EDGE_EDGE_ID );
3875  if (n == UINT64_MAX)
3876  {
3877  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3878  return -1;
3879  }
3880  if ( n != 1 )
3881  {
3882  lwerror("Unexpected error: %d edges deleted when expecting 1", n);
3883  return -1;
3884  }
3885 
3886  upd_node[0].node_id = nid[0];
3887  upd_node[0].containing_face = containing_face;
3888  n = 1;
3889  if ( nid[1] != nid[0] ) {
3890  upd_node[1].node_id = nid[1];
3891  upd_node[1].containing_face = containing_face;
3892  ++n;
3893  }
3894  n = lwt_be_updateNodesById(topo, upd_node, n,
3896  if (n == UINT64_MAX)
3897  {
3898  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3899  return -1;
3900  }
3901 
3902  /* Check that the edge can be safely removed
3903  * See https://trac.osgeo.org/postgis/ticket/3248
3904  */
3905  if ( ! lwt_be_checkTopoGeomRemIsoEdge(topo, id) )
3906  {
3908  return -1;
3909  }
3910 
3911  return 0; /* success */
3912 }
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: