From 1890d12534dde97c72ec2c5359e9ea7829c3919c Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 7 Oct 2015 14:06:49 -0700 Subject: [PATCH] [wip] on #3116 --- include/mapnik/attribute.hpp | 5 ++++- include/mapnik/attribute_collector.hpp | 2 +- include/mapnik/expression_evaluator.hpp | 4 ++++ src/parse_path.cpp | 12 ++++++++++-- test/visual/renderer.hpp | 2 +- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/include/mapnik/attribute.hpp b/include/mapnik/attribute.hpp index b0cf6839a..96a04e723 100644 --- a/include/mapnik/attribute.hpp +++ b/include/mapnik/attribute.hpp @@ -36,12 +36,15 @@ namespace mapnik { struct attribute { std::string name_; + bool is_id_; explicit attribute(std::string const& name) - : name_(name) {} + : name_(name), + is_id_(name == "__id__") {} template V const& value(F const& f) const { + if (is_id_) return f.id(); return f.get(name_); } diff --git a/include/mapnik/attribute_collector.hpp b/include/mapnik/attribute_collector.hpp index 878bfd4d4..3da6393df 100644 --- a/include/mapnik/attribute_collector.hpp +++ b/include/mapnik/attribute_collector.hpp @@ -62,7 +62,7 @@ struct expression_attributes void operator() (attribute const& attr) const { - names_.emplace(attr.name()); + if (attr.name() != "__id__") names_.emplace(attr.name()); } template diff --git a/include/mapnik/expression_evaluator.hpp b/include/mapnik/expression_evaluator.hpp index 6ac0451ef..4a520af26 100644 --- a/include/mapnik/expression_evaluator.hpp +++ b/include/mapnik/expression_evaluator.hpp @@ -77,6 +77,10 @@ struct evaluate value_type operator() (global_attribute const& attr) const { + if (attr.name == "@id") + { + return feature_.id(); + } auto itr = vars_.find(attr.name); if (itr != vars_.end()) { diff --git a/src/parse_path.cpp b/src/parse_path.cpp index a3d67c2cb..8fe6042ca 100644 --- a/src/parse_path.cpp +++ b/src/parse_path.cpp @@ -67,8 +67,16 @@ namespace path_processor_detail void operator() (attribute const& attr) const { // convert mapnik::value to std::string - value const& val = feature_.get(attr.name()); - filename_ += val.to_string(); + std::string const& name = attr.name(); + if (name == "__id__") + { + std::clog << "TODO\n"; + } + else + { + value const& val = feature_.get(name); + filename_ += val.to_string(); + } } std::string & filename_; diff --git a/test/visual/renderer.hpp b/test/visual/renderer.hpp index 6b033f99c..2bba22235 100644 --- a/test/visual/renderer.hpp +++ b/test/visual/renderer.hpp @@ -177,7 +177,7 @@ struct grid_renderer : renderer_base } if (val < 0) { - throw std::runtime_error("grid renderer: feature id is negative."); + val = std::abs(val); } val *= 100;