diff --git a/plugins/input/csv/csv_datasource.cpp b/plugins/input/csv/csv_datasource.cpp index 1d44b90c2..a61cdb9e6 100644 --- a/plugins/input/csv/csv_datasource.cpp +++ b/plugins/input/csv/csv_datasource.cpp @@ -388,7 +388,14 @@ void csv_datasource::parse_csv(T& stream, int feature_count(1); bool extent_initialized = false; - unsigned num_headers = headers_.size(); + std::size_t num_headers = headers_.size(); + + ctx_ = boost::make_shared(); + for (std::size_t i = 0; i < headers_.size(); ++i) + { + ctx_->push(headers_[i]); + } + mapnik::transcoder tr(desc_.get_encoding()); while (std::getline(stream,csv_line,newline)) @@ -434,7 +441,7 @@ void csv_datasource::parse_csv(T& stream, } } - mapnik::feature_ptr feature(mapnik::feature_factory::create(feature_count)); + mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_count)); double x(0); double y(0); bool parsed_x = false; @@ -450,9 +457,7 @@ void csv_datasource::parse_csv(T& stream, std::string value; if (beg == tok.end()) { - UnicodeString ustr = tr.transcode(value.c_str()); - boost::put(*feature,fld_name,ustr); - // boost::put(*feature,fld_name,mapnik::value_null()); + feature->put(fld_name,tr.transcode(value.c_str())); null_geom = true; if (feature_count == 1) { @@ -632,8 +637,7 @@ void csv_datasource::parse_csv(T& stream, (value_length > 20) || (value_length > 1 && !has_dot && value[0] == '0')) { - UnicodeString ustr = tr.transcode(value.c_str()); - boost::put(*feature,fld_name,ustr); + feature->put(fld_name,tr.transcode(value.c_str())); if (feature_count == 1) { desc_.add_descriptor(mapnik::attribute_descriptor(fld_name,mapnik::String)); @@ -649,7 +653,7 @@ void csv_datasource::parse_csv(T& stream, { if (has_dot) { - boost::put(*feature,fld_name,float_val); + feature->put(fld_name,float_val); if (feature_count == 1) { desc_.add_descriptor( @@ -659,8 +663,7 @@ void csv_datasource::parse_csv(T& stream, } else { - int val = static_cast(float_val); - boost::put(*feature,fld_name,val); + feature->put(fld_name,static_cast(float_val)); if (feature_count == 1) { desc_.add_descriptor( @@ -672,8 +675,7 @@ void csv_datasource::parse_csv(T& stream, else { // fallback to normal string - UnicodeString ustr = tr.transcode(value.c_str()); - boost::put(*feature,fld_name,ustr); + feature->put(fld_name,tr.transcode(value.c_str())); if (feature_count == 1) { desc_.add_descriptor( @@ -685,8 +687,7 @@ void csv_datasource::parse_csv(T& stream, else { // fallback to normal string - UnicodeString ustr = tr.transcode(value.c_str()); - boost::put(*feature,fld_name,ustr); + feature->put(fld_name,tr.transcode(value.c_str())); if (feature_count == 1) { desc_.add_descriptor( @@ -865,7 +866,7 @@ mapnik::featureset_ptr csv_datasource::features(mapnik::query const& q) const while (pos != attribute_names.end()) { bool found_name = false; - for (int i = 0; i < headers_.size(); ++i) + for (std::size_t i = 0; i < headers_.size(); ++i) { if (headers_[i] == *pos) { diff --git a/plugins/input/csv/csv_datasource.hpp b/plugins/input/csv/csv_datasource.hpp index e8fff4b5b..120f79dd9 100644 --- a/plugins/input/csv/csv_datasource.hpp +++ b/plugins/input/csv/csv_datasource.hpp @@ -40,6 +40,7 @@ private: mutable bool strict_; mutable bool quiet_; mutable double filesize_max_; + mutable mapnik::context_ptr ctx_; };