21 #include <boost/geometry/algorithms/within.hpp> 22 #include <boost/geometry/core/access.hpp> 23 #include <boost/geometry/geometries/box.hpp> 24 #include <boost/geometry/geometries/polygon.hpp> 25 #include <boost/geometry/geometries/register/box.hpp> 29 BOOST_GEOMETRY_REGISTER_BOX_TEMPLATED(
geopop::AABBox, lower, upper)
44 template <
typename InsertIter,
typename T>
58 template <
typename InsertIter,
typename T =
typename InsertIter::container_type::value_type>
75 template <
typename Policy,
typename... F>
78 static_assert(
sizeof...(F) <= 1,
"Should have at most one functor type");
84 template <
typename Policy>
89 : m_policy(
std::forward<typename Policy::Args>(args)), m_tree(tree)
97 auto box = m_policy.GetBoundingBox();
100 if (m_policy.Contains(pt)) {
116 template <
typename Policy,
typename F>
121 :
GeoAggregator<Policy>(tree,
std::forward<typename Policy::Args&&>(args)), m_functor(
std::move(f))
139 using Args = std::tuple<geogrid_detail::KdTree2DPoint, double>;
150 constexpr
double EARTH_RADIUS_KM = 6371.0;
151 const double scaled_radius = m_radius / EARTH_RADIUS_KM;
153 const double startlon = m_center.Get<0>();
154 const double startlat = m_center.Get<1>();
177 using Args = std::tuple<double, double, double, double>;
184 return {{get<0>(m_args), get<1>(m_args)}, {get<2>(m_args), get<3>(m_args)}};
199 using Args = boost::geometry::model::polygon<Coordinate, true>;
201 explicit PolygonPolicy(boost::geometry::model::polygon<Coordinate, true> args) : m_poly(
std::move(args)) {}
205 using boost::geometry::get;
207 boost::geometry::envelope(m_poly, boostbox);
209 {get<0>(boostbox.
upper), get<1>(boostbox.
upper)}};
215 return boost::geometry::within(pt.
GetPoint(), m_poly);
std::tuple< geogrid_detail::KdTree2DPoint, double > Args
double RadianToDegree(double rad)
bool Contains(const geogrid_detail::KdTree2DPoint &pt) const
Collector< InsertIter, T > MakeCollector(const InsertIter &ins)
Build a Collector, useful for type inference.
boost::geometry::model::polygon< Coordinate, true > Args
AxisAlignedBoundingBox (hyperrectangle defined by lower and upper bound for every dimension)...
bool InRadius(const KdTree2DPoint &start, double radius) const
Does the point lie within radius km from start?
const Location * GetLocation() const
Retrieve the location.
Coordinate GetPoint() const
Get the coordinate for this Location.
void operator()(F f)
Aggregate over the area specified by the policy with the functor f.
const KdTree< geogrid_detail::KdTree2DPoint > & m_tree
A GeoAggregator can either be instantiated with a functor, or be called with one every time...
PolygonPolicy(boost::geometry::model::polygon< Coordinate, true > args)
AABBox< geogrid_detail::KdTree2DPoint > GetBoundingBox() const
Aggregates into a vector that must should remain alive for the usage duration of the Collector...
Namespace for the geographic and demograhic classes.
bool Contains(const geogrid_detail::KdTree2DPoint &) const
P lower
The lower bound for every dimension.
Collector(const InsertIter &ins)
P upper
The upper bound for every dimension.
InsertIter m_ins
The (back_)insert_iterator that receives new elements.
KdTree for some more information on methods.
bool Contains(const geogrid_detail::KdTree2DPoint &pt) const
void operator()(T elem)
Collect a new element.
void operator()()
Aggregate over the policy with the functor specified at construction time.
double DegreeToRadian(double deg)
AABBox< geogrid_detail::KdTree2DPoint > GetBoundingBox() const
GeoAggregator Policy that aggregates locations within a radius (in km) of a center point...
geogrid_detail::KdTree2DPoint m_center
A GeoAggregator Policy that aggregates over a (clockwise) polygon.
GeoAggregator(const KdTree< geogrid_detail::KdTree2DPoint > &tree, typename Policy::Args &&args)
std::tuple< double, double, double, double > Args
lon1, lat1, lon2, lat2
GeoAggregator Policy that aggregates over an axis aligned bounding box.
GeoAggregator(const KdTree< geogrid_detail::KdTree2DPoint > &tree, F f, typename Policy::Args &&args)
AABBox< geogrid_detail::KdTree2DPoint > GetBoundingBox() const