The R-tree spatial index. More...
#include <rtree.hpp>
Public Types | |
typedef Value | value_type |
The type of Value stored in the container. | |
typedef Parameters | parameters_type |
R-tree parameters type. | |
typedef IndexableGetter | indexable_getter |
The function object extracting Indexable from Value. | |
typedef EqualTo | value_equal |
The function object comparing objects of type Value. | |
typedef Allocator | allocator_type |
The type of allocator used by the container. | |
typedef index::detail::indexable_type < detail::translator < IndexableGetter, EqualTo > >::type | indexable_type |
The Indexable type to which Value is translated. | |
typedef geometry::model::box < geometry::model::point < typename coordinate_type < indexable_type >::type, dimension< indexable_type > ::value, typename coordinate_system < indexable_type >::type > > | bounds_type |
The Box type used by the R-tree. | |
typedef allocators_type::reference | reference |
Type of reference to Value. | |
typedef allocators_type::const_reference | const_reference |
Type of reference to const Value. | |
typedef allocators_type::pointer | pointer |
Type of pointer to Value. | |
typedef allocators_type::const_pointer | const_pointer |
Type of pointer to const Value. | |
typedef allocators_type::difference_type | difference_type |
Type of difference type. | |
typedef allocators_type::size_type | size_type |
Unsigned integral type used by the container. | |
typedef index::detail::rtree::iterators::iterator < value_type, options_type, translator_type, box_type, allocators_type > | const_iterator |
Type of const iterator, category ForwardIterator. | |
typedef index::detail::rtree::iterators::query_iterator < value_type, allocators_type > | const_query_iterator |
Type of const query iterator, category ForwardIterator. | |
Public Member Functions | |
rtree (parameters_type const ¶meters=parameters_type(), indexable_getter const &getter=indexable_getter(), value_equal const &equal=value_equal()) | |
The constructor. | |
rtree (parameters_type const ¶meters, indexable_getter const &getter, value_equal const &equal, allocator_type const &allocator) | |
The constructor. | |
template<typename Iterator > | |
rtree (Iterator first, Iterator last, parameters_type const ¶meters=parameters_type(), indexable_getter const &getter=indexable_getter(), value_equal const &equal=value_equal(), allocator_type const &allocator=allocator_type()) | |
The constructor. | |
template<typename Range > | |
rtree (Range const &rng, parameters_type const ¶meters=parameters_type(), indexable_getter const &getter=indexable_getter(), value_equal const &equal=value_equal(), allocator_type const &allocator=allocator_type()) | |
The constructor. | |
~rtree () | |
The destructor. | |
rtree (rtree const &src) | |
The copy constructor. | |
rtree (rtree const &src, allocator_type const &allocator) | |
The copy constructor. | |
rtree (rtree &&src) | |
The moving constructor. | |
rtree (rtree &&src, allocator_type const &allocator) | |
The moving constructor. | |
rtree & | operator= (rtree const &src) |
The assignment operator. | |
rtree & | operator= (rtree &&src) |
The moving assignment. | |
void | swap (rtree &other) |
Swaps contents of two rtrees. | |
void | insert (value_type const &value) |
Insert a value to the index. | |
template<typename Iterator > | |
void | insert (Iterator first, Iterator last) |
Insert a range of values to the index. | |
template<typename ConvertibleOrRange > | |
void | insert (ConvertibleOrRange const &conv_or_rng) |
Insert a value created using convertible object or a range of values to the index. | |
size_type | remove (value_type const &value) |
Remove a value from the container. | |
template<typename Iterator > | |
size_type | remove (Iterator first, Iterator last) |
Remove a range of values from the container. | |
template<typename ConvertibleOrRange > | |
size_type | remove (ConvertibleOrRange const &conv_or_rng) |
Remove value corresponding to an object convertible to it or a range of values from the container. | |
template<typename Predicates , typename OutIter > | |
size_type | query (Predicates const &predicates, OutIter out_it) const |
Finds values meeting passed predicates e.g. nearest to some Point and/or intersecting some Box. | |
template<typename Predicates > | |
const_query_iterator | qbegin (Predicates const &predicates) const |
Returns a query iterator pointing at the begin of the query range. | |
const_query_iterator | qend () const |
Returns a query iterator pointing at the end of the query range. | |
const_iterator | begin () const |
Returns the iterator pointing at the begin of the rtree values range. | |
const_iterator | end () const |
Returns the iterator pointing at the end of the rtree values range. | |
size_type | size () const |
Returns the number of stored values. | |
bool | empty () const |
Query if the container is empty. | |
void | clear () |
Removes all values stored in the container. | |
bounds_type | bounds () const |
Returns the box able to contain all values stored in the container. | |
template<typename ValueOrIndexable > | |
size_type | count (ValueOrIndexable const &vori) const |
Count Values or Indexables stored in the container. | |
parameters_type | parameters () const |
Returns parameters. | |
indexable_getter | indexable_get () const |
Returns function retrieving Indexable from Value. | |
value_equal | value_eq () const |
Returns function comparing Values. | |
allocator_type | get_allocator () const |
Returns allocator used by the rtree. |
The R-tree spatial index.
This is self-balancing spatial index capable to store various types of Values and balancing algorithms.
std::pair<Indexable, T>
, boost::tuple<Indexable, ...>
and std::tuple<Indexable, ...>
when possible. For example, for Value of type std::pair<Box, int>
, the default IndexableGetter translates from std::pair<Box, int> const&
to Box const&
.true
if they are equal. It's similar to std::equal_to<>
. The default EqualTo returns the result of boost::geometry::equals()
for types adapted to some Geometry concept defined in Boost.Geometry and the result of operator==
for other types. Components of Pairs and Tuples are compared left-to-right.Value | The type of objects stored in the container. |
Parameters | Compile-time parameters. |
IndexableGetter | The function object extracting Indexable from Value. |
EqualTo | The function object comparing objects of type Value. |
Allocator | The allocator used to allocate/deallocate memory, construct/destroy nodes and Values. |
boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::rtree | ( | parameters_type const & | parameters = parameters_type() , |
indexable_getter const & | getter = indexable_getter() , |
||
value_equal const & | equal = value_equal() |
||
) | [inline, explicit] |
The constructor.
parameters | The parameters object. |
getter | The function object extracting Indexable from Value. |
equal | The function object comparing Values. |
boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::rtree | ( | parameters_type const & | parameters, |
indexable_getter const & | getter, | ||
value_equal const & | equal, | ||
allocator_type const & | allocator | ||
) | [inline] |
The constructor.
parameters | The parameters object. |
getter | The function object extracting Indexable from Value. |
equal | The function object comparing Values. |
allocator | The allocator object. |
boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::rtree | ( | Iterator | first, |
Iterator | last, | ||
parameters_type const & | parameters = parameters_type() , |
||
indexable_getter const & | getter = indexable_getter() , |
||
value_equal const & | equal = value_equal() , |
||
allocator_type const & | allocator = allocator_type() |
||
) | [inline] |
The constructor.
The tree is created using packing algorithm.
first | The beginning of the range of Values. |
last | The end of the range of Values. |
parameters | The parameters object. |
getter | The function object extracting Indexable from Value. |
equal | The function object comparing Values. |
allocator | The allocator object. |
boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::rtree | ( | Range const & | rng, |
parameters_type const & | parameters = parameters_type() , |
||
indexable_getter const & | getter = indexable_getter() , |
||
value_equal const & | equal = value_equal() , |
||
allocator_type const & | allocator = allocator_type() |
||
) | [inline, explicit] |
The constructor.
The tree is created using packing algorithm.
rng | The range of Values. |
parameters | The parameters object. |
getter | The function object extracting Indexable from Value. |
equal | The function object comparing Values. |
allocator | The allocator object. |
boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::~rtree | ( | ) | [inline] |
The destructor.
boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::rtree | ( | rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator > const & | src | ) | [inline] |
The copy constructor.
It uses parameters, translator and allocator from the source tree.
src | The rtree which content will be copied. |
boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::rtree | ( | rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator > const & | src, |
allocator_type const & | allocator | ||
) | [inline] |
The copy constructor.
It uses Parameters and translator from the source tree.
src | The rtree which content will be copied. |
allocator | The allocator which will be used. |
boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::rtree | ( | rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator > && | src | ) | [inline] |
The moving constructor.
It uses parameters, translator and allocator from the source tree.
src | The rtree which content will be moved. |
boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::rtree | ( | rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator > && | src, |
allocator_type const & | allocator | ||
) | [inline] |
The moving constructor.
It uses parameters and translator from the source tree.
src | The rtree which content will be moved. |
allocator | The allocator. |
const_iterator boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::begin | ( | ) | const [inline] |
Returns the iterator pointing at the begin of the rtree values range.
This method returns the iterator which may be used to iterate over all values stored in the rtree.
// Copy all values into the vector std::copy(tree.begin(), tree.end(), std::back_inserter(vec)); for ( Rtree::const_iterator it = tree.begin() ; it != tree.end() ; ++it ) { // do something with value } // C++11 (auto) for ( auto it = tree.begin() ; it != tree.end() ; ++it ) { // do something with value } // C++14 (generic lambda expression) std::for_each(tree.begin(), tree.end(), [](auto const& val){ // do something with value })
bounds_type boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::bounds | ( | ) | const [inline] |
Returns the box able to contain all values stored in the container.
Returns the box able to contain all values stored in the container. If the container is empty the result of geometry::assign_inverse()
is returned.
void boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::clear | ( | ) | [inline] |
Removes all values stored in the container.
size_type boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::count | ( | ValueOrIndexable const & | vori | ) | const [inline] |
Count Values or Indexables stored in the container.
For indexable_type it returns the number of values which indexables equals the parameter. For value_type it returns the number of values which equals the parameter.
vori | The value or indexable which will be counted. |
bool boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::empty | ( | ) | const [inline] |
Query if the container is empty.
const_iterator boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::end | ( | ) | const [inline] |
Returns the iterator pointing at the end of the rtree values range.
This method returns the iterator which may be compared with the iterator returned by begin() in order to check if the iteration has ended.
for ( Rtree::const_iterator it = tree.begin() ; it != tree.end() ; ++it ) { // do something with value } // C++11 (lambda expression) std::for_each(tree.begin(), tree.end(), [](value_type const& val){ // do something with value })
allocator_type boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::get_allocator | ( | ) | const [inline] |
Returns allocator used by the rtree.
indexable_getter boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::indexable_get | ( | ) | const [inline] |
Returns function retrieving Indexable from Value.
void boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::insert | ( | value_type const & | value | ) | [inline] |
Insert a value to the index.
value | The value which will be stored in the container. |
void boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::insert | ( | Iterator | first, |
Iterator | last | ||
) | [inline] |
Insert a range of values to the index.
first | The beginning of the range of values. |
last | The end of the range of values. |
void boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::insert | ( | ConvertibleOrRange const & | conv_or_rng | ) | [inline] |
Insert a value created using convertible object or a range of values to the index.
conv_or_rng | An object of type convertible to value_type or a range of values. |
rtree& boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::operator= | ( | rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator > const & | src | ) | [inline] |
The assignment operator.
It uses parameters and translator from the source tree.
src | The rtree which content will be copied. |
rtree& boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::operator= | ( | rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator > && | src | ) | [inline] |
The moving assignment.
It uses parameters and translator from the source tree.
src | The rtree which content will be moved. |
parameters_type boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::parameters | ( | ) | const [inline] |
Returns parameters.
const_query_iterator boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::qbegin | ( | Predicates const & | predicates | ) | const [inline] |
Returns a query iterator pointing at the begin of the query range.
This method returns an iterator which may be used to perform iterative queries. For the information about predicates which may be passed to this method see query().
for ( Rtree::const_query_iterator it = tree.qbegin(bgi::nearest(pt, 10000)) ; it != tree.qend() ; ++it ) { // do something with value if ( has_enough_nearest_values() ) break; } // C++11 (auto) for ( auto it = tree.qbegin(bgi::nearest(pt, 3)) ; it != tree.qend() ; ++it ) { // do something with value } // C++14 (generic lambda expression) std::for_each(tree.qbegin(bgi::nearest(pt, 3)), tree.qend(), [](auto const& val){ // do something with value });
predicates | Predicates. |
const_query_iterator boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::qend | ( | ) | const [inline] |
Returns a query iterator pointing at the end of the query range.
This method returns an iterator which may be used to check if the query has ended.
for ( Rtree::const_query_iterator it = tree.qbegin(bgi::nearest(pt, 10000)) ; it != tree.qend() ; ++it ) { // do something with value if ( has_enough_nearest_values() ) break; } // C++11 (auto) for ( auto it = tree.qbegin(bgi::nearest(pt, 3)) ; it != tree.qend() ; ++it ) { // do something with value } // C++14 (generic lambda expression) std::for_each(tree.qbegin(bgi::nearest(pt, 3)), tree.qend(), [](auto const& val){ // do something with value });
size_type boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::query | ( | Predicates const & | predicates, |
OutIter | out_it | ||
) | const [inline] |
Finds values meeting passed predicates e.g. nearest to some Point and/or intersecting some Box.
This query function performs spatial and k-nearest neighbor searches. It allows to pass a set of predicates. Values will be returned only if all predicates are met.
Spatial predicates
Spatial predicates may be generated by one of the functions listed below:
boost::geometry::index::contains()
, boost::geometry::index::covered_by()
, boost::geometry::index::covers()
, boost::geometry::index::disjoint()
, boost::geometry::index::intersects()
, boost::geometry::index::overlaps()
, boost::geometry::index::within()
,It is possible to negate spatial predicates:
! boost::geometry::index::contains()
, ! boost::geometry::index::covered_by()
, ! boost::geometry::index::covers()
, ! boost::geometry::index::disjoint()
, ! boost::geometry::index::intersects()
, ! boost::geometry::index::overlaps()
, ! boost::geometry::index::within()
Satisfies predicate
This is a special kind of predicate which allows to pass a user-defined function or function object which checks if Value should be returned by the query. It's generated by:
Nearest predicate
If the nearest predicate is passed a k-nearest neighbor search will be performed. This query will result in returning k values to the output iterator. Only one nearest predicate may be passed to the query. It may be generated by:
Connecting predicates
Predicates may be passed together connected with operator&&()
.
// return elements intersecting box tree.query(bgi::intersects(box), std::back_inserter(result)); // return elements intersecting poly but not within box tree.query(bgi::intersects(poly) && !bgi::within(box), std::back_inserter(result)); // return elements overlapping box and meeting my_fun unary predicate tree.query(bgi::overlaps(box) && bgi::satisfies(my_fun), std::back_inserter(result)); // return 5 elements nearest to pt and elements are intersecting box tree.query(bgi::nearest(pt, 5) && bgi::intersects(box), std::back_inserter(result)); // For each found value do_something (it is a type of function object) tree.query(bgi::intersects(box), boost::make_function_output_iterator(do_something())); // For each value stored in the rtree do_something // always_true is a type of function object always returning true tree.query(bgi::satisfies(always_true()), boost::make_function_output_iterator(do_something())); // C++11 (lambda expression) tree.query(bgi::intersects(box), boost::make_function_output_iterator([](value_type const& val){ // do something })); // C++14 (generic lambda expression) tree.query(bgi::intersects(box), boost::make_function_output_iterator([](auto const& val){ // do something }));
nearest()
perdicate may be passed to the query. Passing more of them results in compile-time error.predicates | Predicates. |
out_it | The output iterator, e.g. generated by std::back_inserter(). |
size_type boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::remove | ( | value_type const & | value | ) | [inline] |
Remove a value from the container.
In contrast to the std::set
or std::map erase()
method this method removes only one value from the container.
value | The value which will be removed from the container. |
size_type boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::remove | ( | Iterator | first, |
Iterator | last | ||
) | [inline] |
Remove a range of values from the container.
In contrast to the std::set
or std::map erase()
method it doesn't take iterators pointing to values stored in this container. It removes values equal to these passed as a range. Furthermore this method removes only one value for each one passed in the range, not all equal values.
first | The beginning of the range of values. |
last | The end of the range of values. |
size_type boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::remove | ( | ConvertibleOrRange const & | conv_or_rng | ) | [inline] |
Remove value corresponding to an object convertible to it or a range of values from the container.
In contrast to the std::set
or std::map erase()
method it removes values equal to these passed as a range. Furthermore, this method removes only one value for each one passed in the range, not all equal values.
conv_or_rng | The object of type convertible to value_type or a range of values. |
size_type boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::size | ( | ) | const [inline] |
Returns the number of stored values.
void boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::swap | ( | rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator > & | other | ) | [inline] |
Swaps contents of two rtrees.
Parameters, translator and allocators are swapped as well.
other | The rtree which content will be swapped with this rtree content. |
value_equal boost::geometry::index::rtree< Value, Parameters, IndexableGetter, EqualTo, Allocator >::value_eq | ( | ) | const [inline] |
Returns function comparing Values.