PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ geography_tree_closestpoint()

LWGEOM* geography_tree_closestpoint ( const LWGEOM lwgeom1,
const LWGEOM lwgeom2,
double  threshold 
)

Definition at line 1035 of file lwgeodetic_tree.c.

1036 {
1037  CIRC_NODE* circ_tree1 = NULL;
1038  CIRC_NODE* circ_tree2 = NULL;
1039  double min_dist = FLT_MAX;
1040  double max_dist = FLT_MAX;
1041  GEOGRAPHIC_POINT closest1, closest2;
1042  LWGEOM *result;
1043  POINT4D p;
1044 
1045  circ_tree1 = lwgeom_calculate_circ_tree(lwgeom1);
1046  circ_tree2 = lwgeom_calculate_circ_tree(lwgeom2);
1047 
1048  /* Quietly decrease the threshold just a little to avoid cases where */
1049  /* the actual spheroid distance is larger than the sphere distance */
1050  /* causing the return value to be larger than the threshold value */
1051  // double threshold_radians = 0.95 * threshold / spheroid->radius;
1052  double threshold_radians = threshold / WGS84_RADIUS;
1053 
1055  circ_tree1, circ_tree2, threshold_radians,
1056  &min_dist, &max_dist, &closest1, &closest2);
1057 
1058  p.x = rad2deg(closest1.lon);
1059  p.y = rad2deg(closest1.lat);
1060  result = (LWGEOM *)lwpoint_make2d(lwgeom_get_srid(lwgeom1), p.x, p.y);
1061 
1062  circ_tree_free(circ_tree1);
1063  circ_tree_free(circ_tree2);
1064  return result;
1065 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
Definition: lwgeom.c:927
LWPOINT * lwpoint_make2d(int32_t srid, double x, double y)
Definition: lwpoint.c:163
#define WGS84_RADIUS
Definition: liblwgeom.h:148
#define rad2deg(r)
Definition: lwgeodetic.h:81
void circ_tree_free(CIRC_NODE *node)
Recurse from top of node tree and free all children.
double circ_tree_distance_tree_internal(const CIRC_NODE *n1, const CIRC_NODE *n2, double threshold, double *min_dist, double *max_dist, GEOGRAPHIC_POINT *closest1, GEOGRAPHIC_POINT *closest2)
CIRC_NODE * lwgeom_calculate_circ_tree(const LWGEOM *lwgeom)
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:54
double x
Definition: liblwgeom.h:414
double y
Definition: liblwgeom.h:414
Note that p1 and p2 are pointers into an independent POINTARRAY, do not free them.

References circ_tree_distance_tree_internal(), circ_tree_free(), GEOGRAPHIC_POINT::lat, GEOGRAPHIC_POINT::lon, lwgeom_calculate_circ_tree(), lwgeom_get_srid(), lwpoint_make2d(), rad2deg, result, WGS84_RADIUS, POINT4D::x, and POINT4D::y.

Referenced by geography_closestpoint(), and test_geography_tree_closestpoint().

Here is the call graph for this function:
Here is the caller graph for this function: