PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ gserialized_gist_distance()

Datum gserialized_gist_distance ( PG_FUNCTION_ARGS  )

Definition at line 1229 of file gserialized_gist_nd.c.

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

Referenced by gserialized_gist_geog_distance().

1230 {
1231  GISTENTRY *entry = (GISTENTRY*) PG_GETARG_POINTER(0);
1232  StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
1233  char query_box_mem[GIDX_MAX_SIZE];
1234  GIDX *query_box = (GIDX*)query_box_mem;
1235  GIDX *entry_box;
1236 #if POSTGIS_PGSQL_VERSION >= 95
1237  bool *recheck = (bool *) PG_GETARG_POINTER(4);
1238 #endif
1239 
1240  double distance;
1241 
1242  POSTGIS_DEBUG(4, "[GIST] 'distance' function called");
1243 
1244  /* Strategy 13 is <<->> */
1245  /* Strategy 20 is |=| */
1246  if ( strategy != 13 && strategy != 20 ) {
1247  elog(ERROR, "unrecognized strategy number: %d", strategy);
1248  PG_RETURN_FLOAT8(FLT_MAX);
1249  }
1250 
1251  /* Null box should never make this far. */
1252  if ( gserialized_datum_get_gidx_p(PG_GETARG_DATUM(1), query_box) == LW_FAILURE )
1253  {
1254  POSTGIS_DEBUG(4, "[GIST] null query_gbox_index!");
1255  PG_RETURN_FLOAT8(FLT_MAX);
1256  }
1257 
1258  /* Get the entry box */
1259  entry_box = (GIDX*)DatumGetPointer(entry->key);
1260 
1261 #if POSTGIS_PGSQL_VERSION >= 95
1262 
1263  /* Strategy 20 is |=| */
1264  distance = gidx_distance(entry_box, query_box, strategy == 20);
1265 
1266  /* Treat leaf node tests different from internal nodes */
1267  if (GIST_LEAF(entry))
1268  *recheck = true;
1269 #else
1270 
1271  if ( strategy == 20 )
1272  {
1273  elog(ERROR, "You need PostgreSQL 9.5.0 or higher in order to use |=| with index");
1274  PG_RETURN_FLOAT8(FLT_MAX);
1275  }
1276 
1277  /* Treat leaf node tests different from internal nodes */
1278  if (GIST_LEAF(entry))
1279  {
1280  /* Calculate distance to leaves */
1281  distance = (double)gidx_distance_leaf_centroid(entry_box, query_box);
1282  }
1283  else
1284  {
1285  /* Calculate distance for internal nodes */
1286  distance = (double)gidx_distance_node_centroid(entry_box, query_box);
1287  }
1288 #endif
1289  PG_RETURN_FLOAT8(distance);
1290 }
static double gidx_distance_node_centroid(const GIDX *node, const GIDX *query)
#define LW_FAILURE
Definition: liblwgeom.h:64
static double gidx_distance(const GIDX *a, const GIDX *b, int m_is_time)
Calculate the box->box distance.
static double gidx_distance_leaf_centroid(const GIDX *a, const GIDX *b)
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: