PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ lwt_GetEdgeByPoint()

LWT_ELEMID lwt_GetEdgeByPoint ( LWT_TOPOLOGY topo,
LWPOINT pt,
double  tol 
)

Find the edge-id of an edge that intersects a given point.

Parameters
topothe topology to operate on
pointthe point to use for query
tolmax distance around the given point to look for an intersecting edge
Returns
an edge identifier if one is found, 0 if none is found, -1 on error (multiple edges within distance). The liblwgeom error handler will be invoked in case of error.

Definition at line 4865 of file lwgeom_topo.c.

4866 {
4867  LWT_ISO_EDGE *elem;
4868  uint64_t num, i;
4869  int flds = LWT_COL_EDGE_EDGE_ID|LWT_COL_EDGE_GEOM; /* GEOM is not needed */
4870  LWT_ELEMID id = 0;
4871  LWGEOM *qp = lwpoint_as_lwgeom(pt); /* query point */
4872 
4873  if ( lwgeom_is_empty(qp) )
4874  {
4875  lwerror("Empty query point");
4876  return -1;
4877  }
4878  elem = lwt_be_getEdgeWithinDistance2D(topo, pt, tol, &num, flds, 0);
4879  if (num == UINT64_MAX)
4880  {
4881  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
4882  return -1;
4883  }
4884  for (i=0; i<num;++i)
4885  {
4886  LWT_ISO_EDGE *e = &(elem[i]);
4887 #if 0
4888  LWGEOM* geom;
4889  double dist;
4890 
4891  if ( ! e->geom )
4892  {
4893  _lwt_release_edges(elem, num);
4894  lwnotice("Corrupted topology: edge %" LWTFMT_ELEMID
4895  " has null geometry", e->edge_id);
4896  continue;
4897  }
4898 
4899  /* Should we check for intersection not being on an endpoint
4900  * as documented ? */
4901  geom = lwline_as_lwgeom(e->geom);
4902  dist = lwgeom_mindistance2d_tolerance(geom, qp, tol);
4903  if ( dist > tol ) continue;
4904 #endif
4905 
4906  if ( id )
4907  {
4908  _lwt_release_edges(elem, num);
4909  lwerror("Two or more edges found");
4910  return -1;
4911  }
4912  else id = e->edge_id;
4913  }
4914 
4915  if ( num ) _lwt_release_edges(elem, num);
4916 
4917  return id;
4918 }
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:339
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:344
double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling min distance calculations and dwithin calculations.
Definition: measures.c:210
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
#define LWTFMT_ELEMID
Definition: lwgeom_topo.c:43
static void _lwt_release_edges(LWT_ISO_EDGE *edges, int num_edges)
Definition: lwgeom_topo.c:465
LWT_ISO_EDGE * lwt_be_getEdgeWithinDistance2D(LWT_TOPOLOGY *topo, const LWPOINT *pt, double dist, uint64_t *numelems, int fields, int64_t limit)
Definition: lwgeom_topo.c:250
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwinline.h:203
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, lwerror(), lwgeom_is_empty(), lwgeom_mindistance2d_tolerance(), lwline_as_lwgeom(), lwnotice(), lwpoint_as_lwgeom(), lwt_be_getEdgeWithinDistance2D(), lwt_be_lastErrorMessage(), LWT_COL_EDGE_EDGE_ID, LWT_COL_EDGE_GEOM, and LWTFMT_ELEMID.

Here is the call graph for this function: