From 9040d2ac9d3ddf66974fd350e468419b55539fd6 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Fri, 26 Oct 2012 18:18:35 -0700 Subject: [PATCH] fix feature-cache for rasters - TODO: no intersection check option for memory_featureset --- .../mapnik/feature_style_processor_impl.hpp | 2 +- include/mapnik/memory_datasource.hpp | 3 ++- include/mapnik/memory_featureset.hpp | 27 +++++++++++-------- src/memory_datasource.cpp | 7 ++--- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/include/mapnik/feature_style_processor_impl.hpp b/include/mapnik/feature_style_processor_impl.hpp index 629b84ac5..48a4e545e 100644 --- a/include/mapnik/feature_style_processor_impl.hpp +++ b/include/mapnik/feature_style_processor_impl.hpp @@ -458,7 +458,7 @@ void feature_style_processor::apply_to_layer(layer const& lay, Proces } else if (cache_features) { - memory_datasource cache; + memory_datasource cache(ds->type()); 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 8966fe036..ef30d5f3d 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(); + memory_datasource(datasource::datasource_t type=datasource::Vector); virtual ~memory_datasource(); void push(feature_ptr feature); datasource::datasource_t type() const; @@ -50,6 +50,7 @@ public: private: std::vector features_; mapnik::layer_descriptor desc_; + datasource::datasource_t type_; }; } diff --git a/include/mapnik/memory_featureset.hpp b/include/mapnik/memory_featureset.hpp index 8f14940e5..5bf5c452e 100644 --- a/include/mapnik/memory_featureset.hpp +++ b/include/mapnik/memory_featureset.hpp @@ -24,7 +24,6 @@ #define MAPNIK_MEMORY_FEATURESET_HPP // mapnik -#include #include // boost @@ -38,13 +37,15 @@ public: memory_featureset(box2d const& bbox, memory_datasource const& ds) : bbox_(bbox), pos_(ds.features_.begin()), - end_(ds.features_.end()) + end_(ds.features_.end()), + type_(ds.type()) {} memory_featureset(box2d const& bbox, std::vector const& features) : bbox_(bbox), pos_(features.begin()), - end_(features.end()) + end_(features.end()), + type_(datasource::Vector) {} virtual ~memory_featureset() {} @@ -53,20 +54,23 @@ public: { while (pos_ != end_) { - for (unsigned i=0; i<(*pos_)->num_geometries();++i) + if (type_ == datasource::Raster) { - geometry_type & geom = (*pos_)->get_geometry(i); - - MAPNIK_LOG_DEBUG(memory_featureset) << "memory_featureset: BBox=" << bbox_ << ",Envelope=" << geom.envelope(); - - if (bbox_.intersects(geom.envelope())) + return *pos_++; + } + else + { + for (unsigned i=0; i<(*pos_)->num_geometries();++i) { - return *pos_++; + geometry_type & geom = (*pos_)->get_geometry(i); + if (bbox_.intersects(geom.envelope())) + { + return *pos_++; + } } } ++pos_; } - return feature_ptr(); } @@ -74,6 +78,7 @@ private: box2d bbox_; std::vector::const_iterator pos_; std::vector::const_iterator end_; + datasource::datasource_t type_; }; } diff --git a/src/memory_datasource.cpp b/src/memory_datasource.cpp index 0549a92d0..66cf83d46 100644 --- a/src/memory_datasource.cpp +++ b/src/memory_datasource.cpp @@ -62,9 +62,10 @@ struct accumulate_extent bool first_; }; -memory_datasource::memory_datasource() +memory_datasource::memory_datasource(datasource::datasource_t type) : datasource(parameters()), - desc_("in-memory datasource","utf-8") {} + desc_("in-memory datasource","utf-8"), + type_(type) {} memory_datasource::~memory_datasource() {} @@ -77,7 +78,7 @@ void memory_datasource::push(feature_ptr feature) datasource::datasource_t memory_datasource::type() const { - return datasource::Vector; + return type_; } featureset_ptr memory_datasource::features(const query& q) const