PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ gserialized_gist_geog_distance()

Datum gserialized_gist_geog_distance ( PG_FUNCTION_ARGS  )

Definition at line 1460 of file gserialized_gist_nd.c.

1461 {
1462  GISTENTRY *entry = (GISTENTRY*) PG_GETARG_POINTER(0);
1463  Datum query_datum = PG_GETARG_DATUM(1);
1464  StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
1465 #if POSTGIS_PGSQL_VERSION >= 95
1466  bool *recheck = (bool *) PG_GETARG_POINTER(4);
1467 #endif
1468  char query_box_mem[GIDX_MAX_SIZE];
1469  GIDX *query_box = (GIDX*)query_box_mem;
1470  GIDX *entry_box;
1471  double distance;
1472 
1473  POSTGIS_DEBUGF(3, "[GIST] '%s' function called", __func__);
1474 
1475  /* We are using '13' as the gist geography distance <-> strategy number */
1476  if ( strategy != 13 )
1477  {
1478  elog(ERROR, "unrecognized strategy number: %d", strategy);
1479  PG_RETURN_FLOAT8(FLT_MAX);
1480  }
1481 
1482  /* Null box should never make this far. */
1483  if ( gserialized_datum_get_gidx_p(query_datum, query_box) == LW_FAILURE )
1484  {
1485  POSTGIS_DEBUG(2, "[GIST] null query_gbox_index!");
1486  PG_RETURN_FLOAT8(FLT_MAX);
1487  }
1488 
1489 #if POSTGIS_PGSQL_VERSION >= 95
1490  /* When we hit leaf nodes, it's time to turn on recheck */
1491  if (GIST_LEAF(entry))
1492  {
1493  *recheck = true;
1494  }
1495 #endif
1496 
1497  /* Get the entry box */
1498  entry_box = (GIDX*)DatumGetPointer(entry->key);
1499 
1500  /* Return distances from key-based tests should always be */
1501  /* the minimum possible distance, box-to-box */
1502  /* We scale up to "world units" so that the box-to-box distances */
1503  /* compare reasonably with the over-the-spheroid distances that */
1504  /* the recheck process will turn up */
1505  distance = WGS84_RADIUS * gidx_distance(entry_box, query_box, 0);
1506  POSTGIS_DEBUGF(2, "[GIST] '%s' got distance %g", __func__, distance);
1507 
1508  PG_RETURN_FLOAT8(distance);
1509 }
static double gidx_distance(const GIDX *a, const GIDX *b, int m_is_time)
Calculate the centroid->centroid distance between the boxes.
#define LW_FAILURE
Definition: liblwgeom.h:79
#define WGS84_RADIUS
Definition: liblwgeom.h:131
Datum distance(PG_FUNCTION_ARGS)

References distance(), gidx_distance(), LW_FAILURE, and WGS84_RADIUS.

Here is the call graph for this function: