adapt to new rtree interface in boost geometry >= 1.56 - refs #2367
This commit is contained in:
parent
d62365cd64
commit
f939a8f8e7
4 changed files with 42 additions and 16 deletions
|
@ -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>
|
||||
|
@ -103,7 +99,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");
|
||||
|
||||
|
@ -141,7 +141,7 @@ geojson_datasource::geojson_datasource(parameters const& params)
|
|||
}
|
||||
|
||||
bool first = true;
|
||||
std::size_t count=0;
|
||||
std::size_t count = 0;
|
||||
BOOST_FOREACH (mapnik::feature_ptr const& f, features_)
|
||||
{
|
||||
mapnik::box2d<double> box = f->envelope();
|
||||
|
@ -161,7 +161,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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,7 +220,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
|
||||
|
|
|
@ -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_;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -33,17 +33,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
|
||||
|
|
Loading…
Add table
Reference in a new issue