PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ gserialized_gist_distance()

Datum gserialized_gist_distance ( PG_FUNCTION_ARGS  )

Definition at line 1529 of file gserialized_gist_nd.c.

1530 {
1531  GISTENTRY *entry = (GISTENTRY*) PG_GETARG_POINTER(0);
1532  StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
1533  char query_box_mem[GIDX_MAX_SIZE];
1534  GIDX *query_box = (GIDX*)query_box_mem;
1535  GIDX *entry_box;
1536 #if POSTGIS_PGSQL_VERSION >= 95
1537  bool *recheck = (bool *) PG_GETARG_POINTER(4);
1538 #endif
1539 
1540  double distance;
1541 
1542  POSTGIS_DEBUG(4, "[GIST] 'distance' function called");
1543 
1544  /* Strategy 13 is <<->> */
1545  /* Strategy 20 is |=| */
1546  if ( strategy != 13 && strategy != 20 ) {
1547  elog(ERROR, "unrecognized strategy number: %d", strategy);
1548  PG_RETURN_FLOAT8(FLT_MAX);
1549  }
1550 
1551  /* Null box should never make this far. */
1552  if ( gserialized_datum_get_gidx_p(PG_GETARG_DATUM(1), query_box) == LW_FAILURE )
1553  {
1554  POSTGIS_DEBUG(4, "[GIST] null query_gbox_index!");
1555  PG_RETURN_FLOAT8(FLT_MAX);
1556  }
1557 
1558  /* Get the entry box */
1559  entry_box = (GIDX*)DatumGetPointer(entry->key);
1560 
1561 #if POSTGIS_PGSQL_VERSION >= 95
1562 
1563  /* Strategy 20 is |=| */
1564  distance = gidx_distance(entry_box, query_box, strategy == 20);
1565 
1566  /* Treat leaf node tests different from internal nodes */
1567  if (GIST_LEAF(entry))
1568  *recheck = true;
1569 #else
1570 
1571  if ( strategy == 20 )
1572  {
1573  elog(ERROR, "You need PostgreSQL 9.5.0 or higher in order to use |=| with index");
1574  PG_RETURN_FLOAT8(FLT_MAX);
1575  }
1576 
1577  /* Treat leaf node tests different from internal nodes */
1578  if (GIST_LEAF(entry))
1579  {
1580  /* Calculate distance to leaves */
1581  distance = (double)gidx_distance_leaf_centroid(entry_box, query_box);
1582  }
1583  else
1584  {
1585  /* Calculate distance for internal nodes */
1586  distance = (double)gidx_distance_node_centroid(entry_box, query_box);
1587  }
1588 #endif
1589  PG_RETURN_FLOAT8(distance);
1590 }
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
Datum distance(PG_FUNCTION_ARGS)

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

Here is the call graph for this function: