PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ geography_distance_tree()

Datum geography_distance_tree ( PG_FUNCTION_ARGS  )

Definition at line 338 of file geography_measurement.c.

339 {
340  GSERIALIZED *g1 = NULL;
341  GSERIALIZED *g2 = NULL;
342  double tolerance = 0.0;
343  double distance;
344  bool use_spheroid = true;
345  SPHEROID s;
346 
347  /* Get our geometry objects loaded into memory. */
348  g1 = PG_GETARG_GSERIALIZED_P(0);
349  g2 = PG_GETARG_GSERIALIZED_P(1);
350 
351  gserialized_error_if_srid_mismatch(g1, g2, __func__);
352 
353  /* Return zero on empty arguments. */
355  {
356  PG_FREE_IF_COPY(g1, 0);
357  PG_FREE_IF_COPY(g2, 1);
358  PG_RETURN_FLOAT8(0.0);
359  }
360 
361  /* Read our tolerance value. */
362  if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
363  tolerance = PG_GETARG_FLOAT8(2);
364 
365  /* Read our calculation type. */
366  if ( PG_NARGS() > 3 && ! PG_ARGISNULL(3) )
367  use_spheroid = PG_GETARG_BOOL(3);
368 
369  /* Initialize spheroid */
370  spheroid_init_from_srid(fcinfo, gserialized_get_srid(g1), &s);
371 
372  /* Set to sphere if requested */
373  if ( ! use_spheroid )
374  s.a = s.b = s.radius;
375 
376  if ( geography_tree_distance(g1, g2, &s, tolerance, &distance) == LW_FAILURE )
377  {
378  elog(ERROR, "geography_distance_tree failed!");
379  PG_RETURN_NULL();
380  }
381 
382  /* Knock off any funny business at the nanometer level, ticket #2168 */
383  distance = round(distance * INVMINDIST) / INVMINDIST;
384 
385  PG_RETURN_FLOAT8(distance);
386 }
char * s
Definition: cu_in_wkt.c:23
#define INVMINDIST
int geography_tree_distance(const GSERIALIZED *g1, const GSERIALIZED *g2, const SPHEROID *s, double tolerance, double *distance)
void gserialized_error_if_srid_mismatch(const GSERIALIZED *g1, const GSERIALIZED *g2, const char *funcname)
Definition: gserialized.c:404
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: gserialized.c:126
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: gserialized.c:152
#define LW_FAILURE
Definition: liblwgeom.h:110
static double distance(double x1, double y1, double x2, double y2)
Definition: lwtree.c:1032

References distance(), geography_tree_distance(), gserialized_error_if_srid_mismatch(), gserialized_get_srid(), gserialized_is_empty(), INVMINDIST, LW_FAILURE, and s.

Here is the call graph for this function: