PostGIS  2.2.8dev-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 4759 of file lwgeom_topo.c.

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.

4760 {
4761  LWT_ISO_NODE *elem;
4762  int num;
4763  int flds = LWT_COL_NODE_NODE_ID|LWT_COL_NODE_GEOM; /* geom not needed */
4764  LWT_ELEMID id = 0;
4765  POINT2D qp; /* query point */
4766 
4767  if ( ! getPoint2d_p(pt->point, 0, &qp) )
4768  {
4769  lwerror("Empty query point");
4770  return -1;
4771  }
4772  elem = lwt_be_getNodeWithinDistance2D(topo, pt, tol, &num, flds, 0);
4773  if ( num == -1 )
4774  {
4775  lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface));
4776  return -1;
4777  }
4778  else if ( num )
4779  {
4780  if ( num > 1 )
4781  {
4782  _lwt_release_nodes(elem, num);
4783  lwerror("Two or more nodes found");
4784  return -1;
4785  }
4786  id = elem[0].node_id;
4787  _lwt_release_nodes(elem, num);
4788  }
4789 
4790  return id;
4791 }
static void _lwt_release_nodes(LWT_ISO_NODE *nodes, int num_nodes)
Definition: lwgeom_topo.c:481
LWT_ISO_NODE * lwt_be_getNodeWithinDistance2D(LWT_TOPOLOGY *topo, LWPOINT *pt, double dist, int *numelems, int fields, int limit)
Definition: lwgeom_topo.c:167
POINTARRAY * point
Definition: liblwgeom.h:395
const LWT_BE_IFACE * be_iface
LWT_ELEMID node_id
int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point)
Definition: lwgeom_api.c:448
#define LWT_COL_NODE_NODE_ID
Node fields.
#define LWT_COL_NODE_GEOM
LWT_INT64 LWT_ELEMID
Identifier of topology element.
const char * lwt_be_lastErrorMessage(const LWT_BE_IFACE *be)
Definition: lwgeom_topo.c:124
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
Here is the call graph for this function: