-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
23 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,44 @@ | ||
|
||
#include <fmt/core.h> | ||
#include "gtest/gtest.h" | ||
|
||
#include "fmt/format.h" | ||
#include <filesystem> | ||
#include <limits> | ||
|
||
#include "osmium/io/pbf_input.hpp" | ||
#include "fmt/format.h" | ||
#include "gtest/gtest.h" | ||
#include "osmium/handler.hpp" | ||
#include "osmium/handler/dump.hpp" | ||
#include "osmium/io/pbf_input.hpp" | ||
#include "osmium/visitor.hpp" | ||
|
||
#include <filesystem> | ||
#include <limits> | ||
|
||
namespace robot::openstreetmap { | ||
|
||
TEST(OpenstreetmapTest, can_open_pbf_file) { | ||
// Setup | ||
struct TestHandler : public osmium::handler::Handler { | ||
int node_counter = 0; | ||
std::pair<double, double> min{std::numeric_limits<double>::max(),std::numeric_limits<double>::max()}; | ||
std::pair<double, double> max{std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest()}; | ||
void node(const osmium::Node &node) { | ||
const auto location = node.location(); | ||
|
||
|
||
if (location.valid()) { | ||
min = std::make_pair(std::min(min.first, location.lat()), std::min(min.second, location.lon())); | ||
max = std::make_pair(std::max(max.first, location.lat()), std::max(max.second, location.lon())); | ||
} | ||
if (!node.visible()) { | ||
return; | ||
} | ||
|
||
fmt::print("{} id: {} location: ({}, {}) tags: {{", node_counter++, node.id(), location.lat(), location.lon()); | ||
for (const auto &tag: node.tags()) { | ||
fmt::print("{}: {}, ", tag.key(), tag.value()); | ||
} | ||
std::cout << "}" << std::endl; | ||
} | ||
|
||
void way(const osmium::Way &way) { | ||
|
||
} | ||
int way_counter = 0; | ||
int relation_counter = 0; | ||
|
||
void node(const osmium::Node &node) { node_counter++; } | ||
|
||
void way(const osmium::Way &way) { way_counter++; } | ||
|
||
void relation(const osmium::Relation &relation) { relation_counter++; } | ||
}; | ||
const std::filesystem::path osm_pbf_path("external/openstreetmap_snippet/us-virgin-islands-latest.osm.pbf"); | ||
osmium::io::Reader reader(osm_pbf_path, osmium::osm_entity_bits::node | osmium::osm_entity_bits::way); | ||
const std::filesystem::path osm_pbf_path( | ||
"external/openstreetmap_snippet/us-virgin-islands-latest.osm.pbf"); | ||
osmium::io::Reader reader(osm_pbf_path, osmium::osm_entity_bits::node | | ||
osmium::osm_entity_bits::way | | ||
osmium::osm_entity_bits::relation); | ||
|
||
// Action | ||
auto handler = TestHandler(); | ||
osmium::apply(reader, handler); | ||
|
||
fmt::print("min: ({}, {}) max: ({}, {})\r\n", handler.min.first, handler.min.second, handler.max.first, handler.max.second); | ||
|
||
// Verification | ||
EXPECT_TRUE(std::filesystem::exists(osm_pbf_path)); | ||
} | ||
|
||
EXPECT_GT(handler.node_counter, 0); | ||
EXPECT_GT(handler.way_counter, 0); | ||
EXPECT_GT(handler.relation_counter, 0); | ||
} | ||
|
||
} // namespace robot::openstreetmap |