PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ lwt_GetNodeByPoint()

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

Retrieve the id of a node at a point location.

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

Definition at line 4658 of file lwgeom_topo.c.

4659 {
4660  LWT_ISO_NODE *elem;
4661  uint64_t num;
4662  int flds = LWT_COL_NODE_NODE_ID|LWT_COL_NODE_GEOM; /* geom not needed */
4663  LWT_ELEMID id = 0;
4664  POINT2D qp; /* query point */
4665 
4666  if ( ! getPoint2d_p(pt->point, 0, &qp) )
4667  {
4668  lwerror("Empty query point");
4669  return -1;
4670  }
4671  elem = lwt_be_getNodeWithinDistance2D(topo, pt, tol, &num, flds, 0);
4672  if (num == UINT64_MAX)
4673  {
4674  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
4675  return -1;
4676  }
4677  else if ( num )
4678  {
4679  if ( num > 1 )
4680  {
4681  _lwt_release_nodes(elem, num);
4682  lwerror("Two or more nodes found");
4683  return -1;
4684  }
4685  id = elem[0].node_id;
4686  _lwt_release_nodes(elem, num);
4687  }
4688 
4689  return id;
4690 }
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
Definition: lwgeom_api.c:349
LWT_INT64 LWT_ELEMID
Identifier of topology element.
#define LWT_COL_NODE_GEOM
#define LWT_COL_NODE_NODE_ID
Node fields.
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
const char * lwt_be_lastErrorMessage(const LWT_BE_IFACE *be)
Definition: lwgeom_topo.c:119
static void _lwt_release_nodes(LWT_ISO_NODE *nodes, int num_nodes)
Definition: lwgeom_topo.c:461
LWT_ISO_NODE * lwt_be_getNodeWithinDistance2D(LWT_TOPOLOGY *topo, LWPOINT *pt, double dist, uint64_t *numelems, int fields, int64_t limit)
Definition: lwgeom_topo.c:161
POINTARRAY * point
Definition: liblwgeom.h:457
LWT_ELEMID node_id
const LWT_BE_IFACE * be_iface

References _lwt_release_nodes(), LWT_TOPOLOGY_T::be_iface, getPoint2d_p(), lwerror(), lwt_be_getNodeWithinDistance2D(), lwt_be_lastErrorMessage(), LWT_COL_NODE_GEOM, LWT_COL_NODE_NODE_ID, LWT_ISO_NODE::node_id, and LWPOINT::point.

Here is the call graph for this function: