PostGIS  2.5.0dev-r@@SVN_REVISION@@
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 4868 of file lwgeom_topo.c.

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.

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

Here is the call graph for this function: