Merge commit '879f7eb04200d7d2c28af565229bf6e3d54274fd' into retry/libosmium

This commit is contained in:
karenzshea
2016-10-03 13:08:59 -04:00
208 changed files with 11590 additions and 4051 deletions
+3 -3
View File
@@ -10,9 +10,9 @@
#include <osmium/io/xml_input.hpp>
#include <osmium/visitor.hpp>
typedef osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location> index_neg_type;
typedef osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location> index_pos_type;
typedef osmium::handler::NodeLocationsForWays<index_pos_type, index_neg_type> location_handler_type;
using index_neg_type = osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location>;
using index_pos_type = osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
using location_handler_type = osmium::handler::NodeLocationsForWays<index_pos_type, index_neg_type>;
#include "check_basics_handler.hpp"
#include "check_wkt_handler.hpp"
@@ -1,7 +1,9 @@
#include <cstring>
#include <iostream>
#include <fstream>
#include <map>
#include <string>
#include <gdalcpp.hpp>
@@ -17,21 +19,20 @@
#include <osmium/io/xml_input.hpp>
#include <osmium/visitor.hpp>
typedef osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location> index_type;
typedef osmium::handler::NodeLocationsForWays<index_type> location_handler_type;
using index_type = osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
using location_handler_type = osmium::handler::NodeLocationsForWays<index_type>;
struct less_charptr {
bool operator()(const char* a, const char* b) const {
bool operator()(const char* a, const char* b) const noexcept {
return std::strcmp(a, b) < 0;
}
}; // less_charptr
typedef std::map<const char*, const char*, less_charptr> tagmap_type;
using tagmap_type = std::map<const char*, const char*, less_charptr>;
inline tagmap_type create_map(const osmium::TagList& taglist) {
tagmap_type create_map(const osmium::TagList& taglist) {
tagmap_type map;
for (auto& tag : taglist) {
@@ -52,7 +53,7 @@ class TestHandler : public osmium::handler::Handler {
std::ofstream m_out;
bool m_first_out {true};
bool m_first_out{true};
public:
@@ -77,7 +78,7 @@ public:
}
void node(const osmium::Node& node) {
gdalcpp::Feature feature(m_layer_point, m_ogr_factory.create_point(node));
gdalcpp::Feature feature{m_layer_point, m_ogr_factory.create_point(node)};
feature.set_field("id", static_cast<double>(node.id()));
feature.set_field("type", node.tags().get_value_by_key("type"));
feature.add_to_layer();
@@ -85,11 +86,11 @@ public:
void way(const osmium::Way& way) {
try {
gdalcpp::Feature feature(m_layer_lines, m_ogr_factory.create_linestring(way));
gdalcpp::Feature feature{m_layer_lines, m_ogr_factory.create_linestring(way)};
feature.set_field("id", static_cast<double>(way.id()));
feature.set_field("type", way.tags().get_value_by_key("type"));
feature.add_to_layer();
} catch (osmium::geometry_error&) {
} catch (const osmium::geometry_error&) {
std::cerr << "Ignoring illegal geometry for way " << way.id() << ".\n";
}
}
@@ -103,10 +104,10 @@ public:
}
m_out << "{\n \"test_id\": " << (area.orig_id() / 1000) << ",\n \"area_id\": " << area.id() << ",\n \"from_id\": " << area.orig_id() << ",\n \"from_type\": \"" << (area.from_way() ? "way" : "relation") << "\",\n \"wkt\": \"";
try {
std::string wkt = m_wkt_factory.create_multipolygon(area);
const std::string wkt = m_wkt_factory.create_multipolygon(area);
m_out << wkt << "\",\n \"tags\": {";
auto tagmap = create_map(area.tags());
const auto tagmap = create_map(area.tags());
bool first = true;
for (auto& tag : tagmap) {
if (first) {
@@ -117,11 +118,11 @@ public:
m_out << '"' << tag.first << "\": \"" << tag.second << '"';
}
m_out << "}\n}";
} catch (osmium::geometry_error&) {
} catch (const osmium::geometry_error&) {
m_out << "INVALID\"\n}";
}
try {
gdalcpp::Feature feature(m_layer_mpoly, m_ogr_factory.create_multipolygon(area));
gdalcpp::Feature feature{m_layer_mpoly, m_ogr_factory.create_multipolygon(area)};
feature.set_field("id", static_cast<double>(area.orig_id()));
std::string from_type;
@@ -132,7 +133,7 @@ public:
}
feature.set_field("from_type", from_type.c_str());
feature.add_to_layer();
} catch (osmium::geometry_error&) {
} catch (const osmium::geometry_error&) {
std::cerr << "Ignoring illegal geometry for area " << area.id() << " created from " << (area.from_way() ? "way" : "relation") << " with id=" << area.orig_id() << ".\n";
}
}
@@ -144,35 +145,38 @@ public:
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " INFILE\n";
exit(1);
std::exit(1);
}
std::string output_format("SQLite");
std::string input_filename(argv[1]);
std::string output_filename("multipolygon.db");
const std::string output_format{"SQLite"};
const std::string input_filename{argv[1]};
const std::string output_filename{"multipolygon.db"};
CPLSetConfigOption("OGR_SQLITE_SYNCHRONOUS", "FALSE");
gdalcpp::Dataset dataset{output_format, output_filename, gdalcpp::SRS{}, { "SPATIALITE=TRUE" }};
gdalcpp::Dataset dataset{output_format, output_filename, gdalcpp::SRS{}, {"SPATIALITE=TRUE"}};
osmium::area::ProblemReporterOGR problem_reporter(dataset);
osmium::area::Assembler::config_type assembler_config(&problem_reporter);
assembler_config.enable_debug_output();
osmium::area::MultipolygonCollector<osmium::area::Assembler> collector(assembler_config);
osmium::area::ProblemReporterOGR problem_reporter{dataset};
osmium::area::Assembler::config_type assembler_config;
assembler_config.problem_reporter = &problem_reporter;
assembler_config.check_roles = true;
assembler_config.create_empty_areas = true;
assembler_config.debug_level = 2;
osmium::area::MultipolygonCollector<osmium::area::Assembler> collector{assembler_config};
std::cerr << "Pass 1...\n";
osmium::io::Reader reader1(input_filename);
osmium::io::Reader reader1{input_filename};
collector.read_relations(reader1);
reader1.close();
std::cerr << "Pass 1 done\n";
index_type index;
location_handler_type location_handler(index);
location_handler_type location_handler{index};
location_handler.ignore_errors();
TestHandler test_handler(dataset);
TestHandler test_handler{dataset};
std::cerr << "Pass 2...\n";
osmium::io::Reader reader2(input_filename);
osmium::io::Reader reader2{input_filename};
osmium::apply(reader2, location_handler, test_handler, collector.handler([&test_handler](const osmium::memory::Buffer& area_buffer) {
osmium::apply(area_buffer, test_handler);
}));
+12 -11
View File
@@ -1,6 +1,7 @@
/* The code in this file is released into the Public Domain. */
#include <iostream>
#include <string>
#include <gdalcpp.hpp>
@@ -12,8 +13,8 @@
#include <osmium/io/xml_input.hpp>
#include <osmium/visitor.hpp>
typedef osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location> index_type;
typedef osmium::handler::NodeLocationsForWays<index_type> location_handler_type;
using index_type = osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
using location_handler_type = osmium::handler::NodeLocationsForWays<index_type>;
class TestOverviewHandler : public osmium::handler::Handler {
@@ -64,7 +65,7 @@ public:
}
feature.add_to_layer();
} catch (osmium::geometry_error&) {
} catch (const osmium::geometry_error&) {
std::cerr << "Ignoring illegal geometry for way " << way.id() << ".\n";
}
}
@@ -76,24 +77,24 @@ public:
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " INFILE\n";
exit(1);
std::exit(1);
}
std::string output_format("SQLite");
std::string input_filename(argv[1]);
std::string output_filename("testdata-overview.db");
const std::string output_format{"SQLite"};
const std::string input_filename{argv[1]};
const std::string output_filename{"testdata-overview.db"};
::unlink(output_filename.c_str());
CPLSetConfigOption("OGR_SQLITE_SYNCHRONOUS", "FALSE");
gdalcpp::Dataset dataset(output_format, output_filename, gdalcpp::SRS{}, { "SPATIALITE=TRUE" });
gdalcpp::Dataset dataset{output_format, output_filename, gdalcpp::SRS{}, {"SPATIALITE=TRUE"}};
osmium::io::Reader reader(input_filename);
osmium::io::Reader reader{input_filename};
index_type index;
location_handler_type location_handler(index);
location_handler_type location_handler{index};
location_handler.ignore_errors();
TestOverviewHandler handler(dataset);
TestOverviewHandler handler{dataset};
osmium::apply(reader, location_handler, handler);
reader.close();
@@ -15,11 +15,9 @@ int main(int argc, char* argv[]) {
std::cerr << "Running tests from '" << dirname << "' (from TESTCASES_DIR environment variable)\n";
} else {
std::cerr << "Please set TESTCASES_DIR environment variable.\n";
exit(1);
std::exit(1);
}
int result = Catch::Session().run(argc, argv);
return result;
return Catch::Session().run(argc, argv);
}
+60 -58
View File
@@ -5,7 +5,9 @@
#include <cassert>
#include <cstdlib>
#include <future>
#include <iostream>
#include <iterator>
#include <string>
#include <osmium/io/detail/queue_util.hpp>
@@ -14,14 +16,14 @@
#include <osmium/visitor.hpp>
std::string S_(const char* s) {
return std::string(s);
return std::string{s};
}
std::string filename(const char* test_id, const char* suffix = "osm") {
const char* testdir = getenv("TESTDIR");
if (!testdir) {
std::cerr << "You have to set TESTDIR environment variable before running testdata-xml\n";
exit(2);
std::exit(2);
}
std::string f;
@@ -47,11 +49,11 @@ struct header_buffer_type {
// file contents fit into small buffers.
std::string read_file(const char* test_id) {
int fd = osmium::io::detail::open_for_reading(filename(test_id));
const int fd = osmium::io::detail::open_for_reading(filename(test_id));
assert(fd >= 0);
std::string input(10000, '\0');
auto n = ::read(fd, reinterpret_cast<unsigned char*>(const_cast<char*>(input.data())), 10000);
const auto n = ::read(fd, reinterpret_cast<unsigned char*>(const_cast<char*>(input.data())), 10000);
assert(n >= 0);
input.resize(static_cast<std::string::size_type>(n));
@@ -61,10 +63,10 @@ std::string read_file(const char* test_id) {
}
std::string read_gz_file(const char* test_id, const char* suffix) {
int fd = osmium::io::detail::open_for_reading(filename(test_id, suffix));
const int fd = osmium::io::detail::open_for_reading(filename(test_id, suffix));
assert(fd >= 0);
osmium::io::GzipDecompressor gzip_decompressor(fd);
osmium::io::GzipDecompressor gzip_decompressor{fd};
std::string input = gzip_decompressor.read();
gzip_decompressor.close();
@@ -81,7 +83,7 @@ header_buffer_type parse_xml(std::string input) {
osmium::io::detail::add_to_queue(input_queue, std::move(input));
osmium::io::detail::add_to_queue(input_queue, std::string{});
osmium::io::detail::XMLParser parser(input_queue, output_queue, header_promise, osmium::osm_entity_bits::all);
osmium::io::detail::XMLParser parser{input_queue, output_queue, header_promise, osmium::osm_entity_bits::all};
parser.parse();
header_buffer_type result;
@@ -117,9 +119,9 @@ TEST_CASE("Reading OSM XML 100") {
}
SECTION("Using Reader") {
osmium::io::Reader reader(filename("100-correct_but_no_data"));
osmium::io::Reader reader{filename("100-correct_but_no_data")};
osmium::io::Header header = reader.header();
const osmium::io::Header header{reader.header()};
REQUIRE(header.get("generator") == "testdata");
osmium::memory::Buffer buffer = reader.read();
@@ -129,9 +131,9 @@ TEST_CASE("Reading OSM XML 100") {
}
SECTION("Using Reader asking for header only") {
osmium::io::Reader reader(filename("100-correct_but_no_data"), osmium::osm_entity_bits::nothing);
osmium::io::Reader reader{filename("100-correct_but_no_data"), osmium::osm_entity_bits::nothing};
osmium::io::Header header = reader.header();
const osmium::io::Header header{reader.header()};
REQUIRE(header.get("generator") == "testdata");
reader.close();
}
@@ -146,15 +148,15 @@ TEST_CASE("Reading OSM XML 101") {
REQUIRE_THROWS_AS(read_xml("101-missing_version"), osmium::format_version_error);
try {
read_xml("101-missing_version");
} catch (osmium::format_version_error& e) {
} catch (const osmium::format_version_error& e) {
REQUIRE(e.version.empty());
}
}
SECTION("Using Reader") {
REQUIRE_THROWS_AS({
osmium::io::Reader reader(filename("101-missing_version"));
osmium::io::Header header = reader.header();
osmium::io::Reader reader{filename("101-missing_version")};
const osmium::io::Header header{reader.header()};
osmium::memory::Buffer buffer = reader.read();
reader.close();
}, osmium::format_version_error);
@@ -170,16 +172,16 @@ TEST_CASE("Reading OSM XML 102") {
REQUIRE_THROWS_AS(read_xml("102-wrong_version"), osmium::format_version_error);
try {
read_xml("102-wrong_version");
} catch (osmium::format_version_error& e) {
} catch (const osmium::format_version_error& e) {
REQUIRE(e.version == "0.1");
}
}
SECTION("Using Reader") {
REQUIRE_THROWS_AS({
osmium::io::Reader reader(filename("102-wrong_version"));
osmium::io::Reader reader{filename("102-wrong_version")};
osmium::io::Header header = reader.header();
const osmium::io::Header header{reader.header()};
osmium::memory::Buffer buffer = reader.read();
reader.close();
}, osmium::format_version_error);
@@ -195,15 +197,15 @@ TEST_CASE("Reading OSM XML 103") {
REQUIRE_THROWS_AS(read_xml("103-old_version"), osmium::format_version_error);
try {
read_xml("103-old_version");
} catch (osmium::format_version_error& e) {
} catch (const osmium::format_version_error& e) {
REQUIRE(e.version == "0.5");
}
}
SECTION("Using Reader") {
REQUIRE_THROWS_AS({
osmium::io::Reader reader(filename("103-old_version"));
osmium::io::Header header = reader.header();
osmium::io::Reader reader{filename("103-old_version")};
const osmium::io::Header header{reader.header()};
osmium::memory::Buffer buffer = reader.read();
reader.close();
}, osmium::format_version_error);
@@ -219,7 +221,7 @@ TEST_CASE("Reading OSM XML 104") {
REQUIRE_THROWS_AS(read_xml("104-empty_file"), osmium::xml_error);
try {
read_xml("104-empty_file");
} catch (osmium::xml_error& e) {
} catch (const osmium::xml_error& e) {
REQUIRE(e.line == 1);
REQUIRE(e.column == 0);
}
@@ -227,8 +229,8 @@ TEST_CASE("Reading OSM XML 104") {
SECTION("Using Reader") {
REQUIRE_THROWS_AS({
osmium::io::Reader reader(filename("104-empty_file"));
osmium::io::Header header = reader.header();
osmium::io::Reader reader{filename("104-empty_file")};
const osmium::io::Header header{reader.header()};
osmium::memory::Buffer buffer = reader.read();
reader.close();
}, osmium::xml_error);
@@ -245,8 +247,8 @@ TEST_CASE("Reading OSM XML 105") {
SECTION("Using Reader") {
REQUIRE_THROWS_AS({
osmium::io::Reader reader(filename("105-incomplete_xml_file"));
osmium::io::Header header = reader.header();
osmium::io::Reader reader{filename("105-incomplete_xml_file")};
const osmium::io::Header header{reader.header()};
osmium::memory::Buffer buffer = reader.read();
reader.close();
}, osmium::xml_error);
@@ -270,9 +272,9 @@ TEST_CASE("Reading OSM XML 120") {
}
SECTION("Using Reader") {
osmium::io::Reader reader(filename("120-correct_gzip_file_without_data", "osm.gz"));
osmium::io::Reader reader{filename("120-correct_gzip_file_without_data", "osm.gz")};
osmium::io::Header header = reader.header();
const osmium::io::Header header{reader.header()};
REQUIRE(header.get("generator") == "testdata");
osmium::memory::Buffer buffer = reader.read();
@@ -296,8 +298,8 @@ TEST_CASE("Reading OSM XML 121") {
SECTION("Using Reader") {
// can throw osmium::gzip_error or osmium::xml_error
REQUIRE_THROWS({
osmium::io::Reader reader(filename("121-truncated_gzip_file", "osm.gz"));
osmium::io::Header header = reader.header();
osmium::io::Reader reader{filename("121-truncated_gzip_file", "osm.gz")};
const osmium::io::Header header{reader.header()};
osmium::memory::Buffer buffer = reader.read();
reader.close();
});
@@ -317,8 +319,8 @@ TEST_CASE("Reading OSM XML 122") {
SECTION("Using Reader") {
REQUIRE_THROWS_AS({
osmium::io::Reader reader(filename("122-no_osm_element"));
osmium::io::Header header = reader.header();
osmium::io::Reader reader{filename("122-no_osm_element")};
const osmium::io::Header header{reader.header()};
osmium::memory::Buffer buffer = reader.read();
reader.close();
}, osmium::xml_error);
@@ -331,19 +333,19 @@ TEST_CASE("Reading OSM XML 122") {
TEST_CASE("Reading OSM XML 140") {
SECTION("Using Reader") {
osmium::io::Reader reader(filename("140-unicode"));
osmium::io::Reader reader{filename("140-unicode")};
osmium::memory::Buffer buffer = reader.read();
reader.close();
int count = 0;
for (auto it = buffer.begin<osmium::Node>(); it != buffer.end<osmium::Node>(); ++it) {
for (const auto& node : buffer.select<osmium::Node>()) {
++count;
REQUIRE(it->id() == count);
const osmium::TagList& t = it->tags();
REQUIRE(node.id() == count);
const osmium::TagList& t = node.tags();
const char* uc = t["unicode_char"];
auto len = atoi(t["unicode_utf8_length"]);
const auto len = atoi(t["unicode_utf8_length"]);
REQUIRE(len == strlen(uc));
REQUIRE(S_(uc) == t["unicode_xml"]);
@@ -382,7 +384,7 @@ TEST_CASE("Reading OSM XML 140") {
TEST_CASE("Reading OSM XML 141") {
SECTION("Using Reader") {
osmium::io::Reader reader(filename("141-entities"));
osmium::io::Reader reader{filename("141-entities")};
osmium::memory::Buffer buffer = reader.read();
reader.close();
REQUIRE(buffer.committed() > 0);
@@ -406,40 +408,40 @@ TEST_CASE("Reading OSM XML 141") {
TEST_CASE("Reading OSM XML 142") {
SECTION("Using Reader to read nodes") {
osmium::io::Reader reader(filename("142-whitespace"));
osmium::io::Reader reader{filename("142-whitespace")};
osmium::memory::Buffer buffer = reader.read();
reader.close();
int count = 0;
for (auto it = buffer.begin<osmium::Node>(); it != buffer.end<osmium::Node>(); ++it) {
for (const auto& node : buffer.select<osmium::Node>()) {
++count;
REQUIRE(it->id() == count);
REQUIRE(it->tags().size() == 1);
const osmium::Tag& tag = *(it->tags().begin());
REQUIRE(node.id() == count);
REQUIRE(node.tags().size() == 1);
const osmium::Tag& tag = *(node.tags().begin());
switch (count) {
case 1:
REQUIRE(S_(it->user()) == "user name");
REQUIRE(S_(node.user()) == "user name");
REQUIRE(S_(tag.key()) == "key with space");
REQUIRE(S_(tag.value()) == "value with space");
break;
case 2:
REQUIRE(S_(it->user()) == "line\nfeed");
REQUIRE(S_(node.user()) == "line\nfeed");
REQUIRE(S_(tag.key()) == "key with\nlinefeed");
REQUIRE(S_(tag.value()) == "value with\nlinefeed");
break;
case 3:
REQUIRE(S_(it->user()) == "carriage\rreturn");
REQUIRE(S_(node.user()) == "carriage\rreturn");
REQUIRE(S_(tag.key()) == "key with\rcarriage\rreturn");
REQUIRE(S_(tag.value()) == "value with\rcarriage\rreturn");
break;
case 4:
REQUIRE(S_(it->user()) == "tab\tulator");
REQUIRE(S_(node.user()) == "tab\tulator");
REQUIRE(S_(tag.key()) == "key with\ttab");
REQUIRE(S_(tag.value()) == "value with\ttab");
break;
case 5:
REQUIRE(S_(it->user()) == "unencoded linefeed");
REQUIRE(S_(node.user()) == "unencoded linefeed");
REQUIRE(S_(tag.key()) == "key with unencoded linefeed");
REQUIRE(S_(tag.value()) == "value with unencoded linefeed");
break;
@@ -451,12 +453,12 @@ TEST_CASE("Reading OSM XML 142") {
}
SECTION("Using Reader to read relation") {
osmium::io::Reader reader(filename("142-whitespace"));
osmium::io::Reader reader{filename("142-whitespace")};
osmium::memory::Buffer buffer = reader.read();
reader.close();
auto it = buffer.begin<osmium::Relation>();
REQUIRE(it != buffer.end<osmium::Relation>());
auto it = buffer.select<osmium::Relation>().begin();
REQUIRE(it != buffer.select<osmium::Relation>().end());
REQUIRE(it->id() == 21);
const auto& members = it->members();
REQUIRE(members.size() == 5);
@@ -505,9 +507,9 @@ TEST_CASE("Reading OSM XML 200") {
}
SECTION("Using Reader") {
osmium::io::Reader reader(filename("200-nodes"));
osmium::io::Reader reader{filename("200-nodes")};
osmium::io::Header header = reader.header();
const osmium::io::Header header{reader.header()};
REQUIRE(header.get("generator") == "testdata");
osmium::memory::Buffer buffer = reader.read();
@@ -519,9 +521,9 @@ TEST_CASE("Reading OSM XML 200") {
}
SECTION("Using Reader asking for nodes") {
osmium::io::Reader reader(filename("200-nodes"), osmium::osm_entity_bits::node);
osmium::io::Reader reader{filename("200-nodes"), osmium::osm_entity_bits::node};
osmium::io::Header header = reader.header();
const osmium::io::Header header{reader.header()};
REQUIRE(header.get("generator") == "testdata");
osmium::memory::Buffer buffer = reader.read();
@@ -533,9 +535,9 @@ TEST_CASE("Reading OSM XML 200") {
}
SECTION("Using Reader asking for header only") {
osmium::io::Reader reader(filename("200-nodes"), osmium::osm_entity_bits::nothing);
osmium::io::Reader reader{filename("200-nodes"), osmium::osm_entity_bits::nothing};
osmium::io::Header header = reader.header();
const osmium::io::Header header{reader.header()};
REQUIRE(header.get("generator") == "testdata");
REQUIRE_THROWS({
@@ -546,9 +548,9 @@ TEST_CASE("Reading OSM XML 200") {
}
SECTION("Using Reader asking for ways") {
osmium::io::Reader reader(filename("200-nodes"), osmium::osm_entity_bits::way);
osmium::io::Reader reader{filename("200-nodes"), osmium::osm_entity_bits::way};
osmium::io::Header header = reader.header();
const osmium::io::Header header{reader.header()};
REQUIRE(header.get("generator") == "testdata");
osmium::memory::Buffer buffer = reader.read();