PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ geography_tree_shortestline()

LWGEOM* geography_tree_shortestline ( const LWGEOM lwgeom1,
const LWGEOM lwgeom2,
double  threshold,
const SPHEROID spheroid 
)

Definition at line 1069 of file lwgeodetic_tree.c.

1070 {
1071  CIRC_NODE* circ_tree1 = NULL;
1072  CIRC_NODE* circ_tree2 = NULL;
1073  double min_dist = FLT_MAX;
1074  double max_dist = FLT_MAX;
1075  GEOGRAPHIC_POINT closest1, closest2;
1076  LWGEOM *geoms[2];
1077  LWGEOM *result;
1078  POINT4D p1, p2;
1079  uint32_t srid = lwgeom1->srid;
1080 
1081  circ_tree1 = lwgeom_calculate_circ_tree(lwgeom1);
1082  circ_tree2 = lwgeom_calculate_circ_tree(lwgeom2);
1083 
1084  /* Quietly decrease the threshold just a little to avoid cases where */
1085  /* the actual spheroid distance is larger than the sphere distance */
1086  /* causing the return value to be larger than the threshold value */
1087  // double threshold_radians = 0.95 * threshold / spheroid->radius;
1088  double threshold_radians = threshold / spheroid->radius;
1089 
1090  circ_tree_distance_tree_internal(circ_tree1, circ_tree2, threshold_radians,
1091  &min_dist, &max_dist, &closest1, &closest2);
1092 
1093  p1.x = rad2deg(closest1.lon);
1094  p1.y = rad2deg(closest1.lat);
1095  p2.x = rad2deg(closest2.lon);
1096  p2.y = rad2deg(closest2.lat);
1097 
1098  geoms[0] = (LWGEOM *)lwpoint_make2d(srid, p1.x, p1.y);
1099  geoms[1] = (LWGEOM *)lwpoint_make2d(srid, p2.x, p2.y);
1100  result = (LWGEOM *)lwline_from_lwgeom_array(srid, 2, geoms);
1101 
1102  lwgeom_free(geoms[0]);
1103  lwgeom_free(geoms[1]);
1104  circ_tree_free(circ_tree1);
1105  circ_tree_free(circ_tree2);
1106  return result;
1107 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
LWPOINT * lwpoint_make2d(int32_t srid, double x, double y)
Definition: lwpoint.c:163
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1218
LWLINE * lwline_from_lwgeom_array(int32_t srid, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwline.c:151
#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
int32_t srid
Definition: liblwgeom.h:460
double x
Definition: liblwgeom.h:414
double y
Definition: liblwgeom.h:414
double radius
Definition: liblwgeom.h:380
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_free(), lwline_from_lwgeom_array(), lwpoint_make2d(), rad2deg, SPHEROID::radius, result, LWGEOM::srid, POINT4D::x, and POINT4D::y.

Referenced by geography_shortestline().

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