PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ _lwt_GetEqualEdge()

static LWT_ELEMID _lwt_GetEqualEdge ( LWT_TOPOLOGY topo,
LWLINE edge 
)
static

Definition at line 5439 of file lwgeom_topo.c.

References _lwt_release_edges(), LWT_TOPOLOGY_T::be_iface, LWT_ISO_EDGE::edge_id, LWT_ISO_EDGE::geom, lwerror(), LWGEOM2GEOS(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwgeom_get_bbox(), lwline_as_lwgeom(), lwnotice(), lwt_be_getEdgeWithinBox2D(), lwt_be_lastErrorMessage(), LWT_COL_EDGE_EDGE_ID, and LWT_COL_EDGE_GEOM.

Referenced by _lwt_AddLineEdge().

5440 {
5441  LWT_ELEMID id;
5442  LWT_ISO_EDGE *edges;
5443  int num, i;
5444  const GBOX *qbox = lwgeom_get_bbox( lwline_as_lwgeom(edge) );
5445  GEOSGeometry *edgeg;
5446  const int flds = LWT_COL_EDGE_EDGE_ID|LWT_COL_EDGE_GEOM;
5447 
5448  edges = lwt_be_getEdgeWithinBox2D( topo, qbox, &num, flds, 0 );
5449  if ( num == -1 )
5450  {
5451  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
5452  return -1;
5453  }
5454  if ( num )
5455  {
5456  initGEOS(lwnotice, lwgeom_geos_error);
5457 
5458  edgeg = LWGEOM2GEOS( lwline_as_lwgeom(edge), 0 );
5459  if ( ! edgeg )
5460  {
5461  _lwt_release_edges(edges, num);
5462  lwerror("Could not convert edge geometry to GEOS: %s", lwgeom_geos_errmsg);
5463  return -1;
5464  }
5465  for (i=0; i<num; ++i)
5466  {
5467  LWT_ISO_EDGE *e = &(edges[i]);
5468  LWGEOM *g = lwline_as_lwgeom(e->geom);
5469  GEOSGeometry *gg;
5470  int equals;
5471  gg = LWGEOM2GEOS( g, 0 );
5472  if ( ! gg )
5473  {
5474  GEOSGeom_destroy(edgeg);
5475  _lwt_release_edges(edges, num);
5476  lwerror("Could not convert edge geometry to GEOS: %s", lwgeom_geos_errmsg);
5477  return -1;
5478  }
5479  equals = GEOSEquals(gg, edgeg);
5480  GEOSGeom_destroy(gg);
5481  if ( equals == 2 )
5482  {
5483  GEOSGeom_destroy(edgeg);
5484  _lwt_release_edges(edges, num);
5485  lwerror("GEOSEquals exception: %s", lwgeom_geos_errmsg);
5486  return -1;
5487  }
5488  if ( equals )
5489  {
5490  id = e->edge_id;
5491  GEOSGeom_destroy(edgeg);
5492  _lwt_release_edges(edges, num);
5493  return id;
5494  }
5495  }
5496  GEOSGeom_destroy(edgeg);
5497  _lwt_release_edges(edges, num);
5498  }
5499 
5500  return 0;
5501 }
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
LWLINE * geom
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:330
void lwgeom_geos_error(const char *fmt,...)
const LWT_BE_IFACE * be_iface
const GBOX * lwgeom_get_bbox(const LWGEOM *lwgeom)
Get a non-empty geometry bounding box, computing and caching it if not already there.
Definition: lwgeom.c:734
LWT_ELEMID edge_id
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
#define LWT_COL_EDGE_EDGE_ID
Edge fields.
static void _lwt_release_edges(LWT_ISO_EDGE *edges, int num_edges)
Definition: lwgeom_topo.c:457
LWT_INT64 LWT_ELEMID
Identifier of topology element.
#define LWT_COL_EDGE_GEOM
static LWT_ISO_EDGE * lwt_be_getEdgeWithinBox2D(const LWT_TOPOLOGY *topo, const GBOX *box, int *numelems, int fields, int limit)
Definition: lwgeom_topo.c:179
uint32_t e
Definition: geobuf.h:57
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
Here is the call graph for this function:
Here is the caller graph for this function: