PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ gserialized_gist_geog_distance()

Datum gserialized_gist_geog_distance ( PG_FUNCTION_ARGS  )

Definition at line 1265 of file gserialized_gist_nd.c.

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