PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum gserialized_gist_distance_2d ( PG_FUNCTION_ARGS  )

Definition at line 1065 of file gserialized_gist_2d.c.

References box2df_distance(), box2df_distance_leaf_centroid(), box2df_distance_node_centroid(), distance(), gserialized_datum_get_box2df_p(), LW_FAILURE, and MAXFLOAT.

1066 {
1067  GISTENTRY *entry = (GISTENTRY*) PG_GETARG_POINTER(0);
1068  BOX2DF query_box;
1069  BOX2DF *entry_box;
1070  StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
1071  double distance;
1072 
1073  POSTGIS_DEBUG(4, "[GIST] 'distance' function called");
1074 
1075  /* We are using '13' as the gist distance-betweeen-centroids strategy number
1076  * and '14' as the gist distance-between-boxes strategy number */
1077  if ( strategy != 13 && strategy != 14 ) {
1078  elog(ERROR, "unrecognized strategy number: %d", strategy);
1079  PG_RETURN_FLOAT8(MAXFLOAT);
1080  }
1081 
1082  /* Null box should never make this far. */
1083  if ( gserialized_datum_get_box2df_p(PG_GETARG_DATUM(1), &query_box) == LW_FAILURE )
1084  {
1085  POSTGIS_DEBUG(4, "[GIST] null query_gbox_index!");
1086  PG_RETURN_FLOAT8(MAXFLOAT);
1087  }
1088 
1089  /* Get the entry box */
1090  entry_box = (BOX2DF*)DatumGetPointer(entry->key);
1091 
1092  /* Box-style distance test */
1093  if ( strategy == 14 )
1094  {
1095  distance = (double)box2df_distance(entry_box, &query_box);
1096  PG_RETURN_FLOAT8(distance);
1097  }
1098 
1099  /* Treat leaf node tests different from internal nodes */
1100  if (GIST_LEAF(entry))
1101  {
1102  /* Calculate distance to leaves */
1103  distance = (double)box2df_distance_leaf_centroid(entry_box, &query_box);
1104  }
1105  else
1106  {
1107  /* Calculate distance for internal nodes */
1108  distance = (double)box2df_distance_node_centroid(entry_box, &query_box);
1109  }
1110 
1111  PG_RETURN_FLOAT8(distance);
1112 }
static double box2df_distance_node_centroid(const BOX2DF *node, const BOX2DF *query)
Calculate the The node_box_edge->query_centroid distance between the boxes.
#define LW_FAILURE
Definition: liblwgeom.h:54
static double box2df_distance(const BOX2DF *a, const BOX2DF *b)
Calculate the box->box distance.
static double box2df_distance_leaf_centroid(const BOX2DF *a, const BOX2DF *b)
Calculate the centroid->centroid distance between the boxes.
static int gserialized_datum_get_box2df_p(Datum gsdatum, BOX2DF *box2df)
Peak into a GSERIALIZED datum to find the bounding box.
Datum distance(PG_FUNCTION_ARGS)
#define MAXFLOAT
Largest float value.

Here is the call graph for this function: