PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ geography_tree_distance()

int geography_tree_distance ( const GSERIALIZED g1,
const GSERIALIZED g2,
const SPHEROID s,
double  tolerance,
double *  distance 
)

Definition at line 290 of file geography_measurement_trees.c.

References circ_tree_distance_tree(), circ_tree_free(), CircTreePIP(), LW_SUCCESS, lwgeom_calculate_circ_tree(), lwgeom_free(), lwgeom_from_gserialized(), and lwgeom_startpoint().

Referenced by geography_distance_tree().

291 {
292  CIRC_NODE* circ_tree1 = NULL;
293  CIRC_NODE* circ_tree2 = NULL;
294  LWGEOM* lwgeom1 = NULL;
295  LWGEOM* lwgeom2 = NULL;
296  POINT4D pt1, pt2;
297 
298  lwgeom1 = lwgeom_from_gserialized(g1);
299  lwgeom2 = lwgeom_from_gserialized(g2);
300  circ_tree1 = lwgeom_calculate_circ_tree(lwgeom1);
301  circ_tree2 = lwgeom_calculate_circ_tree(lwgeom2);
302  lwgeom_startpoint(lwgeom1, &pt1);
303  lwgeom_startpoint(lwgeom2, &pt2);
304 
305  if ( CircTreePIP(circ_tree1, g1, &pt2) || CircTreePIP(circ_tree2, g2, &pt1) )
306  {
307  *distance = 0.0;
308  }
309  else
310  {
311  /* Calculate tree/tree distance */
312  *distance = circ_tree_distance_tree(circ_tree1, circ_tree2, s, tolerance);
313  }
314 
315  circ_tree_free(circ_tree1);
316  circ_tree_free(circ_tree2);
317  lwgeom_free(lwgeom1);
318  lwgeom_free(lwgeom2);
319  return LW_SUCCESS;
320 }
Note that p1 and p2 are pointers into an independent POINTARRAY, do not free them.
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int lwgeom_startpoint(const LWGEOM *lwgeom, POINT4D *pt)
Definition: lwgeom.c:1881
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
#define LW_SUCCESS
Definition: liblwgeom.h:80
double circ_tree_distance_tree(const CIRC_NODE *n1, const CIRC_NODE *n2, const SPHEROID *spheroid, double threshold)
CIRC_NODE * lwgeom_calculate_circ_tree(const LWGEOM *lwgeom)
static int CircTreePIP(const CIRC_NODE *tree1, const GSERIALIZED *g1, const POINT4D *in_point)
Datum distance(PG_FUNCTION_ARGS)
void circ_tree_free(CIRC_NODE *node)
Recurse from top of node tree and free all children.
Here is the call graph for this function:
Here is the caller graph for this function: