1530 GISTENTRY *entry = (GISTENTRY*) PG_GETARG_POINTER(0);
1531 StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
1532 char query_box_mem[GIDX_MAX_SIZE];
1533 GIDX *query_box = (GIDX*)query_box_mem;
1535 #if POSTGIS_PGSQL_VERSION >= 95 1536 bool *recheck = (
bool *) PG_GETARG_POINTER(4);
1541 POSTGIS_DEBUG(4,
"[GIST] 'distance' function called");
1545 if ( strategy != 13 && strategy != 20 ) {
1546 elog(ERROR,
"unrecognized strategy number: %d", strategy);
1547 PG_RETURN_FLOAT8(FLT_MAX);
1551 if ( gserialized_datum_get_gidx_p(PG_GETARG_DATUM(1), query_box) ==
LW_FAILURE )
1553 POSTGIS_DEBUG(4,
"[GIST] null query_gbox_index!");
1554 PG_RETURN_FLOAT8(FLT_MAX);
1558 entry_box = (GIDX*)DatumGetPointer(entry->key);
1560 #if POSTGIS_PGSQL_VERSION >= 95 1563 distance =
gidx_distance(entry_box, query_box, strategy == 20);
1566 if (GIST_LEAF(entry))
1570 if ( strategy == 20 )
1572 elog(ERROR,
"You need PostgreSQL 9.5.0 or higher in order to use |=| with index");
1573 PG_RETURN_FLOAT8(FLT_MAX);
1577 if (GIST_LEAF(entry))
1580 distance = (double)gidx_distance_leaf_centroid(entry_box, query_box);
1585 distance = (double)gidx_distance_node_centroid(entry_box, query_box);
1588 PG_RETURN_FLOAT8(distance);
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)