PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ geography_distance_tree()

Datum geography_distance_tree ( PG_FUNCTION_ARGS  )

Definition at line 331 of file geography_measurement.c.

332 {
333  GSERIALIZED *g1 = NULL;
334  GSERIALIZED *g2 = NULL;
335  double tolerance = 0.0;
336  double distance;
337  bool use_spheroid = true;
338  SPHEROID s;
339 
340  /* Get our geometry objects loaded into memory. */
341  g1 = PG_GETARG_GSERIALIZED_P(0);
342  g2 = PG_GETARG_GSERIALIZED_P(1);
343 
344  gserialized_error_if_srid_mismatch(g1, g2, __func__);
345 
346  /* Return zero on empty arguments. */
348  {
349  PG_FREE_IF_COPY(g1, 0);
350  PG_FREE_IF_COPY(g2, 1);
351  PG_RETURN_FLOAT8(0.0);
352  }
353 
354  /* Read our tolerance value. */
355  if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
356  tolerance = PG_GETARG_FLOAT8(2);
357 
358  /* Read our calculation type. */
359  if ( PG_NARGS() > 3 && ! PG_ARGISNULL(3) )
360  use_spheroid = PG_GETARG_BOOL(3);
361 
362  /* Initialize spheroid */
363  spheroid_init_from_srid(gserialized_get_srid(g1), &s);
364 
365  /* Set to sphere if requested */
366  if ( ! use_spheroid )
367  s.a = s.b = s.radius;
368 
369  if ( geography_tree_distance(g1, g2, &s, tolerance, &distance) == LW_FAILURE )
370  {
371  elog(ERROR, "geography_distance_tree failed!");
372  PG_RETURN_NULL();
373  }
374  /* Knock off any funny business at the nanometer level, ticket #2168 */
375  distance = round(distance * INVMINDIST) / INVMINDIST;
376 
377  PG_RETURN_FLOAT8(distance);
378 }
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:403
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:111
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: