void dbf_file::add_attribute(int col, mapnik::transcoder const& tr, Feature & f) const throw() { using namespace boost::spirit; if (col>=0 && col<num_fields_) { std::string const& name=fields_[col].name_; switch (fields_[col].type_) { case 'C': case 'D'://todo handle date? case 'M': case 'L': { // FIXME - avoid constructing std::string on stack std::string str(record_+fields_[col].offset_,fields_[col].length_); boost::trim(str); f.put(name,tr.transcode(str.c_str())); break; } case 'N': case 'F': { if (record_[fields_[col].offset_] == '*') { f.put(name,0); break; } if ( fields_[col].dec_>0 ) { double val = 0.0; const char *itr = record_+fields_[col].offset_; const char *end = itr + fields_[col].length_; qi::phrase_parse(itr,end,double_,ascii::space,val); f.put(name,val); } else { int val = 0; const char *itr = record_+fields_[col].offset_; const char *end = itr + fields_[col].length_; qi::phrase_parse(itr,end,int_,ascii::space,val); f.put(name,val); } break; } } } }
void process_properties(Feature & feature, Headers const& headers, Values const& values, Locator const& locator, Transcoder const& tr) { auto val_beg = values.begin(); auto val_end = values.end(); auto num_headers = headers.size(); for (std::size_t i = 0; i < num_headers; ++i) { std::string const& fld_name = headers.at(i); if (val_beg == val_end) { feature.put(fld_name,tr.transcode("")); continue; } std::string value = mapnik::util::trim_copy(*val_beg++); int value_length = value.length(); if (locator.index == i && (locator.type == geometry_column_locator::WKT || locator.type == geometry_column_locator::GEOJSON) ) continue; bool matched = false; bool has_dot = value.find(".") != std::string::npos; if (value.empty() || (value_length > 20) || (value_length > 1 && !has_dot && value[0] == '0')) { matched = true; feature.put(fld_name,std::move(tr.transcode(value.c_str()))); } else if (csv_utils::is_likely_number(value)) { bool has_e = value.find("e") != std::string::npos; if (has_dot || has_e) { double float_val = 0.0; if (mapnik::util::string2double(value,float_val)) { matched = true; feature.put(fld_name,float_val); } } else { mapnik::value_integer int_val = 0; if (mapnik::util::string2int(value,int_val)) { matched = true; feature.put(fld_name,int_val); } } } if (!matched) { if (csv_utils::ignore_case_equal(value, "true")) { feature.put(fld_name, true); } else if (csv_utils::ignore_case_equal(value, "false")) { feature.put(fld_name, false); } else // fallback to string { feature.put(fld_name,std::move(tr.transcode(value.c_str()))); } } } }
void dbf_file::add_attribute(int col, mapnik::transcoder const& tr, Feature & f) const throw() { using namespace boost::spirit; if (col>=0 && col<num_fields_) { std::string const& name=fields_[col].name_; switch (fields_[col].type_) { case 'C': case 'D': { // FIXME - avoid constructing std::string on stack std::string str(record_+fields_[col].offset_,fields_[col].length_); boost::trim(str); f.put(name,tr.transcode(str.c_str())); break; } case 'L': { char ch = record_[fields_[col].offset_]; if ( ch == '1' || ch == 't' || ch == 'T' || ch == 'y' || ch == 'Y') { f.put(name,true); } else { // NOTE: null logical fields use '?' f.put(name,false); } break; } case 'N': { if (record_[fields_[col].offset_] == '*') { f.put(name,mapnik::value_null()); break; } if ( fields_[col].dec_>0 ) { double val = 0.0; const char *itr = record_+fields_[col].offset_; const char *end = itr + fields_[col].length_; if (qi::phrase_parse(itr,end,double_,ascii::space,val)) f.put(name,val); } else { mapnik::value_integer val = 0; const char *itr = record_+fields_[col].offset_; const char *end = itr + fields_[col].length_; if (qi::phrase_parse(itr,end,int_,ascii::space,val)) f.put(name,val); } break; } } } }