update csv plugin to use new feature interface
This commit is contained in:
parent
e1ba3f723d
commit
f0e37a9fa1
2 changed files with 17 additions and 15 deletions
|
@ -388,7 +388,14 @@ void csv_datasource::parse_csv(T& stream,
|
||||||
|
|
||||||
int feature_count(1);
|
int feature_count(1);
|
||||||
bool extent_initialized = false;
|
bool extent_initialized = false;
|
||||||
unsigned num_headers = headers_.size();
|
std::size_t num_headers = headers_.size();
|
||||||
|
|
||||||
|
ctx_ = boost::make_shared<mapnik::context>();
|
||||||
|
for (std::size_t i = 0; i < headers_.size(); ++i)
|
||||||
|
{
|
||||||
|
ctx_->push(headers_[i]);
|
||||||
|
}
|
||||||
|
|
||||||
mapnik::transcoder tr(desc_.get_encoding());
|
mapnik::transcoder tr(desc_.get_encoding());
|
||||||
|
|
||||||
while (std::getline(stream,csv_line,newline))
|
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 x(0);
|
||||||
double y(0);
|
double y(0);
|
||||||
bool parsed_x = false;
|
bool parsed_x = false;
|
||||||
|
@ -450,9 +457,7 @@ void csv_datasource::parse_csv(T& stream,
|
||||||
std::string value;
|
std::string value;
|
||||||
if (beg == tok.end())
|
if (beg == tok.end())
|
||||||
{
|
{
|
||||||
UnicodeString ustr = tr.transcode(value.c_str());
|
feature->put(fld_name,tr.transcode(value.c_str()));
|
||||||
boost::put(*feature,fld_name,ustr);
|
|
||||||
// boost::put(*feature,fld_name,mapnik::value_null());
|
|
||||||
null_geom = true;
|
null_geom = true;
|
||||||
if (feature_count == 1)
|
if (feature_count == 1)
|
||||||
{
|
{
|
||||||
|
@ -632,8 +637,7 @@ void csv_datasource::parse_csv(T& stream,
|
||||||
(value_length > 20) ||
|
(value_length > 20) ||
|
||||||
(value_length > 1 && !has_dot && value[0] == '0'))
|
(value_length > 1 && !has_dot && value[0] == '0'))
|
||||||
{
|
{
|
||||||
UnicodeString ustr = tr.transcode(value.c_str());
|
feature->put(fld_name,tr.transcode(value.c_str()));
|
||||||
boost::put(*feature,fld_name,ustr);
|
|
||||||
if (feature_count == 1)
|
if (feature_count == 1)
|
||||||
{
|
{
|
||||||
desc_.add_descriptor(mapnik::attribute_descriptor(fld_name,mapnik::String));
|
desc_.add_descriptor(mapnik::attribute_descriptor(fld_name,mapnik::String));
|
||||||
|
@ -649,7 +653,7 @@ void csv_datasource::parse_csv(T& stream,
|
||||||
{
|
{
|
||||||
if (has_dot)
|
if (has_dot)
|
||||||
{
|
{
|
||||||
boost::put(*feature,fld_name,float_val);
|
feature->put(fld_name,float_val);
|
||||||
if (feature_count == 1)
|
if (feature_count == 1)
|
||||||
{
|
{
|
||||||
desc_.add_descriptor(
|
desc_.add_descriptor(
|
||||||
|
@ -659,8 +663,7 @@ void csv_datasource::parse_csv(T& stream,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int val = static_cast<int>(float_val);
|
feature->put(fld_name,static_cast<int>(float_val));
|
||||||
boost::put(*feature,fld_name,val);
|
|
||||||
if (feature_count == 1)
|
if (feature_count == 1)
|
||||||
{
|
{
|
||||||
desc_.add_descriptor(
|
desc_.add_descriptor(
|
||||||
|
@ -672,8 +675,7 @@ void csv_datasource::parse_csv(T& stream,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// fallback to normal string
|
// fallback to normal string
|
||||||
UnicodeString ustr = tr.transcode(value.c_str());
|
feature->put(fld_name,tr.transcode(value.c_str()));
|
||||||
boost::put(*feature,fld_name,ustr);
|
|
||||||
if (feature_count == 1)
|
if (feature_count == 1)
|
||||||
{
|
{
|
||||||
desc_.add_descriptor(
|
desc_.add_descriptor(
|
||||||
|
@ -685,8 +687,7 @@ void csv_datasource::parse_csv(T& stream,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// fallback to normal string
|
// fallback to normal string
|
||||||
UnicodeString ustr = tr.transcode(value.c_str());
|
feature->put(fld_name,tr.transcode(value.c_str()));
|
||||||
boost::put(*feature,fld_name,ustr);
|
|
||||||
if (feature_count == 1)
|
if (feature_count == 1)
|
||||||
{
|
{
|
||||||
desc_.add_descriptor(
|
desc_.add_descriptor(
|
||||||
|
@ -865,7 +866,7 @@ mapnik::featureset_ptr csv_datasource::features(mapnik::query const& q) const
|
||||||
while (pos != attribute_names.end())
|
while (pos != attribute_names.end())
|
||||||
{
|
{
|
||||||
bool found_name = false;
|
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)
|
if (headers_[i] == *pos)
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,6 +40,7 @@ private:
|
||||||
mutable bool strict_;
|
mutable bool strict_;
|
||||||
mutable bool quiet_;
|
mutable bool quiet_;
|
||||||
mutable double filesize_max_;
|
mutable double filesize_max_;
|
||||||
|
mutable mapnik::context_ptr ctx_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue