Searching the Geophile Demo's Data Set
void web_demo::search(int xlo, int xhi, int ylo, int yhi,
const char* png_file_name)
{
// Locate the Geophile index for the data set.
initialize_for_search();
// Create a box representing the query region.
box* query_region = new box(xlo, xhi, ylo, yhi, 0, 0, 0);
// Do the spatial search.
GF_search_result& result =
geophile::spatial_join_1_n(*query_region, *_space, refine);
// Create image from query result.
create_png(xlo, xhi, ylo, yhi, result, png_file_name);
}
void web_demo::initialize_for_search()
{
// Create the database, overwriting an existing database
// if necessary.
_index = disk_array::open_for_read(_db_name);
// Describe the coordinate space.
int lo[] = { 0, 0 };
int hi[] = { _space_width - 1, _space_height - 1 };
GF_space_description* space_description =
new GF_space_description(2, lo, hi);
// Create the Geophile index by supplying 1) the data
// structure to be used for recording index entries, and
// 2) a description of the space.
_space = new GF_space(*_index, *space_description);
}
// This function is used to refine query results.
// It simply tests whether the query region and a box
// from the data set really overlap.
int web_demo::refine(const void* p1, const void* p2)
{
const colored_box& b1 = **(const colored_box**) p1;
const colored_box& b2 = *(const colored_box*) p2;
return b1.overlaps(b2);
}