1
// Boost.Geometry Index
3
// Spatial query predicates
5
// Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
7
// Use, modification and distribution is subject to the Boost Software License,
8
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9
// http://www.boost.org/LICENSE_1_0.txt)
11
#ifndef BOOST_GEOMETRY_INDEX_PREDICATES_HPP
12
#define BOOST_GEOMETRY_INDEX_PREDICATES_HPP
15
#include <boost/tuple/tuple.hpp>
16
#include <boost/mpl/assert.hpp>
18
#include <boost/geometry/index/detail/predicates.hpp>
19
#include <boost/geometry/index/detail/tuples.hpp>
22
\defgroup predicates Predicates (boost::geometry::index::)
25
namespace boost { namespace geometry { namespace index {
27
#ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
30
\brief Generate \c contains() predicate.
32
Generate a predicate defining Value and Geometry relationship.
33
Value will be returned by the query if <tt>bg::within(Geometry, Indexable)</tt>
38
bgi::query(spatial_index, bgi::contains(box), std::back_inserter(result));
43
\tparam Geometry The Geometry type.
45
\param g The Geometry object.
47
template <typename Geometry> inline
48
detail::spatial_predicate<Geometry, detail::contains_tag, false>
49
contains(Geometry const& g)
51
return detail::spatial_predicate<Geometry, detail::contains_tag, false>(g);
54
#endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
57
\brief Generate \c covered_by() predicate.
59
Generate a predicate defining Value and Geometry relationship.
60
Value will be returned by the query if <tt>bg::covered_by(Indexable, Geometry)</tt>
65
bgi::query(spatial_index, bgi::covered_by(box), std::back_inserter(result));
70
\tparam Geometry The Geometry type.
72
\param g The Geometry object.
74
template <typename Geometry> inline
75
detail::spatial_predicate<Geometry, detail::covered_by_tag, false>
76
covered_by(Geometry const& g)
78
return detail::spatial_predicate<Geometry, detail::covered_by_tag, false>(g);
81
#ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
84
\brief Generate \c covers() predicate.
86
Generate a predicate defining Value and Geometry relationship.
87
Value will be returned by the query if <tt>bg::covered_by(Geometry, Indexable)</tt>
92
bgi::query(spatial_index, bgi::covers(box), std::back_inserter(result));
97
\tparam Geometry The Geometry type.
99
\param g The Geometry object.
101
template <typename Geometry> inline
102
detail::spatial_predicate<Geometry, detail::covers_tag, false>
103
covers(Geometry const& g)
105
return detail::spatial_predicate<Geometry, detail::covers_tag, false>(g);
108
#endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
111
\brief Generate \c disjoint() predicate.
113
Generate a predicate defining Value and Geometry relationship.
114
Value will be returned by the query if <tt>bg::disjoint(Indexable, Geometry)</tt>
119
bgi::query(spatial_index, bgi::disjoint(box), std::back_inserter(result));
124
\tparam Geometry The Geometry type.
126
\param g The Geometry object.
128
template <typename Geometry> inline
129
detail::spatial_predicate<Geometry, detail::disjoint_tag, false>
130
disjoint(Geometry const& g)
132
return detail::spatial_predicate<Geometry, detail::disjoint_tag, false>(g);
136
\brief Generate \c intersects() predicate.
138
Generate a predicate defining Value and Geometry relationship.
139
Value will be returned by the query if <tt>bg::intersects(Indexable, Geometry)</tt>
144
bgi::query(spatial_index, bgi::intersects(box), std::back_inserter(result));
145
bgi::query(spatial_index, bgi::intersects(ring), std::back_inserter(result));
146
bgi::query(spatial_index, bgi::intersects(polygon), std::back_inserter(result));
151
\tparam Geometry The Geometry type.
153
\param g The Geometry object.
155
template <typename Geometry> inline
156
detail::spatial_predicate<Geometry, detail::intersects_tag, false>
157
intersects(Geometry const& g)
159
return detail::spatial_predicate<Geometry, detail::intersects_tag, false>(g);
163
\brief Generate \c overlaps() predicate.
165
Generate a predicate defining Value and Geometry relationship.
166
Value will be returned by the query if <tt>bg::overlaps(Indexable, Geometry)</tt>
171
bgi::query(spatial_index, bgi::overlaps(box), std::back_inserter(result));
176
\tparam Geometry The Geometry type.
178
\param g The Geometry object.
180
template <typename Geometry> inline
181
detail::spatial_predicate<Geometry, detail::overlaps_tag, false>
182
overlaps(Geometry const& g)
184
return detail::spatial_predicate<Geometry, detail::overlaps_tag, false>(g);
187
#ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
190
\brief Generate \c touches() predicate.
192
Generate a predicate defining Value and Geometry relationship.
193
Value will be returned by the query if <tt>bg::touches(Indexable, Geometry)</tt>
198
\tparam Geometry The Geometry type.
200
\param g The Geometry object.
202
template <typename Geometry> inline
203
detail::spatial_predicate<Geometry, detail::touches_tag, false>
204
touches(Geometry const& g)
206
return detail::spatial_predicate<Geometry, detail::touches_tag, false>(g);
209
#endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
212
\brief Generate \c within() predicate.
214
Generate a predicate defining Value and Geometry relationship.
215
Value will be returned by the query if <tt>bg::within(Indexable, Geometry)</tt>
220
bgi::query(spatial_index, bgi::within(box), std::back_inserter(result));
225
\tparam Geometry The Geometry type.
227
\param g The Geometry object.
229
template <typename Geometry> inline
230
detail::spatial_predicate<Geometry, detail::within_tag, false>
231
within(Geometry const& g)
233
return detail::spatial_predicate<Geometry, detail::within_tag, false>(g);
237
\brief Generate satisfies() predicate.
239
A wrapper around user-defined UnaryPredicate checking if Value should be returned by spatial query.
243
bool is_red(Value const& v) { return v.is_red(); }
246
template <typename Value> bool operator()(Value const& v) { return v.is_red(); }
251
rt.query(index::intersects(box) && index::satisfies(is_red),
252
std::back_inserter(result));
254
rt.query(index::intersects(box) && index::satisfies(is_red_o()),
255
std::back_inserter(result));
257
#ifndef BOOST_NO_CXX11_LAMBDAS
258
rt.query(index::intersects(box) && index::satisfies([](Value const& v) { return v.is_red(); }),
259
std::back_inserter(result));
265
\tparam UnaryPredicate A type of unary predicate function or function object.
267
\param pred The unary predicate function or function object.
269
template <typename UnaryPredicate> inline
270
detail::satisfies<UnaryPredicate, false>
271
satisfies(UnaryPredicate const& pred)
273
return detail::satisfies<UnaryPredicate, false>(pred);
277
\brief Generate nearest() predicate.
279
When nearest predicate is passed to the query, k-nearest neighbour search will be performed.
280
\c nearest() predicate takes a \c Point from which distance to \c Values is calculated
281
and the maximum number of \c Values that should be returned.
285
bgi::query(spatial_index, bgi::nearest(pt, 5), std::back_inserter(result));
286
bgi::query(spatial_index, bgi::nearest(pt, 5) && bgi::intersects(box), std::back_inserter(result));
290
Only one \c nearest() predicate may be used in a query.
294
\param point The point from which distance is calculated.
295
\param k The maximum number of values to return.
297
template <typename Point> inline
298
detail::nearest<Point>
299
nearest(Point const& point, unsigned k)
301
return detail::nearest<Point>(point, k);
304
#ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
307
\brief Generate path() predicate.
309
When path predicate is passed to the query, the returned values are k values along the path closest to
310
its begin. \c path() predicate takes a \c Segment or a \c Linestring defining the path and the maximum
311
number of \c Values that should be returned.
315
bgi::query(spatial_index, bgi::path(segment, 5), std::back_inserter(result));
316
bgi::query(spatial_index, bgi::path(linestring, 5) && bgi::intersects(box), std::back_inserter(result));
320
Only one distance predicate (\c nearest() or \c path()) may be used in a query.
324
\param linestring The path along which distance is calculated.
325
\param k The maximum number of values to return.
327
template <typename SegmentOrLinestring> inline
328
detail::path<SegmentOrLinestring>
329
path(SegmentOrLinestring const& linestring, unsigned k)
331
return detail::path<SegmentOrLinestring>(linestring, k);
334
#endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
338
// operator! generators
340
template <typename Fun, bool Negated> inline
341
satisfies<Fun, !Negated>
342
operator!(satisfies<Fun, Negated> const& p)
344
return satisfies<Fun, !Negated>(p);
347
template <typename Geometry, typename Tag, bool Negated> inline
348
spatial_predicate<Geometry, Tag, !Negated>
349
operator!(spatial_predicate<Geometry, Tag, Negated> const& p)
351
return spatial_predicate<Geometry, Tag, !Negated>(p.geometry);
354
// operator&& generators
356
template <typename Pred1, typename Pred2> inline
359
boost::tuples::cons<Pred2, boost::tuples::null_type>
361
operator&&(Pred1 const& p1, Pred2 const& p2)
363
/*typedef typename boost::mpl::if_c<is_predicate<Pred1>::value, Pred1, Pred1 const&>::type stored1;
364
typedef typename boost::mpl::if_c<is_predicate<Pred2>::value, Pred2, Pred2 const&>::type stored2;*/
365
namespace bt = boost::tuples;
368
bt::cons< Pred1, bt::cons<Pred2, bt::null_type> >
369
( p1, bt::cons<Pred2, bt::null_type>(p2, bt::null_type()) );
372
template <typename Head, typename Tail, typename Pred> inline
373
typename tuples::push_back_impl<
374
boost::tuples::cons<Head, Tail>,
377
boost::tuples::length<boost::tuples::cons<Head, Tail> >::value
379
operator&&(boost::tuples::cons<Head, Tail> const& t, Pred const& p)
381
//typedef typename boost::mpl::if_c<is_predicate<Pred>::value, Pred, Pred const&>::type stored;
382
namespace bt = boost::tuples;
385
tuples::push_back_impl<
386
bt::cons<Head, Tail>, Pred, 0, bt::length< bt::cons<Head, Tail> >::value
390
} // namespace detail
392
}}} // namespace boost::geometry::index
394
#endif // BOOST_GEOMETRY_INDEX_PREDICATES_HPP