diff --git a/plugins/input/csv/csv_utils.cpp b/plugins/input/csv/csv_utils.cpp index ff75a46ed..e8fe78986 100644 --- a/plugins/input/csv/csv_utils.cpp +++ b/plugins/input/csv/csv_utils.cpp @@ -128,11 +128,11 @@ std::tuple autodetect_csv_flavour(std::istream & stream, { if (size < file_length && ss.eof()) { - // we can't be sure that last line + // we can't be sure last line // is not truncated so skip it break; } - if (line.size() == 0 || (line.size() == 1 && line[0] == char(0xa))) continue; // empty lines are not interesting + if (line.size() == 0) continue; // empty lines are not interesting auto num_quotes = std::count(line.begin(), line.end(), quote); if (num_quotes % 2 != 0) { diff --git a/plugins/input/sqlite/sqlite_datasource.cpp b/plugins/input/sqlite/sqlite_datasource.cpp index 4efdb4607..939d9d319 100644 --- a/plugins/input/sqlite/sqlite_datasource.cpp +++ b/plugins/input/sqlite/sqlite_datasource.cpp @@ -53,22 +53,22 @@ using mapnik::parameters; DATASOURCE_PLUGIN(sqlite_datasource) sqlite_datasource::sqlite_datasource(parameters const& params) - : datasource(params), - extent_(), - extent_initialized_(false), - type_(datasource::Vector), - table_(*params.get("table", "")), - fields_(*params.get("fields", "*")), - metadata_(*params.get("metadata", "")), - geometry_table_(*params.get("geometry_table", "")), - geometry_field_(*params.get("geometry_field", "")), - index_table_(*params.get("index_table", "")), - key_field_(*params.get("key_field", "")), - row_offset_(*params.get("row_offset", 0)), - row_limit_(*params.get("row_limit", 0)), - intersects_token_("!intersects!"), - desc_(sqlite_datasource::name(), *params.get("encoding", "utf-8")), - format_(mapnik::wkbAuto) + : datasource(params), + extent_(), + extent_initialized_(false), + type_(datasource::Vector), + table_(*params.get("table", "")), + fields_(*params.get("fields", "*")), + metadata_(*params.get("metadata", "")), + geometry_table_(*params.get("geometry_table", "")), + geometry_field_(*params.get("geometry_field", "")), + index_table_(*params.get("index_table", "")), + key_field_(*params.get("key_field", "")), + row_offset_(*params.get("row_offset", 0)), + row_limit_(*params.get("row_limit", 0)), + intersects_token_("!intersects!"), + desc_(sqlite_datasource::name(), *params.get("encoding", "utf-8")), + format_(mapnik::wkbAuto) { /* TODO - throw if no primary key but spatial index is present? @@ -448,7 +448,7 @@ boost::optional sqlite_datasource::get_geometry_t if (data) { - mapnik::geometry::geometry geom = mapnik::geometry_utils::from_twkb(data, size); + mapnik::geometry::geometry geom = mapnik::geometry_utils::from_wkb(data, size, format_); if (mapnik::geometry::is_empty(geom)) { continue; diff --git a/plugins/input/sqlite/sqlite_featureset.cpp b/plugins/input/sqlite/sqlite_featureset.cpp index 2474ca45d..99a44db54 100644 --- a/plugins/input/sqlite/sqlite_featureset.cpp +++ b/plugins/input/sqlite/sqlite_featureset.cpp @@ -81,7 +81,7 @@ feature_ptr sqlite_featureset::next() } feature_ptr feature = feature_factory::create(ctx_,rs_->column_integer64(1)); - mapnik::geometry::geometry geom = geometry_utils::from_twkb(data, size); + mapnik::geometry::geometry geom = geometry_utils::from_wkb(data, size, format_); if (mapnik::geometry::is_empty(geom)) { continue; diff --git a/test/unit/serialization/wkb_formats_test.cpp b/test/unit/serialization/wkb_formats_test.cpp index 9ffe8f156..698645266 100644 --- a/test/unit/serialization/wkb_formats_test.cpp +++ b/test/unit/serialization/wkb_formats_test.cpp @@ -1,3 +1,4 @@ + #include "catch.hpp" #include @@ -7,7 +8,6 @@ #include #include #include -#include #include TEST_CASE("geometry formats") { @@ -64,13 +64,8 @@ SECTION("wkb") { // spatialite blob mapnik::geometry::geometry geom = mapnik::geometry_utils::from_wkb((const char*)sp_valid_blob, - sizeof(sp_valid_blob) / sizeof(sp_valid_blob[0]), - mapnik::wkbSpatiaLite); - std::string wkt; - if (mapnik::util::to_wkt(wkt, geom)) - { - std::cerr << wkt << std::endl; - } + sizeof(sp_valid_blob) / sizeof(sp_valid_blob[0]), + mapnik::wkbSpatiaLite); // winding order is not correct per OGC so we'll fix it mapnik::geometry::correct(geom); #if BOOST_VERSION >= 105800 @@ -81,10 +76,7 @@ SECTION("wkb") { geom = mapnik::geometry_utils::from_wkb((const char*)sp_valid_blob, sizeof(sp_valid_blob) / sizeof(sp_valid_blob[0]), mapnik::wkbAuto); - - mapnik::geometry::correct(geom); - #if BOOST_VERSION >= 105800 REQUIRE(mapnik::geometry::is_valid(geom)); REQUIRE(mapnik::geometry::is_simple(geom)); diff --git a/utils/pgsql2sqlite/main.cpp b/utils/pgsql2sqlite/main.cpp index 2765a8b38..81eff635e 100644 --- a/utils/pgsql2sqlite/main.cpp +++ b/utils/pgsql2sqlite/main.cpp @@ -58,7 +58,7 @@ int main ( int argc, char** argv) ("query,q",po::value(),"Name of the table/or query to pass to postmaster") ("table,t",po::value(),"Name of the output table to create (default: table in query)") ("file,f",po::value(),"Use this option to specify the name of the file to create.") - ("twkb", "Output geometries in TWKB format.") + ; //po::positional_options_description p; @@ -90,8 +90,6 @@ int main ( int argc, char** argv) boost::optional password; boost::optional connect_timeout("4"); - bool output_twkb = vm.count("twkb") ? true : false; - if (vm.count("host")) host = vm["host"].as(); if (vm.count("port")) port = vm["port"].as(); if (vm.count("dbname")) dbname = vm["dbname"].as(); @@ -109,7 +107,7 @@ int main ( int argc, char** argv) std::cout << "output_table : " << output_table_name << "\n"; - mapnik::pgsql2sqlite(conn, query, output_table_name, output_file, output_twkb); + mapnik::pgsql2sqlite(conn,query,output_table_name,output_file); } catch (mapnik::datasource_exception & ex) { diff --git a/utils/pgsql2sqlite/pgsql2sqlite.hpp b/utils/pgsql2sqlite/pgsql2sqlite.hpp index 8022206c1..e339a8f58 100644 --- a/utils/pgsql2sqlite/pgsql2sqlite.hpp +++ b/utils/pgsql2sqlite/pgsql2sqlite.hpp @@ -165,8 +165,7 @@ template void pgsql2sqlite(Connection conn, std::string const& query, std::string const& output_table_name, - std::string const& output_filename, - bool output_twkb) + std::string const& output_filename) { namespace sqlite = mapnik::sqlite; sqlite::database db(output_filename); @@ -224,20 +223,11 @@ void pgsql2sqlite(Connection conn, geom_type = rs->getValue("type"); } + // add AsBinary() modifier std::string select_sql_str = select_sql.str(); - if (output_twkb) - { - // add AsTWKB(, 2) modifier - boost::algorithm::replace_all(select_sql_str, "\"" + geom_col + "\"","ST_AsTWKB(" + geom_col+", 2) as " + geom_col); - } - else - { - // add AsBinary() modifier - boost::algorithm::replace_all(select_sql_str, "\"" + geom_col + "\"","ST_AsBinary(" + geom_col+") as " + geom_col); - } + boost::algorithm::replace_all(select_sql_str, "\"" + geom_col + "\"","ST_AsBinary(" + geom_col+") as " + geom_col); -//#ifdef MAPNIK_DEBUG -#if 1 +#ifdef MAPNIK_DEBUG std::cout << select_sql_str << "\n"; #endif @@ -397,15 +387,7 @@ void pgsql2sqlite(Connection conn, if (oid == geometry_oid) { mapnik::feature_impl feat(ctx,pkid); - mapnik::geometry::geometry geom; - if (output_twkb) - { - geom = geometry_utils::from_twkb(buf, size); - } - else - { - geom = geometry_utils::from_wkb(buf, size, wkbGeneric); - } + mapnik::geometry::geometry geom = geometry_utils::from_wkb(buf, size, wkbGeneric); if (!mapnik::geometry::is_empty(geom)) { box2d bbox = mapnik::geometry::envelope(geom);