PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

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

4981{
4982 LWT_ISO_EDGE *elem;
4983 uint64_t num, i;
4984 int flds = LWT_COL_EDGE_EDGE_ID|LWT_COL_EDGE_GEOM; /* GEOM is not needed */
4985 LWT_ELEMID id = 0;
4986 LWGEOM *qp = lwpoint_as_lwgeom(pt); /* query point */
4987
4988 if ( lwgeom_is_empty(qp) )
4989 {
4990 lwerror("Empty query point");
4991 return -1;
4992 }
4993 elem = lwt_be_getEdgeWithinDistance2D(topo, pt, tol, &num, flds, 0);
4994 if (num == UINT64_MAX)
4995 {
4997 return -1;
4998 }
4999 for (i=0; i<num;++i)
5000 {
5001 LWT_ISO_EDGE *e = &(elem[i]);
5002#if 0
5003 LWGEOM* geom;
5004 double dist;
5005
5006 if ( ! e->geom )
5007 {
5008 _lwt_release_edges(elem, num);
5009 lwnotice("Corrupted topology: edge %" LWTFMT_ELEMID
5010 " has null geometry", e->edge_id);
5011 continue;
5012 }
5013
5014 /* Should we check for intersection not being on an endpoint
5015 * as documented ? */
5016 geom = lwline_as_lwgeom(e->geom);
5017 dist = lwgeom_mindistance2d_tolerance(geom, qp, tol);
5018 if ( dist > tol ) continue;
5019#endif
5020
5021 if ( id )
5022 {
5023 _lwt_release_edges(elem, num);
5024 lwerror("Two or more edges found");
5025 return -1;
5026 }
5027 else id = e->edge_id;
5028 }
5029
5030 if ( num ) _lwt_release_edges(elem, num);
5031
5032 return id;
5033}
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition lwgeom.c:372
double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling min distance calculations and dwithin calculations.
Definition measures.c:222
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition lwgeom.c:367
LWT_INT64 LWT_ELEMID
Identifier of topology element.
#define LWT_COL_EDGE_EDGE_ID
Edge fields.
#define LWT_COL_EDGE_GEOM
#define PGTOPO_BE_ERROR()
#define LWTFMT_ELEMID
void lwnotice(const char *fmt,...) __attribute__((format(printf
Write a notice out to the notice handler.
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
LWT_ISO_EDGE * lwt_be_getEdgeWithinDistance2D(LWT_TOPOLOGY *topo, const LWPOINT *pt, double dist, uint64_t *numelems, int fields, int64_t limit)
void _lwt_release_edges(LWT_ISO_EDGE *edges, int num_edges)
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:199
LWT_ELEMID edge_id

References _lwt_release_edges(), 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_COL_EDGE_EDGE_ID, LWT_COL_EDGE_GEOM, LWTFMT_ELEMID, and PGTOPO_BE_ERROR.

Here is the call graph for this function: