PostGIS  3.4.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 1070 of file lwgeodetic_tree.c.

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