diff --git a/include/mapnik/feature.hpp b/include/mapnik/feature.hpp index f0bce2215..7d6015b9c 100644 --- a/include/mapnik/feature.hpp +++ b/include/mapnik/feature.hpp @@ -159,24 +159,26 @@ public: value_type const& get(context_type::key_type const& key) const { context_type::map_type::const_iterator itr = ctx_->mapping_.find(key); - if (itr != ctx_->mapping_.end() - && itr->second < data_.size()) - { - return data_[itr->second]; - } - else - { - throw std::out_of_range(std::string("Key does not exist: '") + key + "'"); - } + if (itr != ctx_->mapping_.end()) + return get(itr->second); + else + throw std::out_of_range(std::string("Key does not exist: '") + key + "'"); } - + value_type const& get(std::size_t index) const { if (index < data_.size()) return data_[index]; throw std::out_of_range("Index out of range"); } - + + boost::optional get_optional(std::size_t index) const + { + if (index < data_.size()) + return boost::optional(data_[index]); + return boost::optional(); + } + std::size_t size() const { return data_.size(); diff --git a/src/feature_kv_iterator.cpp b/src/feature_kv_iterator.cpp index 56c9acd51..85e8825f7 100644 --- a/src/feature_kv_iterator.cpp +++ b/src/feature_kv_iterator.cpp @@ -22,6 +22,7 @@ #include #include +#include namespace mapnik { @@ -44,7 +45,9 @@ bool feature_kv_iterator::equal( feature_kv_iterator const& other) const feature_kv_iterator::value_type const& feature_kv_iterator::dereference() const { boost::get<0>(kv_) = itr_->first; - boost::get<1>(kv_) = f_.get(itr_->first); + boost::optional val = f_.get_optional(itr_->second); + if (val) boost::get<1>(kv_) = *val; + else boost::get<1>(kv_) = value_null(); return kv_; }