csv plugin: support conversion to boolean types - closes #1540
This commit is contained in:
parent
f76ea12700
commit
c55a3c3130
1 changed files with 29 additions and 12 deletions
|
@ -670,12 +670,14 @@ void csv_datasource::parse_csv(T & stream,
|
|||
// now, add attributes, skipping any WKT or JSON fields
|
||||
if ((has_wkt_field) && (i == wkt_idx)) continue;
|
||||
if ((has_json_field) && (i == json_idx)) continue;
|
||||
/* First we detect likely strings, then try parsing likely numbers,
|
||||
finally falling back to string type
|
||||
* We intentionally do not try to detect boolean or null types
|
||||
since they are not common in csv
|
||||
* Likely strings are either empty values, very long values
|
||||
or value with leading zeros like 001 (which are not safe
|
||||
/* First we detect likely strings,
|
||||
then try parsing likely numbers,
|
||||
then try converting to bool,
|
||||
finally falling back to string type.
|
||||
An empty string or a string of "null" will be parsed
|
||||
as a string rather than a true null value.
|
||||
Likely strings are either empty values, very long values
|
||||
or values with leading zeros like 001 (which are not safe
|
||||
to assume are numbers)
|
||||
*/
|
||||
|
||||
|
@ -730,6 +732,20 @@ void csv_datasource::parse_csv(T & stream,
|
|||
}
|
||||
}
|
||||
if (!matched)
|
||||
{
|
||||
bool bool_val = false;
|
||||
if (mapnik::util::string2bool(value,bool_val))
|
||||
{
|
||||
matched = true;
|
||||
feature->put(fld_name,bool_val);
|
||||
if (feature_count == 1)
|
||||
{
|
||||
desc_.add_descriptor(
|
||||
mapnik::attribute_descriptor(
|
||||
fld_name,mapnik::Boolean));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// fallback to normal string
|
||||
feature->put(fld_name,std::move(tr.transcode(value.c_str())));
|
||||
|
@ -741,6 +757,7 @@ void csv_datasource::parse_csv(T & stream,
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool null_geom = true;
|
||||
if (has_wkt_field || has_json_field)
|
||||
|
|
Loading…
Reference in a new issue