PostGIS  3.4.0dev-r@@SVN_REVISION@@
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages

◆ 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 3670 of file lwgeom_topo.c.

3671 {
3672  LWT_ISO_EDGE deledge;
3673  LWT_ISO_EDGE *edge;
3674  LWT_ELEMID nid[2];
3675  LWT_ISO_NODE upd_node[2];
3676  LWT_ELEMID containing_face;
3677  uint64_t n = 1;
3678  uint64_t i;
3679 
3680  edge = lwt_be_getEdgeById( topo, &id, &n, LWT_COL_EDGE_START_NODE|
3684  if ( ! edge )
3685  {
3686  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3687  return -1;
3688  }
3689  if ( ! n )
3690  {
3691  lwerror("SQL/MM Spatial exception - non-existent edge");
3692  return -1;
3693  }
3694  if ( n > 1 )
3695  {
3696  lwfree(edge);
3697  lwerror("Corrupted topology: more than a single edge have id %"
3698  LWTFMT_ELEMID, id);
3699  return -1;
3700  }
3701 
3702  if ( edge[0].face_left != edge[0].face_right )
3703  {
3704  lwfree(edge);
3705  lwerror("SQL/MM Spatial exception - not isolated edge");
3706  return -1;
3707  }
3708  containing_face = edge[0].face_left;
3709 
3710  nid[0] = edge[0].start_node;
3711  nid[1] = edge[0].end_node;
3712  lwfree(edge);
3713 
3714  n = 2;
3715  edge = lwt_be_getEdgeByNode( topo, nid, &n, LWT_COL_EDGE_EDGE_ID );
3716  if ((n == UINT64_MAX) || (edge == NULL))
3717  {
3718  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3719  return -1;
3720  }
3721  for (i = 0; i < n; ++i)
3722  {
3723  if (edge[i].edge_id != id)
3724  {
3725  lwfree(edge);
3726  lwerror("SQL/MM Spatial exception - not isolated edge");
3727  return -1;
3728  }
3729  }
3730  lwfree(edge);
3731 
3732  deledge.edge_id = id;
3733  n = lwt_be_deleteEdges( topo, &deledge, LWT_COL_EDGE_EDGE_ID );
3734  if (n == UINT64_MAX)
3735  {
3736  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3737  return -1;
3738  }
3739  if ( n != 1 )
3740  {
3741  lwerror("Unexpected error: %d edges deleted when expecting 1", n);
3742  return -1;
3743  }
3744 
3745  upd_node[0].node_id = nid[0];
3746  upd_node[0].containing_face = containing_face;
3747  n = 1;
3748  if ( nid[1] != nid[0] ) {
3749  upd_node[1].node_id = nid[1];
3750  upd_node[1].containing_face = containing_face;
3751  ++n;
3752  }
3753  n = lwt_be_updateNodesById(topo, upd_node, n,
3755  if (n == UINT64_MAX)
3756  {
3757  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
3758  return -1;
3759  }
3760 
3761  /* Check that the edge can be safely removed
3762  * See https://trac.osgeo.org/postgis/ticket/3248
3763  */
3764  if ( ! lwt_be_checkTopoGeomRemIsoEdge(topo, id) )
3765  {
3767  return -1;
3768  }
3769 
3770  return 0; /* success */
3771 }
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:125
LWT_ISO_EDGE * lwt_be_getEdgeById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields)
Definition: lwgeom_topo.c:226
static int lwt_be_checkTopoGeomRemIsoEdge(LWT_TOPOLOGY *topo, LWT_ELEMID edge_id)
Definition: lwgeom_topo.c:349
static LWT_ISO_EDGE * lwt_be_getEdgeByNode(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields)
Definition: lwgeom_topo.c:238
static int lwt_be_updateNodesById(LWT_TOPOLOGY *topo, const LWT_ISO_NODE *nodes, int numnodes, int upd_fields)
Definition: lwgeom_topo.c:313
int lwt_be_deleteEdges(LWT_TOPOLOGY *topo, const LWT_ISO_EDGE *sel_edge, int sel_fields)
Definition: lwgeom_topo.c:321
#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: