// example file to test boost.
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/index/rtree.hpp>
// to store queries results
#include <vector>
// just for output
#include <boost/foreach.hpp>
#include <iostream>
namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;
// If we use geographic coordinate system, the left edge middle point query
// returns vector with 0 element.
//
// If we use geographic coordinate system, the left edge middle point query
// returns vector with 1 element.
//
// typedef bg::model::point<double, 2, bg::cs::cartesian> point;
typedef bg::model::point<double, 2, bg::cs::geographic<bg::degree>> point;
typedef bg::model::box<point> box;
typedef std::pair<box, unsigned> value;
int main(int argc, char* argv[]) {
// create the rtree using default constructor
bgi::rtree<value, bgi::quadratic<16>> rtree;
point sw(-122.18, 37.38), ne(-122.16, 37.39);
box b(sw, ne);
rtree.insert(std::make_pair(b, 1));
point check_point(-122.18, 37.385);
std::vector<value> result_s;
rtree.query(
boost::geometry::index::covers(check_point),
std::back_inserter(result_s));
// display results
std::cout << "spatial query point:" << std::endl;
std::cout << check_point.get<0>() << ", " << check_point.get<1>()
<< std::endl;
std::cout << "spatial query result:" << std::endl;
BOOST_FOREACH (value const& v, result_s)
std::cout << bg::wkt<box>(v.first) << " - " << v.second << std::endl;
return 0;
}