PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ geography_distance_tree()

Datum geography_distance_tree ( PG_FUNCTION_ARGS  )

Definition at line 330 of file geography_measurement.c.

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