Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libosmium to interface with openstreetmap data #349

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,26 @@ http_archive(
build_file = "//third_party:BUILD.zip_file",
integrity = "sha256-K+KFNzufwccL4vEJLErEtNKNVjnWStClXVF2mKpI6lI="
)

http_archive(
name = "libosmium",
urls = ["https://github.com/osmcode/libosmium/archive/refs/tags/v2.20.0.zip"],
build_file = "//third_party:BUILD.libosmium",
strip_prefix = "libosmium-2.20.0",
integrity = "sha256-cS7BoPRNtinhyvatqlM2kV9CPLD2ZJFC14I5i1p1x3k=",
)

http_archive(
name = "protozero",
urls = ["https://github.com/mapbox/protozero/archive/refs/tags/v1.7.1.zip"],
build_file = "//third_party:BUILD.protozero",
strip_prefix = "protozero-1.7.1",

)

http_archive(
name = "openstreetmap_snippet",
urls = ["https://www.dropbox.com/scl/fi/ku5dwktiul0wzx9ocelwc/us-virgin-islands-latest.osm.zip?rlkey=ggo7dnskexdqxvira6m6y32f3&dl=1"],
build_file = "//third_party:BUILD.zip_file",
integrity = "sha256-miPvL6co2035EGlkvbcksmTO6HwB/AknVLQK+/YDet0="
)
11 changes: 11 additions & 0 deletions common/openstreetmap/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

cc_test(
name = "openstreetmap_test",
srcs = ["openstreetmap_test.cc"],
data = ["@openstreetmap_snippet//:files"],
deps = [
"@fmt",
"@libosmium",
"@com_google_googletest//:gtest_main",
]
)
44 changes: 44 additions & 0 deletions common/openstreetmap/openstreetmap_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

#include <fmt/core.h>

#include <filesystem>
#include <limits>

#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"

namespace robot::openstreetmap {
TEST(OpenstreetmapTest, can_open_pbf_file) {
// Setup
struct TestHandler : public osmium::handler::Handler {
int node_counter = 0;
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 |
osmium::osm_entity_bits::relation);

// Action
auto handler = TestHandler();
osmium::apply(reader, handler);

// Verification
EXPECT_GT(handler.node_counter, 0);
EXPECT_GT(handler.way_counter, 0);
EXPECT_GT(handler.relation_counter, 0);
}

} // namespace robot::openstreetmap
19 changes: 19 additions & 0 deletions third_party/BUILD.libosmium
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

cc_library(
name = "libosmium",
visibility = ["//visibility:public"],
hdrs = glob(["include/**/*.hpp"],
exclude = [
"include/io/any_input.hpp",
"include/io/any_output.hpp",
"include/io/xml_input.hpp",
"include/io/xml_output.hpp"
]
),
strip_include_prefix="include",
deps = [
"@protozero",
"@org_bzip_bzip2//:bz2lib",
"@zlib",
]
)
26 changes: 26 additions & 0 deletions third_party/BUILD.protozero
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

cc_library(
name = "protozero",
visibility = ["//visibility:public"],
hdrs = [
"include/protozero/basic_pbf_builder.hpp",
"include/protozero/basic_pbf_writer.hpp",
"include/protozero/buffer_fixed.hpp",
"include/protozero/buffer_string.hpp",
"include/protozero/buffer_tmpl.hpp",
"include/protozero/buffer_vector.hpp",
"include/protozero/byteswap.hpp",
"include/protozero/config.hpp",
"include/protozero/data_view.hpp",
"include/protozero/exception.hpp",
"include/protozero/iterators.hpp",
"include/protozero/pbf_builder.hpp",
"include/protozero/pbf_message.hpp",
"include/protozero/pbf_reader.hpp",
"include/protozero/pbf_writer.hpp",
"include/protozero/types.hpp",
"include/protozero/varint.hpp",
"include/protozero/version.hpp",
],
strip_include_prefix = "include",
)