PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ gserialized_gist_distance()

Datum gserialized_gist_distance ( PG_FUNCTION_ARGS  )

Definition at line 1528 of file gserialized_gist_nd.c.

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

Referenced by gserialized_gist_geog_distance().

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