I am a asked to write a function that takes a "LatLon" as input (LatLon is a class with 2 doubles: latitude and longitude) and returns the the ID (int) of the closest intersection to that position. I am given functions that return the location of any intersection, and also that return the distance between two positions. Because of "performance tests", my instructors have suggested me to store the locations of all Intersections in a R-Tree (from the boost library), where it would be faster to find the closest intersection, rather than iterating over all the intersections. However, I am just learning how R-Trees work, and I am having trouble in how to create one.
The problem is that I have seen several examples online where they create R-Trees, but what really confuses me is that they only use two arguments, rather than four, in one of the constructors. For example, they use:
bgi::rtree< value_t, bgi::quadratic<16> > rtree_;
where value_t is a pair of box and unsigned int, and the other argument is the size, however if I try to make:
bgi::rtree< point, bgi::quadratic<16>> intersectionRTree;
where point is a pair of unsigned int and LatLon, the compiler complains that i am not using the proper constructor, and that it should have four arguments instead of two.
I have read online, and find that I should be using this constructor:
rtree(parameters_type const &, indexable_getter const &, value_equal const &, allocator_type const &)
However, I don't understand the description of each argument, so I don't know how to use this constructor. So, can you please help me to understand what to do? And if possible, could you give me short example? Thank you very much.
This is the LatLon class. It is read only, so I cannot modify it:
class LatLon{
public:
LatLon(){}
explicit LatLon(float lat_, float lon_) : m_lat(lat_),m_lon(lon_){}
double lat() const { return m_lat; }
double lon() const { return m_lon; }
private:
float m_lat = std::numeric_limits<float>::quiet_NaN();
float m_lon = std::numeric_limits<float>::quiet_NaN();
friend class boost::serialization::access;
template<class Archive>void serialize(Archive& ar, unsigned int)
{ ar & m_lat & m_lon; }
};
std::ostream& operator<<(std::ostream& os,LatLon);
std::array<LatLon,4> bounds_to_corners(std::pair<LatLon,LatLon> bounds);
This is why I am trying to do:
#include "LatLon.h"
#include <string>
#include <vector>
#include <cmath>
#include <boost/geometry.hpp>
#include <boost/geometry/index/rtree.hpp>
#include <algorithm>
namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;
using namespace std;
typedef pair<unsigned,LatLon> point;
bgi::rtree<point, bgi::quadratic<16>> intersectionRTree;
for (unsigned intersection = 0; intersection < intersectionNumber; intersection++)
{point intP = make_pair(intersection,getIntersectionPosition(intersection));
intersectionRTree.insert(intP);}
The function getIntersectionPosition returns a LatLon, intersectionNumber is the maximum number of intersections, and intersection is the index of a intersection.
The compiler gives me along error detail that only sends me to another files, but actually never tolds me where I am wrong.