diff --git a/include/mapnik/feature_style_processor_impl.hpp b/include/mapnik/feature_style_processor_impl.hpp index 48a4e545e..ec7d98f76 100644 --- a/include/mapnik/feature_style_processor_impl.hpp +++ b/include/mapnik/feature_style_processor_impl.hpp @@ -427,7 +427,7 @@ void feature_style_processor::apply_to_layer(layer const& lay, Proces featureset_ptr features = ds->features(q); if (features) { // Cache all features into the memory_datasource before rendering. - memory_datasource cache; + memory_datasource cache(ds->type(),false); feature_ptr feature, prev; while ((feature = features->next())) @@ -458,7 +458,7 @@ void feature_style_processor::apply_to_layer(layer const& lay, Proces } else if (cache_features) { - memory_datasource cache(ds->type()); + memory_datasource cache(ds->type(),false); featureset_ptr features = ds->features(q); if (features) { // Cache all features into the memory_datasource before rendering. diff --git a/include/mapnik/memory_datasource.hpp b/include/mapnik/memory_datasource.hpp index ef30d5f3d..8ebb8f281 100644 --- a/include/mapnik/memory_datasource.hpp +++ b/include/mapnik/memory_datasource.hpp @@ -36,7 +36,7 @@ class MAPNIK_DECL memory_datasource : public datasource { friend class memory_featureset; public: - memory_datasource(datasource::datasource_t type=datasource::Vector); + memory_datasource(datasource::datasource_t type=datasource::Vector, bool bbox_check=true); virtual ~memory_datasource(); void push(feature_ptr feature); datasource::datasource_t type() const; @@ -51,6 +51,7 @@ private: std::vector features_; mapnik::layer_descriptor desc_; datasource::datasource_t type_; + bool bbox_check_; }; } diff --git a/include/mapnik/memory_featureset.hpp b/include/mapnik/memory_featureset.hpp index 5bf5c452e..b84ec387b 100644 --- a/include/mapnik/memory_featureset.hpp +++ b/include/mapnik/memory_featureset.hpp @@ -34,18 +34,20 @@ namespace mapnik { class memory_featureset : public Featureset { public: - memory_featureset(box2d const& bbox, memory_datasource const& ds) + memory_featureset(box2d const& bbox, memory_datasource const& ds, bool bbox_check = true) : bbox_(bbox), pos_(ds.features_.begin()), end_(ds.features_.end()), - type_(ds.type()) + type_(ds.type()), + bbox_check_(bbox_check) {} - memory_featureset(box2d const& bbox, std::vector const& features) + memory_featureset(box2d const& bbox, std::vector const& features, bool bbox_check = true) : bbox_(bbox), pos_(features.begin()), end_(features.end()), - type_(datasource::Vector) + type_(datasource::Vector), + bbox_check_(bbox_check) {} virtual ~memory_featureset() {} @@ -54,22 +56,33 @@ public: { while (pos_ != end_) { - if (type_ == datasource::Raster) + if (bbox_check_) { return *pos_++; } else { - for (unsigned i=0; i<(*pos_)->num_geometries();++i) + if (type_ == datasource::Raster) { - geometry_type & geom = (*pos_)->get_geometry(i); - if (bbox_.intersects(geom.envelope())) + raster_ptr const& source = (*pos_)->get_raster(); + if (source && bbox_.intersects(source->ext_)) { return *pos_++; } } + else + { + for (unsigned i=0; i<(*pos_)->num_geometries();++i) + { + geometry_type & geom = (*pos_)->get_geometry(i); + if (bbox_.intersects(geom.envelope())) + { + return *pos_++; + } + } + } + ++pos_; } - ++pos_; } return feature_ptr(); } @@ -79,6 +92,7 @@ private: std::vector::const_iterator pos_; std::vector::const_iterator end_; datasource::datasource_t type_; + bool bbox_check_; }; } diff --git a/src/memory_datasource.cpp b/src/memory_datasource.cpp index 66cf83d46..b622729a2 100644 --- a/src/memory_datasource.cpp +++ b/src/memory_datasource.cpp @@ -62,10 +62,11 @@ struct accumulate_extent bool first_; }; -memory_datasource::memory_datasource(datasource::datasource_t type) +memory_datasource::memory_datasource(datasource::datasource_t type, bool bbox_check) : datasource(parameters()), desc_("in-memory datasource","utf-8"), - type_(type) {} + type_(type), + bbox_check_(bbox_check) {} memory_datasource::~memory_datasource() {} @@ -83,7 +84,7 @@ datasource::datasource_t memory_datasource::type() const featureset_ptr memory_datasource::features(const query& q) const { - return boost::make_shared(q.get_bbox(),*this); + return boost::make_shared(q.get_bbox(),*this,bbox_check_); }