PostGIS  2.5.2dev-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 271 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(), and geography_distance_tree().

272 {
273  CIRC_NODE* circ_tree1 = NULL;
274  CIRC_NODE* circ_tree2 = NULL;
275  LWGEOM* lwgeom1 = NULL;
276  LWGEOM* lwgeom2 = NULL;
277  POINT4D pt1, pt2;
278 
279  lwgeom1 = lwgeom_from_gserialized(g1);
280  lwgeom2 = lwgeom_from_gserialized(g2);
281  circ_tree1 = lwgeom_calculate_circ_tree(lwgeom1);
282  circ_tree2 = lwgeom_calculate_circ_tree(lwgeom2);
283  lwgeom_startpoint(lwgeom1, &pt1);
284  lwgeom_startpoint(lwgeom2, &pt2);
285 
286  if ( CircTreePIP(circ_tree1, g1, &pt2) || CircTreePIP(circ_tree2, g2, &pt1) )
287  {
288  *distance = 0.0;
289  }
290  else
291  {
292  /* Calculate tree/tree distance */
293  *distance = circ_tree_distance_tree(circ_tree1, circ_tree2, s, tolerance);
294  }
295 
296  circ_tree_free(circ_tree1);
297  circ_tree_free(circ_tree2);
298  lwgeom_free(lwgeom1);
299  lwgeom_free(lwgeom2);
300  return LW_SUCCESS;
301 }
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:2115
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define LW_SUCCESS
Definition: liblwgeom.h:79
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: