void spatial_index<Value, Filter, InputStream, BBox>::query_first_n(Filter const& filter, InputStream& in, std::vector<Value>& results, std::size_t count) { static_assert(std::is_standard_layout<Value>::value, "Values stored in quad-tree must be standard layout type"); if (!check_spatial_index(in)) throw std::runtime_error("Invalid index file (regenerate with shapeindex)"); in.seekg(16, std::ios::beg); query_first_n_impl(filter, in, results, count); }
void spatial_index<Value, Filter, InputStream, BBox>::query_first_n_impl(Filter const& filter, InputStream& in, std::vector<Value>& results, std::size_t count) { if (results.size() == count) return; int offset = read_ndr_integer(in); typename spatial_index<Value, Filter, InputStream, BBox>::bbox_type node_ext; read_envelope(in, node_ext); int num_shapes = read_ndr_integer(in); if (!filter.pass(node_ext)) { in.seekg(offset + num_shapes * sizeof(Value) + 4, std::ios::cur); return; } for (int i = 0; i < num_shapes; ++i) { Value item; in.read(reinterpret_cast<char*>(&item), sizeof(Value)); if (results.size() < count) results.push_back(std::move(item)); } int children = read_ndr_integer(in); for (int j = 0; j < children; ++j) { query_first_n_impl(filter, in, results, count); } }
void spatial_index<Value, Filter, InputStream>::query_first_n(Filter const& filter, InputStream& in, std::vector<Value>& results, std::size_t count) { if (!check_header(in)) throw std::runtime_error("Invalid index file (regenerate with shapeindex)"); in.seekg(16, std::ios::beg); query_first_n_impl(filter, in, results, count); }