PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ gserialized_gist_geog_distance()

Datum gserialized_gist_geog_distance ( PG_FUNCTION_ARGS  )

Definition at line 1268 of file gserialized_gist_nd.c.

1269 {
1270  GISTENTRY *entry = (GISTENTRY *)PG_GETARG_POINTER(0);
1271  Datum query_datum = PG_GETARG_DATUM(1);
1272  StrategyNumber strategy = (StrategyNumber)PG_GETARG_UINT16(2);
1273  bool *recheck = (bool *)PG_GETARG_POINTER(4);
1274  char query_box_mem[GIDX_MAX_SIZE];
1275  GIDX *query_box = (GIDX *)query_box_mem;
1276  GIDX *entry_box;
1277  double distance;
1278 
1279  POSTGIS_DEBUGF(3, "[GIST] '%s' function called", __func__);
1280 
1281  /* We are using '13' as the gist geography distance <-> strategy number */
1282  if (strategy != 13)
1283  {
1284  elog(ERROR, "unrecognized strategy number: %d", strategy);
1285  PG_RETURN_FLOAT8(FLT_MAX);
1286  }
1287 
1288  /* Null box should never make this far. */
1289  if (gserialized_datum_get_gidx_p(query_datum, query_box) == LW_FAILURE)
1290  {
1291  POSTGIS_DEBUG(2, "[GIST] null query_gbox_index!");
1292  PG_RETURN_FLOAT8(FLT_MAX);
1293  }
1294 
1295  /* When we hit leaf nodes, it's time to turn on recheck */
1296  if (GIST_LEAF(entry))
1297  *recheck = true;
1298 
1299  /* Get the entry box */
1300  entry_box = (GIDX *)PG_DETOAST_DATUM(entry->key);
1301 
1302  /* Return distances from key-based tests should always be */
1303  /* the minimum possible distance, box-to-box */
1304  /* We scale up to "world units" so that the box-to-box distances */
1305  /* compare reasonably with the over-the-spheroid distances that */
1306  /* the recheck process will turn up */
1307  distance = WGS84_RADIUS * gidx_distance(entry_box, query_box, 0);
1308  POSTGIS_DEBUGF(2, "[GIST] '%s' got distance %g", __func__, distance);
1309 
1310  PG_RETURN_FLOAT8(distance);
1311 }
static double gidx_distance(const GIDX *a, const GIDX *b, int m_is_time)
Calculate the box->box distance.
#define LW_FAILURE
Definition: liblwgeom.h:96
#define WGS84_RADIUS
Definition: liblwgeom.h:148
static double distance(double x1, double y1, double x2, double y2)
Definition: lwtree.c:1032

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

Here is the call graph for this function: