diff --git a/plugins/input/geojson/geojson_datasource.cpp b/plugins/input/geojson/geojson_datasource.cpp index 7c1fc978f..69c3ba230 100644 --- a/plugins/input/geojson/geojson_datasource.cpp +++ b/plugins/input/geojson/geojson_datasource.cpp @@ -25,7 +25,6 @@ #include #include - // boost #include #include @@ -129,11 +128,9 @@ std::map geojson_datasource::get_statistics() c return statistics_; } -// FIXME: implement mapnik::box2d geojson_datasource::envelope() const { if (!is_bound_) bind(); - return extent_; } @@ -149,9 +146,13 @@ mapnik::featureset_ptr geojson_datasource::features(mapnik::query const& q) cons if (!is_bound_) bind(); // if the query box intersects our world extent then query for features - if (extent_.intersects(q.get_bbox())) + mapnik::box2d const& b = q.get_bbox(); + if (extent_.intersects(b)) { - return boost::make_shared(features_,tree_); + box_type box(point_type(b.minx(),b.miny()),point_type(b.maxx(),b.maxy())); + index_array_ = tree_.find(box); + std::cout << "QUERY SIZE=" << index_array_.size() << std::endl; + return boost::make_shared(features_, index_array_.begin(), index_array_.end()); } // otherwise return an empty featureset pointer return mapnik::featureset_ptr(); diff --git a/plugins/input/geojson/geojson_datasource.hpp b/plugins/input/geojson/geojson_datasource.hpp index 829a30f5f..079cb7e3c 100644 --- a/plugins/input/geojson/geojson_datasource.hpp +++ b/plugins/input/geojson/geojson_datasource.hpp @@ -62,6 +62,7 @@ private: boost::shared_ptr tr_; mutable std::vector features_; mutable spatial_index_type tree_; + mutable std::deque index_array_; }; diff --git a/plugins/input/geojson/geojson_featureset.cpp b/plugins/input/geojson/geojson_featureset.cpp index bf5cb7878..f6d45a9d1 100644 --- a/plugins/input/geojson/geojson_featureset.cpp +++ b/plugins/input/geojson/geojson_featureset.cpp @@ -29,23 +29,24 @@ #include "geojson_featureset.hpp" -geojson_featureset::geojson_featureset(std::vector const& features, - geojson_datasource::spatial_index_type const& tree) - : feature_id_(1), - features_(features), - tree_(tree) {} +geojson_featureset::geojson_featureset(std::vector const& features, + std::deque::const_iterator index_itr, + std::deque::const_iterator index_end) + : features_(features), + index_itr_(index_itr), + index_end_(index_end) {} geojson_featureset::~geojson_featureset() {} mapnik::feature_ptr geojson_featureset::next() { - feature_id_++; - if (feature_id_ <= features_.size()) + if (index_itr_ != index_end_) { - return features_.at(feature_id_ - 1); - } - else - { - return mapnik::feature_ptr(); - } + std::size_t index = *index_itr_++; + if ( index < features_.size()) + { + return features_.at(index); + } + } + return mapnik::feature_ptr(); } diff --git a/plugins/input/geojson/geojson_featureset.hpp b/plugins/input/geojson/geojson_featureset.hpp index 6a463f66e..d10919ef8 100644 --- a/plugins/input/geojson/geojson_featureset.hpp +++ b/plugins/input/geojson/geojson_featureset.hpp @@ -2,22 +2,26 @@ #define GEOJSON_FEATURESET_HPP #include -#include #include "geojson_datasource.hpp" +#include +#include + + class geojson_featureset : public mapnik::Featureset { public: geojson_featureset(std::vector const& features, - geojson_datasource::spatial_index_type const& tree); + std::deque::const_iterator index_itr, + std::deque::const_iterator index_end); virtual ~geojson_featureset(); mapnik::feature_ptr next(); private: mapnik::box2d box_; - unsigned int feature_id_; std::vector const& features_; - geojson_datasource::spatial_index_type const& tree_; + std::deque::const_iterator index_itr_; + std::deque::const_iterator index_end_; }; #endif // GEOJSON_FEATURESET_HPP