PostGIS  2.2.8dev-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 252 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().

253 {
254  CIRC_NODE* circ_tree1 = NULL;
255  CIRC_NODE* circ_tree2 = NULL;
256  LWGEOM* lwgeom1 = NULL;
257  LWGEOM* lwgeom2 = NULL;
258  POINT4D pt1, pt2;
259 
260  lwgeom1 = lwgeom_from_gserialized(g1);
261  lwgeom2 = lwgeom_from_gserialized(g2);
262  circ_tree1 = lwgeom_calculate_circ_tree(lwgeom1);
263  circ_tree2 = lwgeom_calculate_circ_tree(lwgeom2);
264  lwgeom_startpoint(lwgeom1, &pt1);
265  lwgeom_startpoint(lwgeom2, &pt2);
266 
267  if ( CircTreePIP(circ_tree1, g1, &pt2) || CircTreePIP(circ_tree2, g2, &pt1) )
268  {
269  *distance = 0.0;
270  }
271  else
272  {
273  /* Calculate tree/tree distance */
274  *distance = circ_tree_distance_tree(circ_tree1, circ_tree2, s, tolerance);
275  }
276 
277  circ_tree_free(circ_tree1);
278  circ_tree_free(circ_tree2);
279  lwgeom_free(lwgeom1);
280  lwgeom_free(lwgeom2);
281  return LW_SUCCESS;
282 }
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:1837
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
#define LW_SUCCESS
Definition: liblwgeom.h:65
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: