PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ geography_tree_closestpoint()

LWGEOM* geography_tree_closestpoint ( const LWGEOM g1,
const LWGEOM g2,
double  threshold 
)

Definition at line 1036 of file lwgeodetic_tree.c.

1037 {
1038  CIRC_NODE* circ_tree1 = NULL;
1039  CIRC_NODE* circ_tree2 = NULL;
1040  double min_dist = FLT_MAX;
1041  double max_dist = FLT_MAX;
1042  GEOGRAPHIC_POINT closest1, closest2;
1043  LWGEOM *result;
1044  POINT4D p;
1045 
1046  circ_tree1 = lwgeom_calculate_circ_tree(lwgeom1);
1047  circ_tree2 = lwgeom_calculate_circ_tree(lwgeom2);
1048 
1049  /* Quietly decrease the threshold just a little to avoid cases where */
1050  /* the actual spheroid distance is larger than the sphere distance */
1051  /* causing the return value to be larger than the threshold value */
1052  // double threshold_radians = 0.95 * threshold / spheroid->radius;
1053  double threshold_radians = threshold / WGS84_RADIUS;
1054 
1056  circ_tree1, circ_tree2, threshold_radians,
1057  &min_dist, &max_dist, &closest1, &closest2);
1058 
1059  p.x = rad2deg(closest1.lon);
1060  p.y = rad2deg(closest1.lat);
1061  result = (LWGEOM *)lwpoint_make2d(lwgeom_get_srid(lwgeom1), p.x, p.y);
1062 
1063  circ_tree_free(circ_tree1);
1064  circ_tree_free(circ_tree2);
1065  return result;
1066 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
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.
static 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().

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