diff --git a/plugins/input/csv/csv_datasource.cpp b/plugins/input/csv/csv_datasource.cpp index 25e3c2a09..50bcb8072 100644 --- a/plugins/input/csv/csv_datasource.cpp +++ b/plugins/input/csv/csv_datasource.cpp @@ -274,7 +274,8 @@ void csv_datasource::parse_csv(T& stream, { std::string val = boost::trim_copy(*beg); std::string lower_val = boost::algorithm::to_lower_copy(val); - if (lower_val == "wkt") + if (lower_val == "wkt" + || (lower_val.find("geom") != std::string::npos)) { wkt_idx = idx; has_wkt_field = true; @@ -343,7 +344,8 @@ void csv_datasource::parse_csv(T& stream, else { std::string lower_val = boost::algorithm::to_lower_copy(val); - if (lower_val == "wkt") + if (lower_val == "wkt" + || (lower_val.find("geom") != std::string::npos)) { wkt_idx = idx; has_wkt_field = true; @@ -400,14 +402,21 @@ void csv_datasource::parse_csv(T& stream, #endif break; } + + unsigned line_length = csv_line.length(); // skip blank lines - if (csv_line.empty()){ - ++line_number; - continue; + if (line_length < 5) + { + std::string trimmed = csv_line; + boost::trim_if(trimmed,boost::algorithm::is_any_of("\",'\r\n")); + if (trimmed.empty()){ + ++line_number; + continue; #ifdef MAPNIK_DEBUG - std::clog << "CSV Plugin: empty row encountered at line: " << line_number << "\n"; + std::clog << "CSV Plugin: empty row encountered at line: " << line_number << "\n"; #endif + } } try @@ -443,7 +452,14 @@ void csv_datasource::parse_csv(T& stream, std::string value; if (beg == tok.end()) { - boost::put(*feature,fld_name,mapnik::value_null()); + UnicodeString ustr = tr.transcode(value.c_str()); + boost::put(*feature,fld_name,ustr); + //boost::put(*feature,fld_name,mapnik::value_null()); + null_geom = true; + if (feature_count == 1) + { + desc_.add_descriptor(mapnik::attribute_descriptor(fld_name,mapnik::String)); + } continue; } else @@ -452,7 +468,6 @@ void csv_datasource::parse_csv(T& stream, ++beg; } - int value_length = value.length(); // parse wkt diff --git a/tests/data/csv/trailing_newline_mac.csv b/tests/data/csv/trailing_newline_mac.csv new file mode 100644 index 000000000..5a7051dd9 --- /dev/null +++ b/tests/data/csv/trailing_newline_mac.csv @@ -0,0 +1 @@ +x,y,z 0,0,0 1,2,3 diff --git a/tests/data/csv/trailing_newline_win.csv b/tests/data/csv/trailing_newline_win.csv new file mode 100644 index 000000000..289bb9514 --- /dev/null +++ b/tests/data/csv/trailing_newline_win.csv @@ -0,0 +1,12 @@ +FID,wkt,REGIONNAME,RID +Eth_Region_Boundary.1,"POINT (0 0)",Addis Ababa,14 +Eth_Region_Boundary.2,"POINT (0 0)",Tigray,01 +Eth_Region_Boundary.3,"POINT (0 0)",Somali,05 +Eth_Region_Boundary.4,"POINT (0 0)",Dire Dawa,15 +Eth_Region_Boundary.5,"POINT (0 0)",Hareri,13 +Eth_Region_Boundary.6,"POINT (0 0)",SNNPR,07 +Eth_Region_Boundary.7,"POINT (0 0)",Gambela,12 +Eth_Region_Boundary.8,"POINT (0 0)",Beneshangul Gumu,06 +Eth_Region_Boundary.9,"POINT (0 0)",Amhara,03 +Eth_Region_Boundary.10,"POINT (0 0)",Afar,02 +Eth_Region_Boundary.11,"POINT (0 0)",Oromia,04