adapt to new rtree interface in boost geometry >= 1.56 - refs #2367

Conflicts:
	plugins/input/geojson/geojson_datasource.cpp
This commit is contained in:
Dane Springmeyer 2014-08-19 13:51:32 -07:00
parent 8c4a5d53d3
commit 29b717f9f6
4 changed files with 43 additions and 17 deletions

View file

@ -32,10 +32,6 @@
#include <boost/algorithm/string.hpp>
#include <boost/spirit/include/support_multi_pass.hpp>
#include <boost/foreach.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/extensions/index/rtree/rtree.hpp>
// mapnik
#include <mapnik/unicode.hpp>
@ -101,7 +97,11 @@ geojson_datasource::geojson_datasource(parameters const& params)
extent_(),
tr_(new mapnik::transcoder(*params.get<std::string>("encoding","utf-8"))),
features_(),
#if BOOST_VERSION >= 105600
tree_()
#else
tree_(16,1)
#endif
{
if (file_.empty()) throw mapnik::datasource_exception("GeoJSON Plugin: missing <file> parameter");
@ -139,9 +139,9 @@ geojson_datasource::geojson_datasource(parameters const& params)
bool first = true;
std::size_t count=0;
BOOST_FOREACH (mapnik::feature_ptr f, features_)
BOOST_FOREACH (mapnik::feature_ptr const& f, features_)
{
mapnik::box2d<double> const& box = f->envelope();
mapnik::box2d<double> box = f->envelope();
if (first)
{
extent_ = box;
@ -158,7 +158,11 @@ geojson_datasource::geojson_datasource(parameters const& params)
{
extent_.expand_to_include(box);
}
tree_.insert(box_type(point_type(box.minx(),box.miny()),point_type(box.maxx(),box.maxy())), count++);
#if BOOST_VERSION >= 105600
tree_.insert(std::make_pair(box_type(point_type(box.minx(),box.miny()),point_type(box.maxx(),box.maxy())),count++));
#else
tree_.insert(box_type(point_type(box.minx(),box.miny()),point_type(box.maxx(),box.maxy())),count++);
#endif
}
}
@ -213,7 +217,11 @@ mapnik::featureset_ptr geojson_datasource::features(mapnik::query const& q) cons
if (extent_.intersects(b))
{
box_type box(point_type(b.minx(),b.miny()),point_type(b.maxx(),b.maxy()));
#if BOOST_VERSION >= 105600
tree_.query(boost::geometry::index::intersects(box),std::back_inserter(index_array_));
#else
index_array_ = tree_.find(box);
#endif
return boost::make_shared<geojson_featureset>(features_, index_array_.begin(), index_array_.end());
}
// otherwise return an empty featureset pointer

View file

@ -36,11 +36,16 @@
// boost
#include <boost/optional.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/algorithms/area.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry.hpp>
#include <boost/version.hpp>
#if BOOST_VERSION >= 105600
#include <boost/geometry/index/rtree.hpp>
#else
#include <boost/geometry/extensions/index/rtree/rtree.hpp>
#endif
// stl
#include <vector>
@ -53,7 +58,14 @@ class geojson_datasource : public mapnik::datasource
public:
typedef boost::geometry::model::d2::point_xy<double> point_type;
typedef boost::geometry::model::box<point_type> box_type;
#if BOOST_VERSION >= 105600
typedef std::pair<box_type,std::size_t> item_type;
typedef boost::geometry::index::linear<16,1> linear_type;
typedef boost::geometry::index::rtree<item_type,linear_type> spatial_index_type;
#else
typedef std::size_t item_type;
typedef boost::geometry::index::rtree<box_type,std::size_t> spatial_index_type;
#endif
// constructor
geojson_datasource(mapnik::parameters const& params);
@ -74,7 +86,7 @@ private:
boost::shared_ptr<mapnik::transcoder> tr_;
std::vector<mapnik::feature_ptr> features_;
spatial_index_type tree_;
mutable std::deque<std::size_t> index_array_;
mutable std::deque<item_type> index_array_;
};

View file

@ -30,8 +30,8 @@
#include "geojson_featureset.hpp"
geojson_featureset::geojson_featureset(std::vector<mapnik::feature_ptr> const& features,
std::deque<std::size_t>::const_iterator index_itr,
std::deque<std::size_t>::const_iterator index_end)
array_type::const_iterator index_itr,
array_type::const_iterator index_end)
: features_(features),
index_itr_(index_itr),
index_end_(index_end) {}
@ -42,7 +42,12 @@ mapnik::feature_ptr geojson_featureset::next()
{
if (index_itr_ != index_end_)
{
std::size_t index = *index_itr_++;
#if BOOST_VERSION >= 105600
geojson_datasource::item_type const& item = *index_itr_++;
std::size_t index = item.second;
#else
std::size_t const& index = *index_itr_++;
#endif
if ( index < features_.size())
{
return features_.at(index);

View file

@ -11,17 +11,18 @@
class geojson_featureset : public mapnik::Featureset
{
public:
typedef std::deque<geojson_datasource::item_type> array_type;
geojson_featureset(std::vector<mapnik::feature_ptr> const& features,
std::deque<std::size_t>::const_iterator index_itr,
std::deque<std::size_t>::const_iterator index_end);
array_type::const_iterator index_itr,
array_type::const_iterator index_end);
virtual ~geojson_featureset();
mapnik::feature_ptr next();
private:
mapnik::box2d<double> box_;
std::vector<mapnik::feature_ptr> const& features_;
std::deque<std::size_t>::const_iterator index_itr_;
std::deque<std::size_t>::const_iterator index_end_;
array_type::const_iterator index_itr_;
array_type::const_iterator index_end_;
};
#endif // GEOJSON_FEATURESET_HPP