First Commit
This commit is contained in:
commit
8a6c7106e3
1312 files changed
+425396
No files matched your search
@@ -0,0 +1 @@
|
||||
multipolygon.qgs~
|
||||
@@ -0,0 +1,128 @@
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# CMake Config
|
||||
#
|
||||
# Libosmium data tests
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
message(STATUS "Configuring data tests")
|
||||
|
||||
if(NOT GDAL_FOUND OR NOT EXPAT_FOUND)
|
||||
message(STATUS "Sorry, building data tests needs GDAL and Expat")
|
||||
message(STATUS "Configuring data tests - failed")
|
||||
return()
|
||||
endif()
|
||||
|
||||
message(STATUS "Looking for osm-testdata")
|
||||
find_path(OSM_TESTDATA grid/data/all.osm HINT osm-testdata)
|
||||
if(OSM_TESTDATA STREQUAL "OSM_TESTDATA-NOTFOUND")
|
||||
message(STATUS "Looking for osm-testdata - not found (data tests disabled)")
|
||||
message(STATUS "Configuring data tests - failed")
|
||||
return()
|
||||
endif()
|
||||
message(STATUS "Looking for osm-testdata - found")
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
include_directories(SYSTEM ../catch)
|
||||
include_directories(include)
|
||||
include_directories(../include)
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# testcases
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
file(GLOB TESTCASE_CPPS testcases/*.cpp)
|
||||
add_executable(testdata-testcases testdata-testcases.cpp ${TESTCASE_CPPS})
|
||||
set_pthread_on_target(testdata-testcases)
|
||||
target_link_libraries(testdata-testcases
|
||||
${OSMIUM_XML_LIBRARIES}
|
||||
)
|
||||
add_test(NAME testdata-testcases
|
||||
COMMAND testdata-testcases
|
||||
)
|
||||
set_tests_properties(testdata-testcases PROPERTIES
|
||||
ENVIRONMENT "TESTCASES_DIR=${OSM_TESTDATA}/grid/data"
|
||||
LABELS "data;fast")
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# xml
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
add_executable(testdata-xml testdata-xml.cpp)
|
||||
set_pthread_on_target(testdata-xml)
|
||||
target_link_libraries(testdata-xml
|
||||
${OSMIUM_XML_LIBRARIES}
|
||||
)
|
||||
add_test(NAME testdata-xml
|
||||
COMMAND testdata-xml
|
||||
)
|
||||
set_tests_properties(testdata-xml PROPERTIES
|
||||
ENVIRONMENT "TESTDIR=${OSM_TESTDATA}/xml/data"
|
||||
LABELS "data;fast")
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# overview
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
add_executable(testdata-overview testdata-overview.cpp)
|
||||
set_pthread_on_target(testdata-overview)
|
||||
target_link_libraries(testdata-overview
|
||||
${OSMIUM_XML_LIBRARIES}
|
||||
${GDAL_LIBRARIES}
|
||||
)
|
||||
add_test(NAME testdata-overview
|
||||
COMMAND testdata-overview ${OSM_TESTDATA}/grid/data/all.osm
|
||||
)
|
||||
set_tests_properties(testdata-overview PROPERTIES
|
||||
LABELS "data;slow")
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# multipolygon
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
find_program(RUBY ruby)
|
||||
if(RUBY)
|
||||
find_package(Gem COMPONENTS json)
|
||||
endif()
|
||||
|
||||
find_program(SPATIALITE spatialite)
|
||||
|
||||
if(RUBY AND GEM_json_FOUND AND SPATIALITE)
|
||||
add_executable(testdata-multipolygon testdata-multipolygon.cpp)
|
||||
set_pthread_on_target(testdata-multipolygon)
|
||||
target_link_libraries(testdata-multipolygon
|
||||
${OSMIUM_XML_LIBRARIES}
|
||||
${GDAL_LIBRARIES}
|
||||
)
|
||||
|
||||
add_test(NAME testdata-multipolygon
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-D OSM_TESTDATA=${OSM_TESTDATA}
|
||||
-D RUBY=${RUBY}
|
||||
-D EXECUTABLE=$<TARGET_FILE:testdata-multipolygon>
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/run-testdata-multipolygon.cmake)
|
||||
|
||||
set_tests_properties(testdata-multipolygon PROPERTIES LABELS "data;slow")
|
||||
configure_file(multipolygon.qgs ${CMAKE_CURRENT_BINARY_DIR}/multipolygon.qgs @ONLY)
|
||||
else()
|
||||
message(WARNING "Disabled testdata-multipolygon test because 'ruby' and/or 'json' ruby gem and/or 'spatialite' was not found")
|
||||
endif()
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
message(STATUS "Configuring data tests - done")
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
# OSM Testdata
|
||||
|
||||
This directory contains software that can be used with the osm-testdata
|
||||
repository at https://github.com/osmcode/osm-testdata . To use it, clone
|
||||
the `osm-testdata` repository in the same directory where you cloned the
|
||||
`libosmium` repository.
|
||||
|
||||
Tests will be built if the CMake option `BUILD_DATA_TESTS` is set and run as
|
||||
part of the `ctest` run.
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
#ifndef CHECK_BASICS_HANDLER_HPP
|
||||
#define CHECK_BASICS_HANDLER_HPP
|
||||
|
||||
#include <iostream>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <osmium/handler.hpp>
|
||||
#include <osmium/osm.hpp>
|
||||
|
||||
/**
|
||||
* Check some basics of the input data:
|
||||
*
|
||||
* 1. Correct number of nodes, ways, and relations
|
||||
* 2. Correct ID space used by nodes, ways, and relations
|
||||
* 3. No ID used more than once
|
||||
*/
|
||||
class CheckBasicsHandler : public osmium::handler::Handler {
|
||||
|
||||
// Lower bound for the id range allowed in this test.
|
||||
int m_id_range;
|
||||
|
||||
// In the beginning these contains the number of nodes, ways, and relations
|
||||
// supposedly in the data.osm file. They will be decremented on each object
|
||||
// and have to be 0 at the end.
|
||||
int m_num_nodes;
|
||||
int m_num_ways;
|
||||
int m_num_relations;
|
||||
|
||||
// All IDs encountered in the data.osm file will be stored in this set and
|
||||
// checked for duplicates.
|
||||
std::unordered_set<osmium::object_id_type> m_ids;
|
||||
|
||||
// Check id is in range [min, max] and that it isn't more than once in input.
|
||||
void id_check(osmium::object_id_type id, osmium::object_id_type min, osmium::object_id_type max) {
|
||||
if (id < m_id_range + min || id > m_id_range + max) {
|
||||
std::cerr << " id " << id << " out of range for this test case\n";
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
auto r = m_ids.insert(id);
|
||||
if (!r.second) {
|
||||
std::cerr << " id " << id << " contained twice in data.osm\n";
|
||||
std::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
static const int ids_per_testcase = 1000;
|
||||
|
||||
CheckBasicsHandler(int testcase, int nodes, int ways, int relations) :
|
||||
osmium::handler::Handler(),
|
||||
m_id_range(testcase * ids_per_testcase),
|
||||
m_num_nodes(nodes),
|
||||
m_num_ways(ways),
|
||||
m_num_relations(relations) {
|
||||
}
|
||||
|
||||
~CheckBasicsHandler() {
|
||||
if (m_num_nodes != 0) {
|
||||
std::cerr << " wrong number of nodes in data.osm\n";
|
||||
std::exit(1);
|
||||
}
|
||||
if (m_num_ways != 0) {
|
||||
std::cerr << " wrong number of ways in data.osm\n";
|
||||
std::exit(1);
|
||||
}
|
||||
if (m_num_relations != 0) {
|
||||
std::cerr << " wrong number of relations in data.osm\n";
|
||||
std::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void node(const osmium::Node& node) {
|
||||
id_check(node.id(), 0, 799);
|
||||
--m_num_nodes;
|
||||
}
|
||||
|
||||
void way(const osmium::Way& way) {
|
||||
id_check(way.id(), 800, 899);
|
||||
--m_num_ways;
|
||||
}
|
||||
|
||||
void relations(const osmium::Relation& relation) {
|
||||
id_check(relation.id(), 900, 999);
|
||||
--m_num_relations;
|
||||
}
|
||||
|
||||
}; // CheckBasicsHandler
|
||||
|
||||
|
||||
#endif // CHECK_BASICS_HANDLER_HPP
|
||||
@@ -0,0 +1,88 @@
|
||||
#ifndef CHECK_WKT_HANDLER_HPP
|
||||
#define CHECK_WKT_HANDLER_HPP
|
||||
|
||||
#include <cassert>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <osmium/handler.hpp>
|
||||
#include <osmium/osm.hpp>
|
||||
#include <osmium/osm/types.hpp>
|
||||
|
||||
class CheckWKTHandler : public osmium::handler::Handler {
|
||||
|
||||
std::map<osmium::object_id_type, std::string> m_geometries;
|
||||
osmium::geom::WKTFactory<> m_factory;
|
||||
|
||||
void read_wkt_file(const std::string& filename) {
|
||||
std::ifstream in{filename, std::ifstream::in};
|
||||
if (in) {
|
||||
osmium::object_id_type id;
|
||||
std::string line;
|
||||
while (std::getline(in, line)) {
|
||||
const std::size_t pos = line.find_first_of(' ');
|
||||
|
||||
if (pos == std::string::npos) {
|
||||
std::cerr << filename << " not formatted correctly\n";
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
std::string id_str = line.substr(0, pos);
|
||||
std::istringstream iss{id_str};
|
||||
iss >> id;
|
||||
|
||||
if (m_geometries.find(id) != m_geometries.end()) {
|
||||
std::cerr << filename + " contains id " << id << "twice\n";
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
m_geometries[id] = line.substr(pos+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
CheckWKTHandler(const std::string& dirname, int test_id) :
|
||||
osmium::handler::Handler() {
|
||||
|
||||
std::string filename = dirname + "/" + std::to_string(test_id / 100) + "/" + std::to_string(test_id) + "/";
|
||||
read_wkt_file(filename + "nodes.wkt");
|
||||
read_wkt_file(filename + "ways.wkt");
|
||||
}
|
||||
|
||||
~CheckWKTHandler() {
|
||||
if (!m_geometries.empty()) {
|
||||
for (const auto& geom : m_geometries) {
|
||||
std::cerr << "geometry id " << geom.first << " not in data.osm.\n";
|
||||
}
|
||||
std::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void node(const osmium::Node& node) {
|
||||
const std::string wkt = m_geometries[node.id()];
|
||||
assert(wkt != "" && "Missing geometry for node in nodes.wkt");
|
||||
|
||||
const std::string this_wkt = m_factory.create_point(node.location());
|
||||
assert(wkt == this_wkt && "wkt geometries don't match");
|
||||
m_geometries.erase(node.id());
|
||||
}
|
||||
|
||||
void way(const osmium::Way& way) {
|
||||
const std::string wkt = m_geometries[way.id()];
|
||||
assert(wkt != "" && "Missing geometry for way in ways.wkt");
|
||||
|
||||
if (wkt != "NULL") {
|
||||
const std::string this_wkt = m_factory.create_linestring(way);
|
||||
assert(wkt == this_wkt && "wkt geometries don't match");
|
||||
}
|
||||
m_geometries.erase(way.id());
|
||||
}
|
||||
|
||||
}; // CheckWKTHandler
|
||||
|
||||
|
||||
#endif // CHECK_WKT_HANDLER_HPP
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef COMMON_HPP
|
||||
#define COMMON_HPP
|
||||
|
||||
#include <osmium/index/map/dummy.hpp>
|
||||
#include <osmium/index/map/sparse_mem_array.hpp>
|
||||
|
||||
#include <osmium/geom/wkt.hpp>
|
||||
#include <osmium/handler.hpp>
|
||||
#include <osmium/handler/node_locations_for_ways.hpp>
|
||||
#include <osmium/io/xml_input.hpp>
|
||||
#include <osmium/visitor.hpp>
|
||||
|
||||
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"
|
||||
|
||||
#include "testdata-testcases.hpp"
|
||||
|
||||
#endif // COMMON_HPP
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef TESTDATA_TESTCASES_HPP
|
||||
#define TESTDATA_TESTCASES_HPP
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
extern std::string dirname;
|
||||
|
||||
#endif // TESTDATA_TESTCASES_HPP
|
||||
+1213
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,45 @@
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Helper script that runs the 'multipolygon' test.
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
# Remove files that might be left over from previous run
|
||||
file(REMOVE multipolygon.db multipolygon-tests.json)
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Create multipolygons from test data.
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
execute_process(
|
||||
COMMAND ${EXECUTABLE} ${OSM_TESTDATA}/grid/data/all.osm
|
||||
RESULT_VARIABLE _result
|
||||
OUTPUT_FILE multipolygon.log
|
||||
ERROR_FILE multipolygon.log
|
||||
)
|
||||
|
||||
if(_result)
|
||||
message(FATAL_ERROR "Error running testdata-multipolygon command")
|
||||
endif()
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Compare created multipolygons with reference data.
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
execute_process(
|
||||
COMMAND ${RUBY} ${OSM_TESTDATA}/bin/compare-areas.rb
|
||||
${OSM_TESTDATA}/grid/data/tests.json
|
||||
multipolygon-tests.json
|
||||
RESULT_VARIABLE _result
|
||||
)
|
||||
|
||||
if(_result)
|
||||
message(FATAL_ERROR "Error running compare-areas command")
|
||||
endif()
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
@@ -0,0 +1,41 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
class TestHandler100 : public osmium::handler::Handler {
|
||||
|
||||
public:
|
||||
|
||||
TestHandler100() :
|
||||
osmium::handler::Handler() {
|
||||
}
|
||||
|
||||
void node(const osmium::Node& node) const {
|
||||
constexpr const double epsilon = 0.00000001;
|
||||
if (node.id() == 100000) {
|
||||
REQUIRE(node.version() == 1);
|
||||
REQUIRE(node.timestamp() == osmium::Timestamp{"2014-01-01T00:00:00Z"});
|
||||
REQUIRE(node.uid() == 1);
|
||||
REQUIRE(!std::strcmp(node.user(), "test"));
|
||||
REQUIRE(node.changeset() == 1);
|
||||
REQUIRE(node.location().lon() == Approx(1.02).epsilon(epsilon));
|
||||
REQUIRE(node.location().lat() == Approx(1.02).epsilon(epsilon));
|
||||
} else {
|
||||
throw std::runtime_error{"Unknown ID"};
|
||||
}
|
||||
}
|
||||
|
||||
}; // class TestHandler100
|
||||
|
||||
TEST_CASE("100") {
|
||||
osmium::io::Reader reader{dirname + "/1/100/data.osm"};
|
||||
|
||||
CheckBasicsHandler check_basics_handler{100, 1, 0, 0};
|
||||
CheckWKTHandler check_wkt_handler{dirname, 100};
|
||||
TestHandler100 test_handler;
|
||||
|
||||
osmium::apply(reader, check_basics_handler, check_wkt_handler, test_handler);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
class TestHandler101 : public osmium::handler::Handler {
|
||||
|
||||
public:
|
||||
|
||||
TestHandler101() :
|
||||
osmium::handler::Handler() {
|
||||
}
|
||||
|
||||
void node(const osmium::Node& node) const {
|
||||
constexpr const double epsilon = 0.00000001;
|
||||
if (node.id() == 101000) {
|
||||
REQUIRE(node.version() == 1);
|
||||
REQUIRE(node.location().lon() == Approx(1.12).epsilon(epsilon));
|
||||
REQUIRE(node.location().lat() == Approx(1.02).epsilon(epsilon));
|
||||
} else if (node.id() == 101001) {
|
||||
REQUIRE(node.version() == 1);
|
||||
REQUIRE(node.location().lon() == Approx(1.12).epsilon(epsilon));
|
||||
REQUIRE(node.location().lat() == Approx(1.03).epsilon(epsilon));
|
||||
} else if (node.id() == 101002) {
|
||||
} else if (node.id() == 101003) {
|
||||
} else {
|
||||
throw std::runtime_error{"Unknown ID"};
|
||||
}
|
||||
}
|
||||
|
||||
}; // class TestHandler101
|
||||
|
||||
TEST_CASE("101") {
|
||||
osmium::io::Reader reader{dirname + "/1/101/data.osm"};
|
||||
|
||||
CheckBasicsHandler check_basics_handler{101, 4, 0, 0};
|
||||
CheckWKTHandler check_wkt_handler{dirname, 101};
|
||||
TestHandler101 test_handler;
|
||||
|
||||
osmium::apply(reader, check_basics_handler, check_wkt_handler, test_handler);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
class TestHandler102 : public osmium::handler::Handler {
|
||||
|
||||
osmium::Location location;
|
||||
|
||||
public:
|
||||
|
||||
TestHandler102() :
|
||||
osmium::handler::Handler() {
|
||||
}
|
||||
|
||||
void node(const osmium::Node& node) {
|
||||
constexpr const double epsilon = 0.00000001;
|
||||
if (node.id() == 102000) {
|
||||
REQUIRE(node.version() == 1);
|
||||
REQUIRE(node.location().lon() == Approx(1.24).epsilon(epsilon));
|
||||
REQUIRE(node.location().lat() == Approx(1.02).epsilon(epsilon));
|
||||
location = node.location();
|
||||
} else if (node.id() == 102001) {
|
||||
REQUIRE(node.version() == 1);
|
||||
REQUIRE(node.location().lon() == Approx(1.24).epsilon(epsilon));
|
||||
REQUIRE(node.location().lat() == Approx(1.02).epsilon(epsilon));
|
||||
REQUIRE(node.location() == location);
|
||||
} else {
|
||||
throw std::runtime_error{"Unknown ID"};
|
||||
}
|
||||
}
|
||||
|
||||
}; // class TestHandler102
|
||||
|
||||
TEST_CASE("102") {
|
||||
osmium::io::Reader reader{dirname + "/1/102/data.osm"};
|
||||
|
||||
CheckBasicsHandler check_basics_handler{102, 2, 0, 0};
|
||||
CheckWKTHandler check_wkt_handler{dirname, 102};
|
||||
TestHandler102 test_handler;
|
||||
|
||||
osmium::apply(reader, check_basics_handler, check_wkt_handler, test_handler);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
class TestHandler110 : public osmium::handler::Handler {
|
||||
|
||||
public:
|
||||
|
||||
TestHandler110() :
|
||||
osmium::handler::Handler() {
|
||||
}
|
||||
|
||||
void node(const osmium::Node& node) const {
|
||||
constexpr const double epsilon = 0.00000001;
|
||||
if (node.id() == 110000) {
|
||||
REQUIRE(node.location().lon() == Approx(1.02).epsilon(epsilon));
|
||||
REQUIRE(node.location().lat() == Approx(1.12).epsilon(epsilon));
|
||||
} else if (node.id() == 110001) {
|
||||
REQUIRE(node.location().lon() == Approx(1.07).epsilon(epsilon));
|
||||
REQUIRE(node.location().lat() == Approx(1.13).epsilon(epsilon));
|
||||
} else {
|
||||
throw std::runtime_error{"Unknown ID"};
|
||||
}
|
||||
}
|
||||
|
||||
void way(const osmium::Way& way) const {
|
||||
if (way.id() == 110800) {
|
||||
REQUIRE(way.version() == 1);
|
||||
REQUIRE(way.nodes().size() == 2);
|
||||
REQUIRE_FALSE(way.is_closed());
|
||||
|
||||
const char *test_id = way.tags().get_value_by_key("test:id");
|
||||
REQUIRE(test_id);
|
||||
REQUIRE(!std::strcmp(test_id, "110"));
|
||||
} else {
|
||||
throw std::runtime_error{"Unknown ID"};
|
||||
}
|
||||
}
|
||||
|
||||
}; // class TestHandler110
|
||||
|
||||
TEST_CASE("110") {
|
||||
osmium::io::Reader reader{dirname + "/1/110/data.osm"};
|
||||
|
||||
index_pos_type index_pos;
|
||||
index_neg_type index_neg;
|
||||
location_handler_type location_handler{index_pos, index_neg};
|
||||
location_handler.ignore_errors();
|
||||
|
||||
CheckBasicsHandler check_basics_handler{110, 2, 1, 0};
|
||||
CheckWKTHandler check_wkt_handler{dirname, 110};
|
||||
TestHandler110 test_handler;
|
||||
|
||||
osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
class TestHandler111 : public osmium::handler::Handler {
|
||||
|
||||
public:
|
||||
|
||||
TestHandler111() :
|
||||
osmium::handler::Handler() {
|
||||
}
|
||||
|
||||
void way(const osmium::Way& way) const {
|
||||
if (way.id() == 111800) {
|
||||
REQUIRE(way.version() == 1);
|
||||
REQUIRE(way.nodes().size() == 4);
|
||||
REQUIRE_FALSE(way.is_closed());
|
||||
|
||||
const char *test_id = way.tags().get_value_by_key("test:id");
|
||||
REQUIRE(test_id);
|
||||
REQUIRE(!std::strcmp(test_id, "111"));
|
||||
} else {
|
||||
throw std::runtime_error{"Unknown ID"};
|
||||
}
|
||||
}
|
||||
|
||||
}; // class TestHandler111
|
||||
|
||||
TEST_CASE("111") {
|
||||
osmium::io::Reader reader{dirname + "/1/111/data.osm"};
|
||||
|
||||
index_pos_type index_pos;
|
||||
index_neg_type index_neg;
|
||||
location_handler_type location_handler{index_pos, index_neg};
|
||||
location_handler.ignore_errors();
|
||||
|
||||
CheckBasicsHandler check_basics_handler{111, 4, 1, 0};
|
||||
CheckWKTHandler check_wkt_handler{dirname, 111};
|
||||
TestHandler111 test_handler;
|
||||
|
||||
osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
class TestHandler112 : public osmium::handler::Handler {
|
||||
|
||||
public:
|
||||
|
||||
TestHandler112() :
|
||||
osmium::handler::Handler() {
|
||||
}
|
||||
|
||||
void way(const osmium::Way& way) const {
|
||||
if (way.id() == 112800) {
|
||||
REQUIRE(way.version() == 1);
|
||||
REQUIRE(way.nodes().size() == 5);
|
||||
REQUIRE(way.is_closed());
|
||||
|
||||
const char *test_id = way.tags().get_value_by_key("test:id");
|
||||
REQUIRE(test_id);
|
||||
REQUIRE(!std::strcmp(test_id, "112"));
|
||||
} else {
|
||||
throw std::runtime_error{"Unknown ID"};
|
||||
}
|
||||
}
|
||||
|
||||
}; // class TestHandler112
|
||||
|
||||
TEST_CASE("112") {
|
||||
osmium::io::Reader reader{dirname + "/1/112/data.osm"};
|
||||
|
||||
index_pos_type index_pos;
|
||||
index_neg_type index_neg;
|
||||
location_handler_type location_handler{index_pos, index_neg};
|
||||
location_handler.ignore_errors();
|
||||
|
||||
CheckBasicsHandler check_basics_handler{112, 4, 1, 0};
|
||||
CheckWKTHandler check_wkt_handler{dirname, 112};
|
||||
TestHandler112 test_handler;
|
||||
|
||||
osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
class TestHandler113 : public osmium::handler::Handler {
|
||||
|
||||
public:
|
||||
|
||||
TestHandler113() :
|
||||
osmium::handler::Handler() {
|
||||
}
|
||||
|
||||
void node(const osmium::Node& node) const {
|
||||
constexpr const double epsilon = 0.00000001;
|
||||
if (node.id() == 113000) {
|
||||
REQUIRE(node.location().lon() == Approx(1.32).epsilon(epsilon));
|
||||
REQUIRE(node.location().lat() == Approx(1.12).epsilon(epsilon));
|
||||
} else if (node.id() == 113001) {
|
||||
REQUIRE(node.location().lon() == Approx(1.34).epsilon(epsilon));
|
||||
REQUIRE(node.location().lat() == Approx(1.13).epsilon(epsilon));
|
||||
} else if (node.id() == 113002) {
|
||||
REQUIRE(node.location().lon() == Approx(1.37).epsilon(epsilon));
|
||||
REQUIRE(node.location().lat() == Approx(1.12).epsilon(epsilon));
|
||||
} else if (node.id() == 113003) {
|
||||
REQUIRE(node.location().lon() == Approx(1.38).epsilon(epsilon));
|
||||
REQUIRE(node.location().lat() == Approx(1.18).epsilon(epsilon));
|
||||
} else {
|
||||
throw std::runtime_error{"Unknown ID"};
|
||||
}
|
||||
}
|
||||
|
||||
void way(const osmium::Way& way) const {
|
||||
if (way.id() == 113800) {
|
||||
REQUIRE(way.version() == 1);
|
||||
REQUIRE(way.nodes().size() == 2);
|
||||
REQUIRE_FALSE(way.is_closed());
|
||||
REQUIRE(way.nodes()[0].ref() == 113000);
|
||||
REQUIRE(way.nodes()[1].ref() == 113001);
|
||||
} else if (way.id() == 113801) {
|
||||
REQUIRE(way.version() == 1);
|
||||
REQUIRE(way.nodes().size() == 2);
|
||||
REQUIRE_FALSE(way.is_closed());
|
||||
REQUIRE(way.nodes()[0].ref() == 113002);
|
||||
REQUIRE(way.nodes()[1].ref() == 113003);
|
||||
} else {
|
||||
throw std::runtime_error{"Unknown ID"};
|
||||
}
|
||||
}
|
||||
|
||||
}; // class TestHandler113
|
||||
|
||||
TEST_CASE("113") {
|
||||
osmium::io::Reader reader{dirname + "/1/113/data.osm"};
|
||||
|
||||
index_pos_type index_pos;
|
||||
index_neg_type index_neg;
|
||||
location_handler_type location_handler{index_pos, index_neg};
|
||||
location_handler.ignore_errors();
|
||||
|
||||
CheckBasicsHandler check_basics_handler{113, 4, 2, 0};
|
||||
CheckWKTHandler check_wkt_handler{dirname, 113};
|
||||
TestHandler113 test_handler;
|
||||
|
||||
osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
class TestHandler114 : public osmium::handler::Handler {
|
||||
|
||||
public:
|
||||
|
||||
TestHandler114() :
|
||||
osmium::handler::Handler() {
|
||||
}
|
||||
|
||||
void way(const osmium::Way& way) const {
|
||||
if (way.id() == 114800) {
|
||||
REQUIRE(way.version() == 1);
|
||||
REQUIRE(way.nodes().size() == 2);
|
||||
REQUIRE_FALSE(way.is_closed());
|
||||
REQUIRE(way.nodes()[0].ref() == 114000);
|
||||
REQUIRE(way.nodes()[1].ref() == 114001);
|
||||
} else if (way.id() == 114801) {
|
||||
REQUIRE(way.version() == 1);
|
||||
REQUIRE(way.nodes().size() == 2);
|
||||
REQUIRE_FALSE(way.is_closed());
|
||||
REQUIRE(way.nodes()[0].ref() == 114001);
|
||||
REQUIRE(way.nodes()[1].ref() == 114002);
|
||||
} else {
|
||||
throw std::runtime_error{"Unknown ID"};
|
||||
}
|
||||
}
|
||||
|
||||
}; // class TestHandler114
|
||||
|
||||
TEST_CASE("114") {
|
||||
osmium::io::Reader reader{dirname + "/1/114/data.osm"};
|
||||
|
||||
index_pos_type index_pos;
|
||||
index_neg_type index_neg;
|
||||
location_handler_type location_handler{index_pos, index_neg};
|
||||
location_handler.ignore_errors();
|
||||
|
||||
CheckBasicsHandler check_basics_handler{114, 3, 2, 0};
|
||||
CheckWKTHandler check_wkt_handler{dirname, 114};
|
||||
TestHandler114 test_handler;
|
||||
|
||||
osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
class TestHandler115 : public osmium::handler::Handler {
|
||||
|
||||
public:
|
||||
|
||||
TestHandler115() :
|
||||
osmium::handler::Handler() {
|
||||
}
|
||||
|
||||
void way(const osmium::Way& way) const {
|
||||
if (way.id() == 115800) {
|
||||
REQUIRE(way.version() == 1);
|
||||
REQUIRE(way.nodes().size() == 2);
|
||||
REQUIRE_FALSE(way.is_closed());
|
||||
REQUIRE(way.nodes()[0].ref() == 115000);
|
||||
REQUIRE(way.nodes()[1].ref() == 115001);
|
||||
} else if (way.id() == 115801) {
|
||||
REQUIRE(way.version() == 1);
|
||||
REQUIRE(way.nodes().size() == 2);
|
||||
REQUIRE_FALSE(way.is_closed());
|
||||
REQUIRE(way.nodes()[0].ref() == 115002);
|
||||
REQUIRE(way.nodes()[1].ref() == 115001);
|
||||
} else {
|
||||
throw std::runtime_error{"Unknown ID"};
|
||||
}
|
||||
}
|
||||
|
||||
}; // class TestHandler115
|
||||
|
||||
TEST_CASE("115") {
|
||||
osmium::io::Reader reader{dirname + "/1/115/data.osm"};
|
||||
|
||||
index_pos_type index_pos;
|
||||
index_neg_type index_neg;
|
||||
location_handler_type location_handler{index_pos, index_neg};
|
||||
location_handler.ignore_errors();
|
||||
|
||||
CheckBasicsHandler check_basics_handler{115, 3, 2, 0};
|
||||
CheckWKTHandler check_wkt_handler{dirname, 115};
|
||||
TestHandler115 test_handler;
|
||||
|
||||
osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
class TestHandler116 : public osmium::handler::Handler {
|
||||
|
||||
public:
|
||||
|
||||
TestHandler116() :
|
||||
osmium::handler::Handler() {
|
||||
}
|
||||
|
||||
void way(const osmium::Way& way) const {
|
||||
if (way.id() == 116800) {
|
||||
REQUIRE(way.version() == 1);
|
||||
REQUIRE(way.nodes().size() == 2);
|
||||
REQUIRE_FALSE(way.is_closed());
|
||||
REQUIRE(way.nodes()[0].ref() == 116000);
|
||||
REQUIRE(way.nodes()[1].ref() == 116001);
|
||||
} else if (way.id() == 116801) {
|
||||
REQUIRE(way.nodes().size() == 2);
|
||||
} else if (way.id() == 116802) {
|
||||
REQUIRE(way.nodes().size() == 4);
|
||||
} else {
|
||||
throw std::runtime_error{"Unknown ID"};
|
||||
}
|
||||
}
|
||||
|
||||
}; // class TestHandler116
|
||||
|
||||
TEST_CASE("116") {
|
||||
osmium::io::Reader reader{dirname + "/1/116/data.osm"};
|
||||
|
||||
index_pos_type index_pos;
|
||||
index_neg_type index_neg;
|
||||
location_handler_type location_handler{index_pos, index_neg};
|
||||
location_handler.ignore_errors();
|
||||
|
||||
CheckBasicsHandler check_basics_handler{116, 5, 3, 0};
|
||||
CheckWKTHandler check_wkt_handler{dirname, 116};
|
||||
TestHandler116 test_handler;
|
||||
|
||||
osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
class TestHandler120 : public osmium::handler::Handler {
|
||||
|
||||
public:
|
||||
|
||||
TestHandler120() :
|
||||
osmium::handler::Handler() {
|
||||
}
|
||||
|
||||
void way(const osmium::Way& way) const {
|
||||
if (way.id() == 120800) {
|
||||
REQUIRE(way.version() == 1);
|
||||
REQUIRE(way.nodes().empty());
|
||||
} else {
|
||||
throw std::runtime_error{"Unknown ID"};
|
||||
}
|
||||
}
|
||||
|
||||
}; // class TestHandler120
|
||||
|
||||
TEST_CASE("120") {
|
||||
osmium::io::Reader reader{dirname + "/1/120/data.osm"};
|
||||
|
||||
index_pos_type index_pos;
|
||||
index_neg_type index_neg;
|
||||
location_handler_type location_handler{index_pos, index_neg};
|
||||
location_handler.ignore_errors();
|
||||
|
||||
CheckBasicsHandler check_basics_handler{120, 0, 1, 0};
|
||||
TestHandler120 test_handler;
|
||||
|
||||
osmium::apply(reader, location_handler, check_basics_handler, test_handler);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
class TestHandler121 : public osmium::handler::Handler {
|
||||
|
||||
public:
|
||||
|
||||
TestHandler121() :
|
||||
osmium::handler::Handler() {
|
||||
}
|
||||
|
||||
void way(const osmium::Way& way) const {
|
||||
if (way.id() == 121800) {
|
||||
REQUIRE(way.version() == 1);
|
||||
REQUIRE(way.nodes().size() == 1);
|
||||
} else {
|
||||
throw std::runtime_error{"Unknown ID"};
|
||||
}
|
||||
}
|
||||
|
||||
}; // class TestHandler121
|
||||
|
||||
TEST_CASE("121") {
|
||||
osmium::io::Reader reader{dirname + "/1/121/data.osm"};
|
||||
|
||||
index_pos_type index_pos;
|
||||
index_neg_type index_neg;
|
||||
location_handler_type location_handler{index_pos, index_neg};
|
||||
location_handler.ignore_errors();
|
||||
|
||||
CheckBasicsHandler check_basics_handler{121, 1, 1, 0};
|
||||
CheckWKTHandler check_wkt_handler{dirname, 121};
|
||||
TestHandler121 test_handler;
|
||||
|
||||
osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
class TestHandler122 : public osmium::handler::Handler {
|
||||
|
||||
public:
|
||||
|
||||
TestHandler122() :
|
||||
osmium::handler::Handler() {
|
||||
}
|
||||
|
||||
void way(const osmium::Way& way) const {
|
||||
if (way.id() == 122800) {
|
||||
REQUIRE(way.version() == 1);
|
||||
REQUIRE(way.nodes().size() == 2);
|
||||
REQUIRE(way.nodes()[0] == way.nodes()[1]);
|
||||
} else {
|
||||
throw std::runtime_error{"Unknown ID"};
|
||||
}
|
||||
}
|
||||
|
||||
}; // class TestHandler122
|
||||
|
||||
TEST_CASE("122") {
|
||||
osmium::io::Reader reader{dirname + "/1/122/data.osm"};
|
||||
|
||||
index_pos_type index_pos;
|
||||
index_neg_type index_neg;
|
||||
location_handler_type location_handler{index_pos, index_neg};
|
||||
location_handler.ignore_errors();
|
||||
|
||||
CheckBasicsHandler check_basics_handler{122, 1, 1, 0};
|
||||
CheckWKTHandler check_wkt_handler{dirname, 122};
|
||||
TestHandler122 test_handler;
|
||||
|
||||
osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
class TestHandler123 : public osmium::handler::Handler {
|
||||
|
||||
public:
|
||||
|
||||
TestHandler123() :
|
||||
osmium::handler::Handler() {
|
||||
}
|
||||
|
||||
void way(const osmium::Way& way) const {
|
||||
if (way.id() == 123800) {
|
||||
REQUIRE(way.version() == 1);
|
||||
REQUIRE(way.nodes().size() == 2);
|
||||
REQUIRE(way.nodes()[0] != way.nodes()[1]);
|
||||
REQUIRE(way.nodes()[0].location() == way.nodes()[1].location());
|
||||
} else {
|
||||
throw std::runtime_error{"Unknown ID"};
|
||||
}
|
||||
}
|
||||
|
||||
}; // class TestHandler123
|
||||
|
||||
TEST_CASE("123") {
|
||||
osmium::io::Reader reader{dirname + "/1/123/data.osm"};
|
||||
|
||||
index_pos_type index_pos;
|
||||
index_neg_type index_neg;
|
||||
location_handler_type location_handler{index_pos, index_neg};
|
||||
location_handler.ignore_errors();
|
||||
|
||||
CheckBasicsHandler check_basics_handler{123, 2, 1, 0};
|
||||
CheckWKTHandler check_wkt_handler{dirname, 123};
|
||||
TestHandler123 test_handler;
|
||||
|
||||
osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
class TestHandler124 : public osmium::handler::Handler {
|
||||
|
||||
public:
|
||||
|
||||
TestHandler124() :
|
||||
osmium::handler::Handler() {
|
||||
}
|
||||
|
||||
void way(const osmium::Way& way) const {
|
||||
if (way.id() == 124800) {
|
||||
REQUIRE(way.version() == 1);
|
||||
REQUIRE(way.nodes().size() == 3);
|
||||
REQUIRE(way.nodes()[0] != way.nodes()[1]);
|
||||
REQUIRE(way.nodes()[0].location() == way.nodes()[1].location());
|
||||
REQUIRE(way.nodes()[0] != way.nodes()[2]);
|
||||
REQUIRE(way.nodes()[0].location() != way.nodes()[2].location());
|
||||
} else {
|
||||
throw std::runtime_error{"Unknown ID"};
|
||||
}
|
||||
}
|
||||
|
||||
}; // class TestHandler124
|
||||
|
||||
TEST_CASE("124") {
|
||||
osmium::io::Reader reader{dirname + "/1/124/data.osm"};
|
||||
|
||||
index_pos_type index_pos;
|
||||
index_neg_type index_neg;
|
||||
location_handler_type location_handler{index_pos, index_neg};
|
||||
location_handler.ignore_errors();
|
||||
|
||||
CheckBasicsHandler check_basics_handler{124, 3, 1, 0};
|
||||
CheckWKTHandler check_wkt_handler{dirname, 124};
|
||||
TestHandler124 test_handler;
|
||||
|
||||
osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
|
||||
#include <osmium/area/assembler_legacy.hpp>
|
||||
#include <osmium/area/multipolygon_collector.hpp>
|
||||
#include <osmium/area/problem_reporter_ogr.hpp>
|
||||
#include <osmium/geom/ogr.hpp>
|
||||
#include <osmium/geom/wkt.hpp>
|
||||
#include <osmium/handler.hpp>
|
||||
#include <osmium/handler/node_locations_for_ways.hpp>
|
||||
#include <osmium/index/map/sparse_mem_array.hpp>
|
||||
#include <osmium/io/xml_input.hpp>
|
||||
#include <osmium/visitor.hpp>
|
||||
|
||||
#include <gdalcpp.hpp>
|
||||
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
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 noexcept {
|
||||
return std::strcmp(a, b) < 0;
|
||||
}
|
||||
|
||||
}; // less_charptr
|
||||
|
||||
using tagmap_type = std::map<const char*, const char*, less_charptr>;
|
||||
|
||||
tagmap_type create_map(const osmium::TagList& taglist) {
|
||||
tagmap_type map;
|
||||
|
||||
for (const auto& tag : taglist) {
|
||||
map[tag.key()] = tag.value();
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
class TestHandler : public osmium::handler::Handler {
|
||||
|
||||
gdalcpp::Layer m_layer_point;
|
||||
gdalcpp::Layer m_layer_lines;
|
||||
gdalcpp::Layer m_layer_mpoly;
|
||||
|
||||
osmium::geom::OGRFactory<> m_ogr_factory;
|
||||
osmium::geom::WKTFactory<> m_wkt_factory;
|
||||
|
||||
std::ofstream m_out;
|
||||
|
||||
bool m_first_out{true};
|
||||
|
||||
public:
|
||||
|
||||
explicit TestHandler(gdalcpp::Dataset& dataset) :
|
||||
m_layer_point(dataset, "points", wkbPoint),
|
||||
m_layer_lines(dataset, "lines", wkbLineString),
|
||||
m_layer_mpoly(dataset, "multipolygons", wkbMultiPolygon),
|
||||
m_out("multipolygon-tests.json") {
|
||||
|
||||
m_layer_point.add_field("id", OFTReal, 10);
|
||||
m_layer_point.add_field("type", OFTString, 30);
|
||||
|
||||
m_layer_lines.add_field("id", OFTReal, 10);
|
||||
m_layer_lines.add_field("type", OFTString, 30);
|
||||
|
||||
m_layer_mpoly.add_field("id", OFTReal, 10);
|
||||
m_layer_mpoly.add_field("from_type", OFTString, 1);
|
||||
}
|
||||
|
||||
TestHandler(const TestHandler&) = delete;
|
||||
TestHandler& operator=(const TestHandler&) = delete;
|
||||
|
||||
TestHandler(TestHandler&&) = delete;
|
||||
TestHandler& operator=(TestHandler&&) = delete;
|
||||
|
||||
~TestHandler() {
|
||||
m_out << "\n]\n";
|
||||
}
|
||||
|
||||
void node(const osmium::Node& 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();
|
||||
}
|
||||
|
||||
void way(const osmium::Way& way) {
|
||||
try {
|
||||
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 (const osmium::geometry_error&) {
|
||||
std::cerr << "Ignoring illegal geometry for way " << way.id() << ".\n";
|
||||
}
|
||||
}
|
||||
|
||||
void area(const osmium::Area& area) {
|
||||
if (m_first_out) {
|
||||
m_out << "[\n";
|
||||
m_first_out = false;
|
||||
} else {
|
||||
m_out << ",\n";
|
||||
}
|
||||
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 {
|
||||
const std::string wkt = m_wkt_factory.create_multipolygon(area);
|
||||
m_out << wkt << "\",\n \"tags\": {";
|
||||
|
||||
const auto tagmap = create_map(area.tags());
|
||||
bool first = true;
|
||||
for (const auto& tag : tagmap) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
m_out << ", ";
|
||||
}
|
||||
m_out << '"' << tag.first << "\": \"" << tag.second << '"';
|
||||
}
|
||||
m_out << "}\n}";
|
||||
} catch (const osmium::geometry_error&) {
|
||||
m_out << "INVALID\"\n}";
|
||||
}
|
||||
try {
|
||||
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;
|
||||
if (area.from_way()) {
|
||||
from_type = "w";
|
||||
} else {
|
||||
from_type = "r";
|
||||
}
|
||||
feature.set_field("from_type", from_type.c_str());
|
||||
feature.add_to_layer();
|
||||
} 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";
|
||||
}
|
||||
}
|
||||
|
||||
}; // class TestHandler
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " INFILE\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
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"}};
|
||||
|
||||
osmium::area::ProblemReporterOGR problem_reporter{dataset};
|
||||
osmium::area::AssemblerLegacy::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::AssemblerLegacy> collector{assembler_config};
|
||||
|
||||
std::cerr << "Pass 1...\n";
|
||||
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.ignore_errors();
|
||||
|
||||
TestHandler test_handler{dataset};
|
||||
|
||||
std::cerr << "Pass 2...\n";
|
||||
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);
|
||||
}));
|
||||
reader2.close();
|
||||
std::cerr << "Pass 2 done\n";
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/* The code in this file is released into the Public Domain. */
|
||||
|
||||
#include <osmium/geom/ogr.hpp>
|
||||
#include <osmium/handler.hpp>
|
||||
#include <osmium/handler/node_locations_for_ways.hpp>
|
||||
#include <osmium/index/map/sparse_mem_array.hpp>
|
||||
#include <osmium/io/xml_input.hpp>
|
||||
#include <osmium/visitor.hpp>
|
||||
|
||||
#include <gdalcpp.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
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 {
|
||||
|
||||
gdalcpp::Layer m_layer_nodes;
|
||||
gdalcpp::Layer m_layer_labels;
|
||||
gdalcpp::Layer m_layer_ways;
|
||||
|
||||
osmium::geom::OGRFactory<> m_factory;
|
||||
|
||||
public:
|
||||
|
||||
explicit TestOverviewHandler(gdalcpp::Dataset& dataset) :
|
||||
m_layer_nodes(dataset, "nodes", wkbPoint),
|
||||
m_layer_labels(dataset, "labels", wkbPoint),
|
||||
m_layer_ways(dataset, "ways", wkbLineString) {
|
||||
|
||||
m_layer_nodes.add_field("id", OFTReal, 10);
|
||||
|
||||
m_layer_labels.add_field("id", OFTReal, 10);
|
||||
m_layer_labels.add_field("label", OFTString, 30);
|
||||
|
||||
m_layer_ways.add_field("id", OFTReal, 10);
|
||||
m_layer_ways.add_field("test", OFTInteger, 3);
|
||||
}
|
||||
|
||||
void node(const osmium::Node& node) {
|
||||
const char* label = node.tags().get_value_by_key("label");
|
||||
if (label) {
|
||||
gdalcpp::Feature feature(m_layer_labels, m_factory.create_point(node));
|
||||
feature.set_field("id", static_cast<double>(node.id()));
|
||||
feature.set_field("label", label);
|
||||
feature.add_to_layer();
|
||||
} else {
|
||||
gdalcpp::Feature feature(m_layer_nodes, m_factory.create_point(node));
|
||||
feature.set_field("id", static_cast<double>(node.id()));
|
||||
feature.add_to_layer();
|
||||
}
|
||||
}
|
||||
|
||||
void way(const osmium::Way& way) {
|
||||
try {
|
||||
gdalcpp::Feature feature(m_layer_ways, m_factory.create_linestring(way));
|
||||
feature.set_field("id", static_cast<double>(way.id()));
|
||||
|
||||
const char* test = way.tags().get_value_by_key("test");
|
||||
if (test) {
|
||||
feature.set_field("test", test);
|
||||
}
|
||||
|
||||
feature.add_to_layer();
|
||||
} catch (const osmium::geometry_error&) {
|
||||
std::cerr << "Ignoring illegal geometry for way " << way.id() << ".\n";
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " INFILE\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
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"}};
|
||||
|
||||
osmium::io::Reader reader{input_filename};
|
||||
|
||||
index_type index;
|
||||
location_handler_type location_handler{index};
|
||||
location_handler.ignore_errors();
|
||||
|
||||
TestOverviewHandler handler{dataset};
|
||||
|
||||
osmium::apply(reader, location_handler, handler);
|
||||
reader.close();
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
|
||||
#include "testdata-testcases.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
std::string dirname; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
const char* testcases_dir = getenv("TESTCASES_DIR");
|
||||
if (testcases_dir) {
|
||||
dirname = testcases_dir;
|
||||
std::cerr << "Running tests from '" << dirname << "' (from TESTCASES_DIR environment variable)\n";
|
||||
} else {
|
||||
std::cerr << "Please set TESTCASES_DIR environment variable.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
return Catch::Session().run(argc, argv);
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,588 @@
|
||||
/* The code in this file is released into the Public Domain. */
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/io/detail/queue_util.hpp>
|
||||
#include <osmium/io/gzip_compression.hpp>
|
||||
#include <osmium/io/xml_input.hpp>
|
||||
#include <osmium/util/misc.hpp>
|
||||
#include <osmium/visitor.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
|
||||
static std::string S_(const char* s) {
|
||||
return std::string{s};
|
||||
}
|
||||
|
||||
// From C++20 we need to handle unicode literals differently
|
||||
#ifdef __cpp_char8_t
|
||||
static std::string S_(const char8_t* s) {
|
||||
return std::string{reinterpret_cast<const char*>(s)};
|
||||
}
|
||||
#endif
|
||||
|
||||
static std::string filename(const char* test_id, const char* suffix = "osm") {
|
||||
const char* testdir = getenv("TESTDIR");
|
||||
if (!testdir) {
|
||||
throw std::runtime_error{"You have to set TESTDIR environment variable before running testdata-xml"};
|
||||
}
|
||||
|
||||
std::string f;
|
||||
f += testdir;
|
||||
f += "/";
|
||||
f += test_id;
|
||||
f += "/data.";
|
||||
f += suffix;
|
||||
return f;
|
||||
}
|
||||
|
||||
struct header_buffer_type {
|
||||
osmium::io::Header header;
|
||||
osmium::memory::Buffer buffer;
|
||||
};
|
||||
|
||||
// =============================================
|
||||
|
||||
// The following helper functions are used to call different parts of the
|
||||
// Osmium internals used to read and parse XML files. This way those parts
|
||||
// can be tested individually. These function can not be used in normal
|
||||
// operations, because they make certain assumptions, for instance that
|
||||
// file contents fit into small buffers.
|
||||
|
||||
static std::string read_file(const char* test_id) {
|
||||
const int fd = osmium::io::detail::open_for_reading(filename(test_id));
|
||||
assert(fd >= 0);
|
||||
|
||||
std::string input(10000, '\0');
|
||||
const auto n = ::read(fd, &*input.begin(), 10000);
|
||||
assert(n >= 0);
|
||||
input.resize(static_cast<std::string::size_type>(n));
|
||||
|
||||
close(fd);
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
static std::string read_gz_file(const char* test_id, const char* suffix) {
|
||||
const int fd = osmium::io::detail::open_for_reading(filename(test_id, suffix));
|
||||
assert(fd >= 0);
|
||||
|
||||
osmium::io::GzipDecompressor gzip_decompressor{fd};
|
||||
std::string input = gzip_decompressor.read();
|
||||
gzip_decompressor.close();
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
static header_buffer_type parse_xml(std::string input) {
|
||||
osmium::thread::Pool pool;
|
||||
osmium::io::detail::future_string_queue_type input_queue;
|
||||
osmium::io::detail::future_buffer_queue_type output_queue;
|
||||
std::promise<osmium::io::Header> header_promise;
|
||||
std::future<osmium::io::Header> header_future = header_promise.get_future();
|
||||
|
||||
osmium::io::detail::add_to_queue(input_queue, std::move(input));
|
||||
osmium::io::detail::add_to_queue(input_queue, std::string{});
|
||||
|
||||
std::atomic<std::size_t> offset{0};
|
||||
|
||||
osmium::io::detail::parser_arguments args = {
|
||||
pool,
|
||||
-1,
|
||||
input_queue,
|
||||
output_queue,
|
||||
header_promise,
|
||||
&offset,
|
||||
osmium::osm_entity_bits::all,
|
||||
osmium::io::read_meta::yes,
|
||||
osmium::io::buffers_type::any,
|
||||
false
|
||||
};
|
||||
osmium::io::detail::XMLParser parser{args};
|
||||
parser.parse();
|
||||
|
||||
header_buffer_type result;
|
||||
result.header = header_future.get();
|
||||
std::future<osmium::memory::Buffer> future_buffer;
|
||||
output_queue.wait_and_pop(future_buffer);
|
||||
result.buffer = future_buffer.get();
|
||||
|
||||
if (result.buffer) {
|
||||
std::future<osmium::memory::Buffer> future_buffer2;
|
||||
output_queue.wait_and_pop(future_buffer2);
|
||||
assert(!future_buffer2.get());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static header_buffer_type read_xml(const char* test_id) {
|
||||
const std::string input = read_file(test_id);
|
||||
return parse_xml(input);
|
||||
}
|
||||
|
||||
template <typename TException>
|
||||
void test_fail(const char* xml_file_name, const char* errmsg) {
|
||||
REQUIRE_THROWS_AS(read_xml(xml_file_name), TException);
|
||||
REQUIRE_THROWS_WITH(read_xml(xml_file_name), errmsg);
|
||||
|
||||
REQUIRE_THROWS_AS([&](){
|
||||
osmium::io::Reader reader{filename(xml_file_name)};
|
||||
const osmium::io::Header header{reader.header()};
|
||||
const osmium::memory::Buffer buffer = reader.read();
|
||||
reader.close();
|
||||
}(), TException);
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 100: Direct") {
|
||||
const header_buffer_type r = read_xml("100-correct_but_no_data");
|
||||
|
||||
REQUIRE(r.header.get("generator") == "testdata");
|
||||
REQUIRE(0 == r.buffer.committed());
|
||||
REQUIRE_FALSE(r.buffer);
|
||||
}
|
||||
|
||||
TEST_CASE("Reading OSM XML 100: Using Reader") {
|
||||
osmium::io::Reader reader{filename("100-correct_but_no_data")};
|
||||
|
||||
const osmium::io::Header header{reader.header()};
|
||||
REQUIRE(header.get("generator") == "testdata");
|
||||
|
||||
const osmium::memory::Buffer buffer = reader.read();
|
||||
REQUIRE(0 == buffer.committed());
|
||||
REQUIRE_FALSE(buffer);
|
||||
reader.close();
|
||||
}
|
||||
|
||||
TEST_CASE("Reading OSM XML 100: Using Reader asking for header only") {
|
||||
osmium::io::Reader reader{filename("100-correct_but_no_data"), osmium::osm_entity_bits::nothing};
|
||||
|
||||
const osmium::io::Header header{reader.header()};
|
||||
REQUIRE(header.get("generator") == "testdata");
|
||||
reader.close();
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 101") {
|
||||
test_fail<osmium::format_version_error>("101-missing_version", "Can not read file without version (missing version attribute on osm element).");
|
||||
|
||||
try {
|
||||
read_xml("101-missing_version");
|
||||
} catch (const osmium::format_version_error& e) {
|
||||
REQUIRE(e.version.empty());
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 102") {
|
||||
test_fail<osmium::format_version_error>("102-wrong_version", "Can not read file with version 0.1");
|
||||
|
||||
try {
|
||||
read_xml("102-wrong_version");
|
||||
} catch (const osmium::format_version_error& e) {
|
||||
REQUIRE(e.version == "0.1");
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 103") {
|
||||
test_fail<osmium::format_version_error>("103-old_version", "Can not read file with version 0.5");
|
||||
|
||||
try {
|
||||
read_xml("103-old_version");
|
||||
} catch (const osmium::format_version_error& e) {
|
||||
REQUIRE(e.version == "0.5");
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 104") {
|
||||
test_fail<osmium::xml_error>("104-empty_file", "XML parsing error at line 1, column 0: no element found");
|
||||
|
||||
try {
|
||||
read_xml("104-empty_file");
|
||||
} catch (const osmium::xml_error& e) {
|
||||
REQUIRE(e.line == 1);
|
||||
REQUIRE(e.column == 0);
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 105") {
|
||||
test_fail<osmium::xml_error>("105-incomplete_xml_file", "XML parsing error at line 3, column 0: no element found");
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 106") {
|
||||
test_fail<osmium::xml_error>("106-invalid_xml_file", "xml file nested too deep");
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 107") {
|
||||
test_fail<osmium::xml_error>("107-wrongly_nested_xml_file", "Unknown element in <node>: modify");
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 108") {
|
||||
test_fail<osmium::xml_error>("108-unknown_top_level", "Unknown top-level element: foo");
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 109: Direct") {
|
||||
read_xml("109-unknown_data_level");
|
||||
}
|
||||
|
||||
TEST_CASE("Reading OSM XML 109: Using Reader") {
|
||||
osmium::io::Reader reader{filename("109-unknown_data_level")};
|
||||
|
||||
const osmium::io::Header header{reader.header()};
|
||||
const osmium::memory::Buffer buffer = reader.read();
|
||||
REQUIRE(buffer.committed() > 0);
|
||||
reader.close();
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 110") {
|
||||
test_fail<osmium::xml_error>("110-entity_declaration", "XML entities are not supported");
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 120: Direct") {
|
||||
const std::string data = read_gz_file("120-correct_gzip_file_without_data", "osm.gz");
|
||||
|
||||
REQUIRE(data.size() == 102);
|
||||
|
||||
const header_buffer_type r = parse_xml(data);
|
||||
REQUIRE(r.header.get("generator") == "testdata");
|
||||
REQUIRE(0 == r.buffer.committed());
|
||||
REQUIRE_FALSE(r.buffer);
|
||||
}
|
||||
|
||||
TEST_CASE("Reading OSM XML 120: Using Reader") {
|
||||
osmium::io::Reader reader{filename("120-correct_gzip_file_without_data", "osm.gz")};
|
||||
|
||||
const osmium::io::Header header{reader.header()};
|
||||
REQUIRE(header.get("generator") == "testdata");
|
||||
|
||||
const osmium::memory::Buffer buffer = reader.read();
|
||||
REQUIRE(0 == buffer.committed());
|
||||
REQUIRE_FALSE(buffer);
|
||||
reader.close();
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 121: Direct") {
|
||||
REQUIRE_THROWS_AS(read_gz_file("121-truncated_gzip_file", "osm.gz"), osmium::gzip_error);
|
||||
}
|
||||
|
||||
TEST_CASE("Reading OSM XML 121: Using Reader") {
|
||||
// can throw osmium::gzip_error or osmium::xml_error
|
||||
REQUIRE_THROWS([](){
|
||||
osmium::io::Reader reader{filename("121-truncated_gzip_file", "osm.gz")};
|
||||
const osmium::io::Header header{reader.header()};
|
||||
const osmium::memory::Buffer buffer = reader.read();
|
||||
reader.close();
|
||||
}());
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 122") {
|
||||
test_fail<osmium::xml_error>("122-no_osm_element", "Unknown top-level element: node");
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 123") {
|
||||
test_fail<osmium::xml_error>("123-unknown_element_in_node", "Unknown element in <node>: nd");
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 124") {
|
||||
test_fail<osmium::xml_error>("124-unknown_element_in_way", "Unknown element in <way>: member");
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 125") {
|
||||
test_fail<osmium::xml_error>("125-unknown_element_in_relation", "Unknown element in <relation>: nd");
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 126") {
|
||||
test_fail<osmium::xml_error>("126-wrong_member_type", "Unknown type on relation <member>");
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 127") {
|
||||
test_fail<osmium::xml_error>("127-missing_member_type", "Unknown type on relation <member>");
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 128") {
|
||||
test_fail<osmium::xml_error>("128-missing_member_ref", "Missing ref on relation <member>");
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 140: Using Reader") {
|
||||
osmium::io::Reader reader{filename("140-unicode")};
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
reader.close();
|
||||
|
||||
int count = 0;
|
||||
for (const auto& node : buffer.select<osmium::Node>()) {
|
||||
++count;
|
||||
REQUIRE(node.id() == count);
|
||||
const osmium::TagList& t = node.tags();
|
||||
|
||||
const char* uc = t["unicode_char"];
|
||||
|
||||
const auto len = osmium::detail::str_to_int<std::size_t>(t["unicode_utf8_length"]);
|
||||
REQUIRE(len == std::strlen(uc));
|
||||
|
||||
REQUIRE(S_(uc) == t["unicode_xml"]);
|
||||
|
||||
switch (count) {
|
||||
case 1:
|
||||
REQUIRE(S_(uc) == S_(u8"a"));
|
||||
break;
|
||||
case 2:
|
||||
REQUIRE(S_(uc) == S_(u8"\u00e4"));
|
||||
break;
|
||||
case 3:
|
||||
REQUIRE(S_(uc) == S_(u8"\u30dc"));
|
||||
break;
|
||||
case 4:
|
||||
REQUIRE(S_(uc) == S_(u8"\U0001d11e"));
|
||||
break;
|
||||
case 5:
|
||||
REQUIRE(S_(uc) == S_(u8"\U0001f6eb"));
|
||||
break;
|
||||
default:
|
||||
REQUIRE(false); // should not be here
|
||||
}
|
||||
}
|
||||
REQUIRE(count == 5);
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 141: Using Reader") {
|
||||
osmium::io::Reader reader{filename("141-entities")};
|
||||
const osmium::memory::Buffer buffer = reader.read();
|
||||
reader.close();
|
||||
REQUIRE(buffer.committed() > 0);
|
||||
REQUIRE(buffer.get<osmium::memory::Item>(0).type() == osmium::item_type::node);
|
||||
|
||||
const osmium::Node& node = buffer.get<osmium::Node>(0);
|
||||
const osmium::TagList& tags = node.tags();
|
||||
|
||||
REQUIRE(S_(tags["less-than"]) == "<");
|
||||
REQUIRE(S_(tags["greater-than"]) == ">");
|
||||
REQUIRE(S_(tags["apostrophe"]) == "'");
|
||||
REQUIRE(S_(tags["ampersand"]) == "&");
|
||||
REQUIRE(S_(tags["quote"]) == "\"");
|
||||
}
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 142: Using Reader to read nodes") {
|
||||
osmium::io::Reader reader{filename("142-whitespace")};
|
||||
const osmium::memory::Buffer buffer = reader.read();
|
||||
reader.close();
|
||||
|
||||
int count = 0;
|
||||
for (const auto& node : buffer.select<osmium::Node>()) {
|
||||
++count;
|
||||
REQUIRE(node.id() == count);
|
||||
REQUIRE(node.tags().size() == 1);
|
||||
const osmium::Tag& tag = *(node.tags().begin());
|
||||
|
||||
switch (count) {
|
||||
case 1:
|
||||
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_(node.user()) == "line\nfeed");
|
||||
REQUIRE(S_(tag.key()) == "key with\nlinefeed");
|
||||
REQUIRE(S_(tag.value()) == "value with\nlinefeed");
|
||||
break;
|
||||
case 3:
|
||||
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_(node.user()) == "tab\tulator");
|
||||
REQUIRE(S_(tag.key()) == "key with\ttab");
|
||||
REQUIRE(S_(tag.value()) == "value with\ttab");
|
||||
break;
|
||||
case 5:
|
||||
REQUIRE(S_(node.user()) == "unencoded linefeed");
|
||||
REQUIRE(S_(tag.key()) == "key with unencoded linefeed");
|
||||
REQUIRE(S_(tag.value()) == "value with unencoded linefeed");
|
||||
break;
|
||||
default:
|
||||
REQUIRE(false); // should not be here
|
||||
}
|
||||
}
|
||||
REQUIRE(count == 5);
|
||||
}
|
||||
|
||||
TEST_CASE("Reading OSM XML 142: Using Reader to read relation") {
|
||||
osmium::io::Reader reader{filename("142-whitespace")};
|
||||
const osmium::memory::Buffer buffer = reader.read();
|
||||
reader.close();
|
||||
|
||||
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);
|
||||
|
||||
int count = 0;
|
||||
for (const auto& member : members) {
|
||||
++count;
|
||||
switch (count) {
|
||||
case 1:
|
||||
REQUIRE(S_(member.role()) == "role with whitespace");
|
||||
break;
|
||||
case 2:
|
||||
REQUIRE(S_(member.role()) == "role with\nlinefeed");
|
||||
break;
|
||||
case 3:
|
||||
REQUIRE(S_(member.role()) == "role with\rcarriage\rreturn");
|
||||
break;
|
||||
case 4:
|
||||
REQUIRE(S_(member.role()) == "role with\ttab");
|
||||
break;
|
||||
case 5:
|
||||
REQUIRE(S_(member.role()) == "role with unencoded linefeed");
|
||||
break;
|
||||
default:
|
||||
REQUIRE(false); // should not be here
|
||||
}
|
||||
}
|
||||
REQUIRE(count == 5);
|
||||
}
|
||||
|
||||
|
||||
// =============================================
|
||||
|
||||
TEST_CASE("Reading OSM XML 200: Direct") {
|
||||
header_buffer_type r = read_xml("200-nodes");
|
||||
|
||||
REQUIRE(r.header.get("generator") == "testdata");
|
||||
REQUIRE(r.buffer.committed() > 0);
|
||||
REQUIRE(r.buffer.get<osmium::memory::Item>(0).type() == osmium::item_type::node);
|
||||
REQUIRE(r.buffer.get<osmium::Node>(0).id() == 36966060);
|
||||
REQUIRE(std::distance(r.buffer.begin(), r.buffer.end()) == 3);
|
||||
}
|
||||
|
||||
TEST_CASE("Reading OSM XML 200: Using Reader") {
|
||||
osmium::io::Reader reader{filename("200-nodes")};
|
||||
|
||||
const osmium::io::Header header{reader.header()};
|
||||
REQUIRE(header.get("generator") == "testdata");
|
||||
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
REQUIRE(buffer.committed() > 0);
|
||||
REQUIRE(buffer.get<osmium::memory::Item>(0).type() == osmium::item_type::node);
|
||||
REQUIRE(buffer.get<osmium::Node>(0).id() == 36966060);
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 3);
|
||||
reader.close();
|
||||
}
|
||||
|
||||
TEST_CASE("Reading OSM XML 200: Using Reader asking for nodes") {
|
||||
osmium::io::Reader reader{filename("200-nodes"), osmium::osm_entity_bits::node};
|
||||
|
||||
const osmium::io::Header header{reader.header()};
|
||||
REQUIRE(header.get("generator") == "testdata");
|
||||
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
REQUIRE(buffer.committed() > 0);
|
||||
REQUIRE(buffer.get<osmium::memory::Item>(0).type() == osmium::item_type::node);
|
||||
REQUIRE(buffer.get<osmium::Node>(0).id() == 36966060);
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 3);
|
||||
reader.close();
|
||||
}
|
||||
|
||||
TEST_CASE("Reading OSM XML 200: Using Reader asking for header only") {
|
||||
osmium::io::Reader reader{filename("200-nodes"), osmium::osm_entity_bits::nothing};
|
||||
|
||||
const osmium::io::Header header{reader.header()};
|
||||
REQUIRE(header.get("generator") == "testdata");
|
||||
|
||||
REQUIRE_FALSE(reader.read());
|
||||
REQUIRE_THROWS(reader.read());
|
||||
|
||||
reader.close();
|
||||
}
|
||||
|
||||
TEST_CASE("Reading OSM XML 200: Using Reader asking for ways") {
|
||||
osmium::io::Reader reader{filename("200-nodes"), osmium::osm_entity_bits::way};
|
||||
|
||||
const osmium::io::Header header{reader.header()};
|
||||
REQUIRE(header.get("generator") == "testdata");
|
||||
|
||||
const osmium::memory::Buffer buffer = reader.read();
|
||||
REQUIRE(0 == buffer.committed());
|
||||
REQUIRE_FALSE(buffer);
|
||||
reader.close();
|
||||
}
|
||||
|
||||
TEST_CASE("Reading OSM XML 300: Change file") {
|
||||
osmium::io::Reader reader{filename("300-change-file", "osc")};
|
||||
|
||||
const osmium::io::Header header{reader.header()};
|
||||
REQUIRE(header.get("generator") == "testdata");
|
||||
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
|
||||
auto it = buffer.select<osmium::Node>().begin();
|
||||
REQUIRE(it != buffer.select<osmium::Node>().end());
|
||||
REQUIRE(it->id() == 11);
|
||||
REQUIRE(it->visible());
|
||||
|
||||
++it;
|
||||
REQUIRE(it->id() == 13);
|
||||
REQUIRE_FALSE(it->visible());
|
||||
|
||||
++it;
|
||||
REQUIRE(it->id() == 14);
|
||||
REQUIRE(it->visible());
|
||||
|
||||
++it;
|
||||
REQUIRE(it == buffer.select<osmium::Node>().end());
|
||||
|
||||
reader.close();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user