PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ gserialized_gist_geog_distance()

Datum gserialized_gist_geog_distance ( PG_FUNCTION_ARGS  )

Definition at line 1459 of file gserialized_gist_nd.c.

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

Referenced by gserialized_gist_same().

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