From 9b9e42ce5da8de87be408e7e0475a2cc62e13aa5 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Fri, 19 Jul 2013 18:32:47 -0400 Subject: [PATCH] use featureset_buffer for simplier render time feature cache from @mappy --- .../mapnik/feature_style_processor_impl.hpp | 41 +++++----- include/mapnik/util/featureset_buffer.hpp | 77 +++++++++++++++++++ 2 files changed, 100 insertions(+), 18 deletions(-) create mode 100644 include/mapnik/util/featureset_buffer.hpp diff --git a/include/mapnik/feature_style_processor_impl.hpp b/include/mapnik/feature_style_processor_impl.hpp index 5ea659b38..c40e53296 100644 --- a/include/mapnik/feature_style_processor_impl.hpp +++ b/include/mapnik/feature_style_processor_impl.hpp @@ -45,6 +45,7 @@ #include #include #include +#include // boost #include @@ -255,7 +256,8 @@ void feature_style_processor::apply_to_layer(layer const& lay, Proces // clip buffered extent by maximum extent, if supplied boost::optional > const& maximum_extent = m_.maximum_extent(); - if (maximum_extent) { + if (maximum_extent) + { buffered_query_ext.clip(*maximum_extent); } @@ -431,24 +433,22 @@ void feature_style_processor::apply_to_layer(layer const& lay, Proces } // Also query the group by attribute - std::string group_by = lay.group_by(); - if (group_by != "") + std::string const& group_by = lay.group_by(); + if (!group_by.empty()) { q.add_property_name(group_by); } bool cache_features = lay.cache_features() && active_styles.size() > 1; - // Render incrementally when the column that we group by - // changes value. - if (group_by != "") + // Render incrementally when the column that we group by changes value. + if (!group_by.empty()) { featureset_ptr features = ds->features(q); - if (features) { - // Cache all features into the memory_datasource before rendering. - memory_datasource cache(ds->type(),false); + if (features) + { + boost::shared_ptr cache = boost::make_shared(); feature_ptr feature, prev; - while ((feature = features->next())) { if (prev && prev->get(group_by) != feature->get(group_by)) @@ -458,44 +458,49 @@ void feature_style_processor::apply_to_layer(layer const& lay, Proces int i = 0; BOOST_FOREACH (feature_type_style const* style, active_styles) { + cache->prepare(); render_style(p, style, rule_caches[i], style_names[i], - cache.features(q), prj_trans); + cache, prj_trans); i++; } - cache.clear(); + cache->clear(); } - cache.push(feature); + cache->push(feature); prev = feature; } int i = 0; BOOST_FOREACH (feature_type_style const* style, active_styles) { + cache->prepare(); render_style(p, style, rule_caches[i], style_names[i], - cache.features(q), prj_trans); + cache, prj_trans); i++; } } } else if (cache_features) { - memory_datasource cache(ds->type(),false); featureset_ptr features = ds->features(q); - if (features) { + boost::shared_ptr cache = boost::make_shared(); + if (features) + { // Cache all features into the memory_datasource before rendering. feature_ptr feature; while ((feature = features->next())) { - cache.push(feature); + cache->push(feature); } } int i = 0; BOOST_FOREACH (feature_type_style const* style, active_styles) { + cache->prepare(); render_style(p, style, rule_caches[i], style_names[i], - cache.features(q), prj_trans); + cache, prj_trans); i++; } + cache->clear(); } // We only have a single style and no grouping. else diff --git a/include/mapnik/util/featureset_buffer.hpp b/include/mapnik/util/featureset_buffer.hpp new file mode 100644 index 000000000..42a07e8ee --- /dev/null +++ b/include/mapnik/util/featureset_buffer.hpp @@ -0,0 +1,77 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2013 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +#ifndef MAPNIK_FEATURESET_BUFFER_HPP +#define MAPNIK_FEATURESET_BUFFER_HPP + +// mapnik +#include + +#include + +namespace mapnik { + +class featureset_buffer : public Featureset +{ +public: + featureset_buffer() + : features_(), + pos_(), + end_() + {} + + virtual ~featureset_buffer() {} + + feature_ptr next() + { + if (pos_ != end_) + { + return *pos_++; + } + return feature_ptr(); + } + + void push(feature_ptr const& feature) + { + features_.push_back(feature); + } + + void prepare() + { + pos_ = features_.begin(); + end_ = features_.end(); + } + + void clear() + { + features_.clear(); + } + +private: + std::vector features_; + std::vector::iterator pos_; + std::vector::iterator end_; +}; + +} + +#endif // MAPNIK_FEATURESET_BUFFER_HPP