Merge commit '8511256779228db8d2ffed7ccced2b53c70be248' as 'third_party/libosmium'
This commit is contained in:
@@ -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";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
auto r = m_ids.insert(id);
|
||||
if (!r.second) {
|
||||
std::cerr << " id " << id << " contained twice in data.osm\n";
|
||||
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";
|
||||
exit(1);
|
||||
}
|
||||
if (m_num_ways != 0) {
|
||||
std::cerr << " wrong number of ways in data.osm\n";
|
||||
exit(1);
|
||||
}
|
||||
if (m_num_relations != 0) {
|
||||
std::cerr << " wrong number of relations in data.osm\n";
|
||||
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,86 @@
|
||||
#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)) {
|
||||
size_t pos = line.find_first_of(' ');
|
||||
|
||||
if (pos == std::string::npos) {
|
||||
std::cerr << filename << " not formatted correctly\n";
|
||||
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";
|
||||
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";
|
||||
}
|
||||
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");
|
||||
|
||||
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");
|
||||
|
||||
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>
|
||||
|
||||
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;
|
||||
|
||||
#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
|
||||
Reference in New Issue
Block a user