PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ _lwt_GetEqualEdge()

static LWT_ELEMID _lwt_GetEqualEdge ( LWT_TOPOLOGY topo,
LWLINE edge,
int *  forward 
)
static

Definition at line 5340 of file lwgeom_topo.c.

5341 {
5342  LWT_ELEMID id;
5343  LWT_ISO_EDGE *edges;
5344  uint64_t num, i;
5345  const GBOX *qbox = lwgeom_get_bbox( lwline_as_lwgeom(edge) );
5346  GEOSGeometry *edgeg;
5347  const int flds = LWT_COL_EDGE_EDGE_ID|LWT_COL_EDGE_GEOM;
5348 
5349  edges = lwt_be_getEdgeWithinBox2D( topo, qbox, &num, flds, 0 );
5350  if (num == UINT64_MAX)
5351  {
5352  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
5353  return -1;
5354  }
5355  if ( num )
5356  {
5357  initGEOS(lwnotice, lwgeom_geos_error);
5358 
5359  edgeg = LWGEOM2GEOS( lwline_as_lwgeom(edge), 0 );
5360  if ( ! edgeg )
5361  {
5362  _lwt_release_edges(edges, num);
5363  lwerror("Could not convert edge geometry to GEOS: %s", lwgeom_geos_errmsg);
5364  return -1;
5365  }
5366  for (i=0; i<num; ++i)
5367  {
5368  LWT_ISO_EDGE *e = &(edges[i]);
5369  LWGEOM *g = lwline_as_lwgeom(e->geom);
5370  GEOSGeometry *gg;
5371  int equals;
5372  gg = LWGEOM2GEOS( g, 0 );
5373  if ( ! gg )
5374  {
5375  GEOSGeom_destroy(edgeg);
5376  _lwt_release_edges(edges, num);
5377  lwerror("Could not convert edge geometry to GEOS: %s", lwgeom_geos_errmsg);
5378  return -1;
5379  }
5380  equals = GEOSEquals(gg, edgeg);
5381  GEOSGeom_destroy(gg);
5382  if ( equals == 2 )
5383  {
5384  GEOSGeom_destroy(edgeg);
5385  _lwt_release_edges(edges, num);
5386  lwerror("GEOSEquals exception: %s", lwgeom_geos_errmsg);
5387  return -1;
5388  }
5389  if ( equals )
5390  {
5391  id = e->edge_id;
5392  /* Check if direction also matches */
5393  if ( forward )
5394  {
5395  /* If input line is closed, we use winding order */
5396  if ( lwline_is_closed(edge) )
5397  {
5398  if ( ptarray_isccw(edge->points) == ptarray_isccw(e->geom->points) )
5399  {
5400  *forward = 1;
5401  }
5402  else
5403  {
5404  *forward = 0;
5405  }
5406  }
5407  else
5408  {
5409  /* Input line is not closed, checking fist point is enough */
5410  if (
5411  memcmp(
5412  getPoint_internal(edge->points, 0),
5413  getPoint_internal(e->geom->points, 0),
5414  sizeof(POINT2D)
5415  ) == 0
5416  )
5417  {
5418  *forward = 1;
5419  }
5420  else
5421  {
5422  *forward = 0;
5423  }
5424  }
5425  }
5426  GEOSGeom_destroy(edgeg);
5427  _lwt_release_edges(edges, num);
5428  return id;
5429  }
5430  }
5431  GEOSGeom_destroy(edgeg);
5432  _lwt_release_edges(edges, num);
5433  }
5434 
5435  return 0;
5436 }
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
void lwgeom_geos_error(const char *fmt,...)
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:322
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:726
int lwline_is_closed(const LWLINE *line)
Definition: lwline.c:445
int ptarray_isccw(const POINTARRAY *pa)
Definition: ptarray.c:1034
LWT_INT64 LWT_ELEMID
Identifier of topology element.
#define LWT_COL_EDGE_EDGE_ID
Edge fields.
#define LWT_COL_EDGE_GEOM
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
const char * lwt_be_lastErrorMessage(const LWT_BE_IFACE *be)
Definition: lwgeom_topo.c:119
static LWT_ISO_EDGE * lwt_be_getEdgeWithinBox2D(const LWT_TOPOLOGY *topo, const GBOX *box, uint64_t *numelems, int fields, uint64_t limit)
Definition: lwgeom_topo.c:178
static void _lwt_release_edges(LWT_ISO_EDGE *edges, int num_edges)
Definition: lwgeom_topo.c:459
static uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition: lwinline.h:77
POINTARRAY * points
Definition: liblwgeom.h:497
LWLINE * geom
LWT_ELEMID edge_id
const LWT_BE_IFACE * be_iface

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

Referenced by _lwt_AddLineEdge().

Here is the call graph for this function:
Here is the caller graph for this function: