...
 
Commits (5)
---
Checks: '*,-android-cloexec-*,-cert-dcl21-cpp,-cert-err58-cpp,-clang-analyzer-optin.cplusplus.VirtualCall,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-static-cast-downcast,-cppcoreguidelines-pro-type-vararg,-fuchsia-*,-google-runtime-references,-hicpp-invalid-access-moved,-hicpp-no-array-decay,-hicpp-no-assembler,-hicpp-vararg,-misc-macro-parentheses,-misc-unused-parameters,-modernize-make-unique,-modernize-raw-string-literal,-readability-avoid-const-params-in-decls,-readability-implicit-bool-cast,-readability-implicit-bool-conversion'
Checks: '*,-android-cloexec-*,-bugprone-macro-parentheses,-cert-dcl21-cpp,-cert-err58-cpp,-clang-analyzer-optin.cplusplus.VirtualCall,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-static-cast-downcast,-cppcoreguidelines-pro-type-vararg,-fuchsia-*,-google-runtime-references,-hicpp-invalid-access-moved,-hicpp-no-array-decay,-hicpp-no-assembler,-hicpp-vararg,-misc-macro-parentheses,-misc-unused-parameters,-modernize-make-unique,-modernize-raw-string-literal,-readability-avoid-const-params-in-decls,-readability-implicit-bool-cast,-readability-implicit-bool-conversion'
#
# For a list of check options, see:
# https://clang.llvm.org/extra/clang-tidy/checks/list.html
......@@ -9,6 +9,10 @@ Checks: '*,-android-cloexec-*,-cert-dcl21-cpp,-cert-err58-cpp,-clang-analyzer-op
# android-cloexec-*
# O_CLOEXEC isn't available on Windows making this non-portable.
#
# bugprone-macro-parentheses
# False positive in the only place where it reports something and
# disabling locally doesn't work.
#
# cert-dcl21-cpp
# It is unclear whether this is still a good recommendation in modern C++.
#
......@@ -64,8 +68,7 @@ Checks: '*,-android-cloexec-*,-cert-dcl21-cpp,-cert-err58-cpp,-clang-analyzer-op
# Too strict, sometimes calling vararg functions is necessary.
#
# misc-macro-parentheses
# False positive in the only place where it reports something and
# disabling locally doesn't work.
# Old name for bugprone-macro-parentheses.
#
# misc-unused-parameters
# Can't be fixed, because then Doxygen will complain. (In file
......
......@@ -13,6 +13,27 @@ This project adheres to [Semantic Versioning](https://semver.org/).
### Fixed
## [2.15.1] - 2019-02-26
### Added
* More tests.
* CMake config: also find clang-tidy-7.
### Changed
* Example and benchmark programs now don't crash with exceptions any more
but report them properly.
### Fixed
* Compile with NDEBUG in RelWithDebInfo mode.
* Correctly throw exception in `multimap::dump_as_list()`.
* Integer truncation on 32 bit systems in `MemoryUsage`.
* Exception specification on some functions.
* Forwarding references that might have hidden copy/move constructors.
## [2.15.0] - 2018-12-07
### Added
......@@ -897,7 +918,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
Doxygen (up to version 1.8.8). This version contains a workaround to fix
this.
[unreleased]: https://github.com/osmcode/libosmium/compare/v2.15.0...HEAD
[unreleased]: https://github.com/osmcode/libosmium/compare/v2.15.1...HEAD
[2.15.1]: https://github.com/osmcode/libosmium/compare/v2.15.0...v2.15.1
[2.15.0]: https://github.com/osmcode/libosmium/compare/v2.14.2...v2.15.0
[2.14.2]: https://github.com/osmcode/libosmium/compare/v2.14.1...v2.14.2
[2.14.1]: https://github.com/osmcode/libosmium/compare/v2.14.0...v2.14.1
......
......@@ -40,7 +40,7 @@ project(libosmium)
set(LIBOSMIUM_VERSION_MAJOR 2)
set(LIBOSMIUM_VERSION_MINOR 15)
set(LIBOSMIUM_VERSION_PATCH 0)
set(LIBOSMIUM_VERSION_PATCH 1)
set(LIBOSMIUM_VERSION
"${LIBOSMIUM_VERSION_MAJOR}.${LIBOSMIUM_VERSION_MINOR}.${LIBOSMIUM_VERSION_PATCH}")
......@@ -206,11 +206,13 @@ endif()
#
#-----------------------------------------------------------------------------
if(MSVC)
set(USUAL_COMPILE_OPTIONS "/Ox")
set(DEV_COMPILE_OPTIONS "/Ox")
set(RWD_COMPILE_OPTIONS "/Ox /DNDEBUG")
# do not show warnings caused by missing .pdb files for libraries
set(USUAL_LINK_OPTIONS "/debug /ignore:4099")
else()
set(USUAL_COMPILE_OPTIONS "-O3 -g")
set(DEV_COMPILE_OPTIONS "-O3 -g")
set(RWD_COMPILE_OPTIONS "-O3 -g -DNDEBUG")
set(USUAL_LINK_OPTIONS "")
endif()
......@@ -218,7 +220,7 @@ if(WIN32)
add_definitions(-DWIN32 -D_WIN32 -DMSWIN32 -DBGDWIN32)
endif()
set(CMAKE_CXX_FLAGS_DEV "${USUAL_COMPILE_OPTIONS}"
set(CMAKE_CXX_FLAGS_DEV "${DEV_COMPILE_OPTIONS}"
CACHE STRING "Flags used by the compiler during developer builds."
FORCE)
......@@ -230,7 +232,7 @@ mark_as_advanced(
CMAKE_EXE_LINKER_FLAGS_DEV
)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${USUAL_COMPILE_OPTIONS}"
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${RWD_COMPILE_OPTIONS}"
CACHE STRING "Flags used by the compiler during RELWITHDEBINFO builds."
FORCE)
......@@ -422,7 +424,7 @@ endif()
#
#-----------------------------------------------------------------------------
message(STATUS "Looking for clang-tidy")
find_program(CLANG_TIDY NAMES clang-tidy clang-tidy-7.0 clang-tidy-6.0 clang-tidy-5.0)
find_program(CLANG_TIDY NAMES clang-tidy clang-tidy-7 clang-tidy-7.0 clang-tidy-6.0 clang-tidy-5.0)
if(CLANG_TIDY)
message(STATUS "Looking for clang-tidy - found ${CLANG_TIDY}")
......
......@@ -7,7 +7,7 @@ A fast and flexible C++ library for working with OpenStreetMap data.
Libosmium works on Linux, Mac OSX and Windows.
[![Travis Build Status](https://secure.travis-ci.org/osmcode/libosmium.svg)](https://travis-ci.org/osmcode/libosmium)
[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/github/osmcode/libosmium?svg=true)](https://ci.appveyor.com/project/Mapbox/libosmium)
[![Appveyor Build status](https://ci.appveyor.com/api/projects/status/ep07l3x5rk3hd8sp/branch/master?svg=true)](https://ci.appveyor.com/project/lonvia/libosmium/branch/master)
[![Coverage Status](https://codecov.io/gh/osmcode/libosmium/branch/master/graph/badge.svg)](https://codecov.io/gh/osmcode/libosmium)
[![Packaging status](https://repology.org/badge/tiny-repos/libosmium.svg)](https://repology.org/metapackage/libosmium)
......
......@@ -14,8 +14,6 @@ clone_depth: 1
environment:
matrix:
- config: MSYS2
autocrlf: true
- config: Debug
autocrlf: true
- config: Release
......@@ -24,6 +22,8 @@ environment:
autocrlf: false
- config: Release
autocrlf: false
- config: MSYS2
autocrlf: true
#-----------------------------------------------------------------------------
......
......@@ -39,16 +39,21 @@ int main(int argc, char* argv[]) {
std::exit(1);
}
const std::string input_filename{argv[1]};
try {
const std::string input_filename{argv[1]};
osmium::io::Reader reader{input_filename};
osmium::io::Reader reader{input_filename};
CountHandler handler;
osmium::apply(reader, handler);
reader.close();
CountHandler handler;
osmium::apply(reader, handler);
reader.close();
std::cout << "Nodes: " << handler.nodes << '\n';
std::cout << "Ways: " << handler.ways << '\n';
std::cout << "Relations: " << handler.relations << '\n';
std::cout << "Nodes: " << handler.nodes << '\n';
std::cout << "Ways: " << handler.ways << '\n';
std::cout << "Relations: " << handler.relations << '\n';
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
std::exit(1);
}
}
......@@ -42,14 +42,19 @@ int main(int argc, char* argv[]) {
std::exit(1);
}
const std::string input_filename{argv[1]};
try {
const std::string input_filename{argv[1]};
osmium::io::Reader reader{input_filename};
osmium::io::Reader reader{input_filename};
CountHandler handler;
osmium::apply(reader, handler);
reader.close();
CountHandler handler;
osmium::apply(reader, handler);
reader.close();
std::cout << "r_all=" << handler.all << " r_counter=" << handler.counter << '\n';
std::cout << "r_all=" << handler.all << " r_counter=" << handler.counter << '\n';
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
std::exit(1);
}
}
......@@ -24,17 +24,22 @@ int main(int argc, char* argv[]) {
std::exit(1);
}
const std::string input_filename{argv[1]};
const std::string location_store{argv[2]};
try {
const std::string input_filename{argv[1]};
const std::string location_store{argv[2]};
osmium::io::Reader reader{input_filename};
osmium::io::Reader reader{input_filename};
const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance();
std::unique_ptr<index_type> index = map_factory.create_map(location_store);
location_handler_type location_handler{*index};
location_handler.ignore_errors();
const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance();
std::unique_ptr<index_type> index = map_factory.create_map(location_store);
location_handler_type location_handler{*index};
location_handler.ignore_errors();
osmium::apply(reader, location_handler);
reader.close();
osmium::apply(reader, location_handler);
reader.close();
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
std::exit(1);
}
}
......@@ -31,12 +31,17 @@ int main(int argc, char* argv[]) {
std::exit(1);
}
const std::string input_filename{argv[1]};
try {
const std::string input_filename{argv[1]};
osmium::io::Reader reader{input_filename};
osmium::io::Reader reader{input_filename};
GeomHandler handler;
osmium::apply(reader, handler);
reader.close();
GeomHandler handler;
osmium::apply(reader, handler);
reader.close();
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
std::exit(1);
}
}
......@@ -44,101 +44,106 @@ int main(int argc, char* argv[]) {
std::exit(1);
}
const std::string input_filename{argv[1]};
try {
const std::string input_filename{argv[1]};
osmium::memory::Buffer buffer{osmium::io::read_file(input_filename)};
osmium::memory::Buffer buffer{osmium::io::read_file(input_filename)};
const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance();
const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance();
const auto buffer_size = buffer.committed() / (1024 * 1024); // buffer size in MBytes
const int runs = std::max(10, static_cast<int>(5000ull / buffer_size));
const auto buffer_size = buffer.committed() / (1024 * 1024); // buffer size in MBytes
const int runs = std::max(10, static_cast<int>(5000ull / buffer_size));
std::cout << "input: filename=" << input_filename << " buffer_size=" << buffer_size << "MBytes\n";
std::cout << "runs: " << runs << "\n";
std::cout << "input: filename=" << input_filename << " buffer_size=" << buffer_size << "MBytes\n";
std::cout << "runs: " << runs << "\n";
double static_min = std::numeric_limits<double>::max();
double static_sum = 0;
double static_max = 0;
double static_min = std::numeric_limits<double>::max();
double static_sum = 0;
double static_max = 0;
double dynamic_min = std::numeric_limits<double>::max();
double dynamic_sum = 0;
double dynamic_max = 0;
double dynamic_min = std::numeric_limits<double>::max();
double dynamic_sum = 0;
double dynamic_max = 0;
for (int i = 0; i < runs; ++i) {
for (int i = 0; i < runs; ++i) {
{
// static index
osmium::memory::Buffer tmp_buffer{buffer.committed()};
for (const auto& item : buffer) {
tmp_buffer.add_item(item);
tmp_buffer.commit();
}
static_index_type static_index;
static_location_handler_type static_location_handler{static_index};
{
// static index
osmium::memory::Buffer tmp_buffer{buffer.committed()};
for (const auto& item : buffer) {
tmp_buffer.add_item(item);
tmp_buffer.commit();
}
const auto start = std::chrono::steady_clock::now();
osmium::apply(tmp_buffer, static_location_handler);
const auto end = std::chrono::steady_clock::now();
static_index_type static_index;
static_location_handler_type static_location_handler{static_index};
const double duration = std::chrono::duration<double, std::milli>(end - start).count();
const auto start = std::chrono::steady_clock::now();
osmium::apply(tmp_buffer, static_location_handler);
const auto end = std::chrono::steady_clock::now();
if (duration < static_min) {
static_min = duration;
}
if (duration > static_max) {
static_max = duration;
}
static_sum += duration;
}
const double duration = std::chrono::duration<double, std::milli>(end - start).count();
{
// dynamic index
osmium::memory::Buffer tmp_buffer{buffer.committed()};
for (const auto& item : buffer) {
tmp_buffer.add_item(item);
tmp_buffer.commit();
if (duration < static_min) {
static_min = duration;
}
if (duration > static_max) {
static_max = duration;
}
static_sum += duration;
}
std::unique_ptr<dynamic_index_type> index = map_factory.create_map(location_store);
dynamic_location_handler_type dynamic_location_handler{*index};
dynamic_location_handler.ignore_errors();
const auto start = std::chrono::steady_clock::now();
osmium::apply(tmp_buffer, dynamic_location_handler);
const auto end = std::chrono::steady_clock::now();
const double duration = std::chrono::duration<double, std::milli>(end - start).count();
if (duration < dynamic_min) {
dynamic_min = duration;
}
if (duration > dynamic_max) {
dynamic_max = duration;
{
// dynamic index
osmium::memory::Buffer tmp_buffer{buffer.committed()};
for (const auto& item : buffer) {
tmp_buffer.add_item(item);
tmp_buffer.commit();
}
std::unique_ptr<dynamic_index_type> index = map_factory.create_map(location_store);
dynamic_location_handler_type dynamic_location_handler{*index};
dynamic_location_handler.ignore_errors();
const auto start = std::chrono::steady_clock::now();
osmium::apply(tmp_buffer, dynamic_location_handler);
const auto end = std::chrono::steady_clock::now();
const double duration = std::chrono::duration<double, std::milli>(end - start).count();
if (duration < dynamic_min) {
dynamic_min = duration;
}
if (duration > dynamic_max) {
dynamic_max = duration;
}
dynamic_sum += duration;
}
dynamic_sum += duration;
}
}
const double static_avg = static_sum / runs;
const double dynamic_avg = dynamic_sum / runs;
const double static_avg = static_sum / runs;
const double dynamic_avg = dynamic_sum / runs;
std::cout << "static min=" << static_min << "ms avg=" << static_avg << "ms max=" << static_max << "ms\n";
std::cout << "dynamic min=" << dynamic_min << "ms avg=" << dynamic_avg << "ms max=" << dynamic_max << "ms\n";
std::cout << "static min=" << static_min << "ms avg=" << static_avg << "ms max=" << static_max << "ms\n";
std::cout << "dynamic min=" << dynamic_min << "ms avg=" << dynamic_avg << "ms max=" << dynamic_max << "ms\n";
const double rfactor = 100.0;
const double diff_min = std::round((dynamic_min - static_min) * rfactor) / rfactor;
const double diff_avg = std::round((dynamic_avg - static_avg) * rfactor) / rfactor;
const double diff_max = std::round((dynamic_max - static_max) * rfactor) / rfactor;
const double rfactor = 100.0;
const double diff_min = std::round((dynamic_min - static_min) * rfactor) / rfactor;
const double diff_avg = std::round((dynamic_avg - static_avg) * rfactor) / rfactor;
const double diff_max = std::round((dynamic_max - static_max) * rfactor) / rfactor;
const double prfactor = 10.0;
const double percent_min = std::round((100.0 * diff_min / static_min) * prfactor) / prfactor;
const double percent_avg = std::round((100.0 * diff_avg / static_avg) * prfactor) / prfactor;
const double percent_max = std::round((100.0 * diff_max / static_max) * prfactor) / prfactor;
const double prfactor = 10.0;
const double percent_min = std::round((100.0 * diff_min / static_min) * prfactor) / prfactor;
const double percent_avg = std::round((100.0 * diff_avg / static_avg) * prfactor) / prfactor;
const double percent_max = std::round((100.0 * diff_max / static_max) * prfactor) / prfactor;
std::cout << "difference:";
std::cout << " min=" << diff_min << "ms (" << percent_min << "%)";
std::cout << " avg=" << diff_avg << "ms (" << percent_avg << "%)";
std::cout << " max=" << diff_max << "ms (" << percent_max << "%)\n";
std::cout << "difference:";
std::cout << " min=" << diff_min << "ms (" << percent_min << "%)";
std::cout << " avg=" << diff_avg << "ms (" << percent_avg << "%)";
std::cout << " max=" << diff_max << "ms (" << percent_max << "%)\n";
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
std::exit(1);
}
}
......@@ -17,19 +17,24 @@ int main(int argc, char* argv[]) {
std::exit(1);
}
std::string input_filename{argv[1]};
std::string output_filename{argv[2]};
osmium::io::Reader reader{input_filename};
osmium::io::File output_file{output_filename, "pbf"};
osmium::io::Header header;
osmium::io::Writer writer{output_file, header, osmium::io::overwrite::allow};
while (osmium::memory::Buffer buffer = reader.read()) { // NOLINT(bugprone-use-after-move) Bug in clang-tidy https://bugs.llvm.org/show_bug.cgi?id=36516
writer(std::move(buffer));
try {
std::string input_filename{argv[1]};
std::string output_filename{argv[2]};
osmium::io::Reader reader{input_filename};
osmium::io::File output_file{output_filename, "pbf"};
osmium::io::Header header;
osmium::io::Writer writer{output_file, header, osmium::io::overwrite::allow};
while (osmium::memory::Buffer buffer = reader.read()) { // NOLINT(bugprone-use-after-move) Bug in clang-tidy https://bugs.llvm.org/show_bug.cgi?id=36516
writer(std::move(buffer));
}
writer.close();
reader.close();
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
std::exit(1);
}
writer.close();
reader.close();
}
libosmium (2.15.0-2) UNRELEASED; urgency=medium
libosmium (2.15.1-1) unstable; urgency=medium
* New upstream release.
* Bump Standards-Version to 4.3.0, no changes.
* Update copyright years for Jochen Topf.
-- Bas Couwenberg <sebastic@debian.org> Tue, 25 Dec 2018 22:31:31 +0100
-- Bas Couwenberg <sebastic@debian.org> Tue, 26 Feb 2019 17:12:59 +0100
libosmium (2.15.0-1) unstable; urgency=medium
......
......@@ -4,7 +4,7 @@ Upstream-Contact: Osmium Developers (https://osmcode.org/contact)
Source: https://github.com/osmcode/libosmium
Files: *
Copyright: 2013-2018, Jochen Topf <jochen@topf.org>
Copyright: 2013-2019, Jochen Topf <jochen@topf.org>
2012, Two Blue Cubes Ltd.
License: BSL-1.0
......@@ -29,7 +29,7 @@ License: public-domain
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Files: debian/*
Copyright: © 2015, Bas Couwenberg <sebastic@debian.org>
Copyright: 2015, Bas Couwenberg <sebastic@debian.org>
License: GPL-2+
License: BSL-1.0
......
......@@ -113,59 +113,65 @@ int main(int argc, char* argv[]) {
std::exit(1);
}
// The input file
const osmium::io::File input_file{argv[1]};
// Configuration for the multipolygon assembler. We disable the option to
// create empty areas when invalid multipolygons are encountered. This
// means areas created have a valid geometry and invalid multipolygons
// are simply ignored.
osmium::area::Assembler::config_type assembler_config;
assembler_config.create_empty_areas = false;
// Initialize the MultipolygonManager. Its job is to collect all
// relations and member ways needed for each area. It then calls an
// instance of the osmium::area::Assembler class (with the given config)
// to actually assemble one area.
osmium::area::MultipolygonManager<osmium::area::Assembler> mp_manager{assembler_config};
// We read the input file twice. In the first pass, only relations are
// read and fed into the multipolygon manager.
std::cerr << "Pass 1...\n";
osmium::relations::read_relations(input_file, mp_manager);
std::cerr << "Pass 1 done\n";
// The index storing all node locations.
index_type index;
// The handler that stores all node locations in the index and adds them
// to the ways.
location_handler_type location_handler{index};
// If a location is not available in the index, we ignore it. It might
// not be needed (if it is not part of a multipolygon relation), so why
// create an error?
location_handler.ignore_errors();
// Create our handler.
AmenityHandler data_handler;
// On the second pass we read all objects and run them first through the
// node location handler and then the multipolygon manager. The manager
// will put the areas it has created into the "buffer" which are then
// fed through our handler.
//
// The read_meta::no option disables reading of meta data (such as version
// numbers, timestamps, etc.) which are not needed in this case. Disabling
// this can speed up your program.
std::cerr << "Pass 2...\n";
osmium::io::Reader reader{input_file, osmium::io::read_meta::no};
osmium::apply(reader, location_handler, data_handler, mp_manager.handler([&data_handler](const osmium::memory::Buffer& area_buffer) {
osmium::apply(area_buffer, data_handler);
}));
reader.close();
std::cerr << "Pass 2 done\n";
try {
// The input file
const osmium::io::File input_file{argv[1]};
// Configuration for the multipolygon assembler. We disable the option to
// create empty areas when invalid multipolygons are encountered. This
// means areas created have a valid geometry and invalid multipolygons
// are simply ignored.
osmium::area::Assembler::config_type assembler_config;
assembler_config.create_empty_areas = false;
// Initialize the MultipolygonManager. Its job is to collect all
// relations and member ways needed for each area. It then calls an
// instance of the osmium::area::Assembler class (with the given config)
// to actually assemble one area.
osmium::area::MultipolygonManager<osmium::area::Assembler> mp_manager{assembler_config};
// We read the input file twice. In the first pass, only relations are
// read and fed into the multipolygon manager.
std::cerr << "Pass 1...\n";
osmium::relations::read_relations(input_file, mp_manager);
std::cerr << "Pass 1 done\n";
// The index storing all node locations.
index_type index;
// The handler that stores all node locations in the index and adds them
// to the ways.
location_handler_type location_handler{index};
// If a location is not available in the index, we ignore it. It might
// not be needed (if it is not part of a multipolygon relation), so why
// create an error?
location_handler.ignore_errors();
// Create our handler.
AmenityHandler data_handler;
// On the second pass we read all objects and run them first through the
// node location handler and then the multipolygon manager. The manager
// will put the areas it has created into the "buffer" which are then
// fed through our handler.
//
// The read_meta::no option disables reading of meta data (such as version
// numbers, timestamps, etc.) which are not needed in this case. Disabling
// this can speed up your program.
std::cerr << "Pass 2...\n";
osmium::io::Reader reader{input_file, osmium::io::read_meta::no};
osmium::apply(reader, location_handler, data_handler, mp_manager.handler([&data_handler](const osmium::memory::Buffer& area_buffer) {
osmium::apply(area_buffer, data_handler);
}));
reader.close();
std::cerr << "Pass 2 done\n";
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
std::exit(1);
}
}
......@@ -107,92 +107,98 @@ int main(int argc, char* argv[]) {
print_usage(argv[0]);
}
// Initialize an empty DynamicHandler. Later it will be associated
// with one of the handlers. You can think of the DynamicHandler as
// a kind of "variant handler" or a "pointer handler" pointing to the
// real handler.
osmium::handler::DynamicHandler handler;
if (!std::strcmp(argv[1], "-w") || !std::strcmp(argv[1], "--dump-wkt")) {
handler.set<WKTDump>();
} else if (!std::strcmp(argv[1], "-o") || !std::strcmp(argv[1], "--dump-objects")) {
handler.set<osmium::handler::Dump>(std::cout);
} else {
print_usage(argv[0]);
}
try {
// Initialize an empty DynamicHandler. Later it will be associated
// with one of the handlers. You can think of the DynamicHandler as
// a kind of "variant handler" or a "pointer handler" pointing to the
// real handler.
osmium::handler::DynamicHandler handler;
if (!std::strcmp(argv[1], "-w") || !std::strcmp(argv[1], "--dump-wkt")) {
handler.set<WKTDump>();
} else if (!std::strcmp(argv[1], "-o") || !std::strcmp(argv[1], "--dump-objects")) {
handler.set<osmium::handler::Dump>(std::cout);
} else {
print_usage(argv[0]);
}
osmium::io::File input_file{argv[2]};
// Configuration for the multipolygon assembler. Here the default settings
// are used, but you could change multiple settings.
osmium::area::Assembler::config_type assembler_config;
// Set up a filter matching only forests. This will be used to only build
// areas with matching tags.
osmium::TagsFilter filter{false};
filter.add_rule(true, "landuse", "forest");
filter.add_rule(true, "natural", "wood");
// Initialize the MultipolygonManager. Its job is to collect all
// relations and member ways needed for each area. It then calls an
// instance of the osmium::area::Assembler class (with the given config)
// to actually assemble one area. The filter parameter is optional, if
// it is not set, all areas will be built.
osmium::area::MultipolygonManager<osmium::area::Assembler> mp_manager{assembler_config, filter};
// We read the input file twice. In the first pass, only relations are
// read and fed into the multipolygon manager.
std::cerr << "Pass 1...\n";
osmium::relations::read_relations(input_file, mp_manager);
std::cerr << "Pass 1 done\n";
// Output the amount of main memory used so far. All multipolygon relations
// are in memory now.
std::cerr << "Memory:\n";
osmium::relations::print_used_memory(std::cerr, mp_manager.used_memory());
// The index storing all node locations.
index_type index;
// The handler that stores all node locations in the index and adds them
// to the ways.
location_handler_type location_handler{index};
// If a location is not available in the index, we ignore it. It might
// not be needed (if it is not part of a multipolygon relation), so why
// create an error?
location_handler.ignore_errors();
// On the second pass we read all objects and run them first through the
// node location handler and then the multipolygon collector. The collector
// will put the areas it has created into the "buffer" which are then
// fed through our "handler".
std::cerr << "Pass 2...\n";
osmium::io::Reader reader{input_file};
osmium::apply(reader, location_handler, mp_manager.handler([&handler](osmium::memory::Buffer&& buffer) {
osmium::apply(buffer, handler);
}));
reader.close();
std::cerr << "Pass 2 done\n";
// Output the amount of main memory used so far. All complete multipolygon
// relations have been cleaned up.
std::cerr << "Memory:\n";
osmium::relations::print_used_memory(std::cerr, mp_manager.used_memory());
// If there were multipolgyon relations in the input, but some of their
// members are not in the input file (which often happens for extracts)
// this will write the IDs of the incomplete relations to stderr.
std::vector<osmium::object_id_type> incomplete_relations_ids;
mp_manager.for_each_incomplete_relation([&](const osmium::relations::RelationHandle& handle){
incomplete_relations_ids.push_back(handle->id());
});
if (!incomplete_relations_ids.empty()) {
std::cerr << "Warning! Some member ways missing for these multipolygon relations:";
for (const auto id : incomplete_relations_ids) {
std::cerr << " " << id;
osmium::io::File input_file{argv[2]};
// Configuration for the multipolygon assembler. Here the default settings
// are used, but you could change multiple settings.
osmium::area::Assembler::config_type assembler_config;
// Set up a filter matching only forests. This will be used to only build
// areas with matching tags.
osmium::TagsFilter filter{false};
filter.add_rule(true, "landuse", "forest");
filter.add_rule(true, "natural", "wood");
// Initialize the MultipolygonManager. Its job is to collect all
// relations and member ways needed for each area. It then calls an
// instance of the osmium::area::Assembler class (with the given config)
// to actually assemble one area. The filter parameter is optional, if
// it is not set, all areas will be built.
osmium::area::MultipolygonManager<osmium::area::Assembler> mp_manager{assembler_config, filter};
// We read the input file twice. In the first pass, only relations are
// read and fed into the multipolygon manager.
std::cerr << "Pass 1...\n";
osmium::relations::read_relations(input_file, mp_manager);
std::cerr << "Pass 1 done\n";
// Output the amount of main memory used so far. All multipolygon relations
// are in memory now.
std::cerr << "Memory:\n";
osmium::relations::print_used_memory(std::cerr, mp_manager.used_memory());
// The index storing all node locations.
index_type index;
// The handler that stores all node locations in the index and adds them
// to the ways.
location_handler_type location_handler{index};
// If a location is not available in the index, we ignore it. It might
// not be needed (if it is not part of a multipolygon relation), so why
// create an error?
location_handler.ignore_errors();
// On the second pass we read all objects and run them first through the
// node location handler and then the multipolygon collector. The collector
// will put the areas it has created into the "buffer" which are then
// fed through our "handler".
std::cerr << "Pass 2...\n";
osmium::io::Reader reader{input_file};
osmium::apply(reader, location_handler, mp_manager.handler([&handler](osmium::memory::Buffer&& buffer) {
osmium::apply(buffer, handler);
}));
reader.close();
std::cerr << "Pass 2 done\n";
// Output the amount of main memory used so far. All complete multipolygon
// relations have been cleaned up.
std::cerr << "Memory:\n";
osmium::relations::print_used_memory(std::cerr, mp_manager.used_memory());
// If there were multipolgyon relations in the input, but some of their
// members are not in the input file (which often happens for extracts)
// this will write the IDs of the incomplete relations to stderr.
std::vector<osmium::object_id_type> incomplete_relations_ids;
mp_manager.for_each_incomplete_relation([&](const osmium::relations::RelationHandle& handle){
incomplete_relations_ids.push_back(handle->id());
});
if (!incomplete_relations_ids.empty()) {
std::cerr << "Warning! Some member ways missing for these multipolygon relations:";
for (const auto id : incomplete_relations_ids) {
std::cerr << " " << id;
}
std::cerr << "\n";
}
std::cerr << "\n";
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
std::exit(1);
}
}
......@@ -196,7 +196,7 @@ int main(int argc, char* argv[]) {
reader.close();
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << "\n";
std::cerr << e.what() << '\n';
std::exit(1);
}
}
......
......@@ -147,7 +147,7 @@ int main(int argc, char* argv[]) {
reader.close();
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << "\n";
std::cerr << e.what() << '\n';
std::exit(1);
}
}
......
......@@ -66,30 +66,36 @@ int main(int argc, char* argv[]) {
std::exit(1);
}
// The Reader is initialized here with an osmium::io::File, but could
// also be directly initialized with a file name.
osmium::io::File input_file{argv[1]};
osmium::io::Reader reader{input_file};
// Create an instance of our own CountHandler and push the data from the
// input file through it.
CountHandler handler;
osmium::apply(reader, handler);
// You do not have to close the Reader explicitly, but because the
// destructor can't throw, you will not see any errors otherwise.
reader.close();
std::cout << "Nodes: " << handler.nodes << "\n";
std::cout << "Ways: " << handler.ways << "\n";
std::cout << "Relations: " << handler.relations << "\n";
// Because of the huge amount of OSM data, some Osmium-based programs
// (though not this one) can use huge amounts of data. So checking actual
// memore usage is often useful and can be done easily with this class.
// (Currently only works on Linux, not OSX and Windows.)
osmium::MemoryUsage memory;
std::cout << "\nMemory used: " << memory.peak() << " MBytes\n";
try {
// The Reader is initialized here with an osmium::io::File, but could
// also be directly initialized with a file name.
osmium::io::File input_file{argv[1]};
osmium::io::Reader reader{input_file};
// Create an instance of our own CountHandler and push the data from the
// input file through it.
CountHandler handler;
osmium::apply(reader, handler);
// You do not have to close the Reader explicitly, but because the
// destructor can't throw, you will not see any errors otherwise.
reader.close();
std::cout << "Nodes: " << handler.nodes << "\n";
std::cout << "Ways: " << handler.ways << "\n";
std::cout << "Relations: " << handler.relations << "\n";
// Because of the huge amount of OSM data, some Osmium-based programs
// (though not this one) can use huge amounts of data. So checking actual
// memore usage is often useful and can be done easily with this class.
// (Currently only works on Linux, not OSX and Windows.)
osmium::MemoryUsage memory;
std::cout << "\nMemory used: " << memory.peak() << " MBytes\n";
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
std::exit(1);
}
}
......@@ -93,7 +93,7 @@ int main(int argc, char* argv[]) {
writer.close();
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << "\n";
std::cerr << e.what() << '\n';
std::exit(1);
}
}
......
......@@ -37,48 +37,54 @@ int main(int argc, char* argv[]) {
std::exit(1);
}
// Default is all entity types: nodes, ways, relations, and changesets
osmium::osm_entity_bits::type read_types = osmium::osm_entity_bits::all;
// Get entity types from command line if there is a 2nd argument.
if (argc == 3) {
read_types = osmium::osm_entity_bits::nothing;
std::string types = argv[2];
if (types.find('n') != std::string::npos) {
read_types |= osmium::osm_entity_bits::node;
try {
// Default is all entity types: nodes, ways, relations, and changesets
osmium::osm_entity_bits::type read_types = osmium::osm_entity_bits::all;
// Get entity types from command line if there is a 2nd argument.
if (argc == 3) {
read_types = osmium::osm_entity_bits::nothing;
std::string types = argv[2];
if (types.find('n') != std::string::npos) {
read_types |= osmium::osm_entity_bits::node;
}
if (types.find('w') != std::string::npos) {
read_types |= osmium::osm_entity_bits::way;
}
if (types.find('r') != std::string::npos) {
read_types |= osmium::osm_entity_bits::relation;
}
if (types.find('c') != std::string::npos) {
read_types |= osmium::osm_entity_bits::changeset;
}
}
if (types.find('w') != std::string::npos) {
read_types |= osmium::osm_entity_bits::way;
}
if (types.find('r') != std::string::npos) {
read_types |= osmium::osm_entity_bits::relation;
}
if (types.find('c') != std::string::npos) {
read_types |= osmium::osm_entity_bits::changeset;
}
}
// Initialize Reader with file name and the types of entities we want to
// read.
osmium::io::Reader reader{argv[1], read_types};
// Initialize Reader with file name and the types of entities we want to
// read.
osmium::io::Reader reader{argv[1], read_types};
// The file header can contain metadata such as the program that generated
// the file and the bounding box of the data.
osmium::io::Header header = reader.header();
std::cout << "HEADER:\n generator=" << header.get("generator") << "\n";
// The file header can contain metadata such as the program that generated
// the file and the bounding box of the data.
osmium::io::Header header = reader.header();
std::cout << "HEADER:\n generator=" << header.get("generator") << "\n";
for (const auto& bbox : header.boxes()) {
std::cout << " bbox=" << bbox << "\n";
}
for (const auto& bbox : header.boxes()) {
std::cout << " bbox=" << bbox << "\n";
}
// Initialize Dump handler.
osmium::handler::Dump dump{std::cout};
// Initialize Dump handler.
osmium::handler::Dump dump{std::cout};
// Read from input and send everything to Dump handler.
osmium::apply(reader, dump);
// Read from input and send everything to Dump handler.
osmium::apply(reader, dump);
// You do not have to close the Reader explicitly, but because the
// destructor can't throw, you will not see any errors otherwise.
reader.close();
// You do not have to close the Reader explicitly, but because the
// destructor can't throw, you will not see any errors otherwise.
reader.close();
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
std::exit(1);
}
}
......@@ -105,92 +105,98 @@ int main(int argc, char* argv[]) {
std::exit(2);
}
const std::string input_file_name{argv[1]};
const std::string output_dir{argv[2]};
try {
const std::string input_file_name{argv[1]};
const std::string output_dir{argv[2]};
// Create output directory. Ignore the error if it already exists.
// Create output directory. Ignore the error if it already exists.
#ifndef _WIN32
const int result = ::mkdir(output_dir.c_str(), 0777);
const int result = ::mkdir(output_dir.c_str(), 0777);
#else
const int result = mkdir(output_dir.c_str());
const int result = mkdir(output_dir.c_str());
#endif
if (result == -1 && errno != EEXIST) {
std::cerr << "Problem creating directory '" << output_dir << "': " << std::strerror(errno) << "\n";
std::exit(2);
}
if (result == -1 && errno != EEXIST) {
std::cerr << "Problem creating directory '" << output_dir << "': " << std::strerror(errno) << "\n";
std::exit(2);
}
// Create the output file which will contain our serialized OSM data
const std::string data_file{output_dir + "/data.osm.ser"};
const int data_fd = ::open(data_file.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666); // NOLINT(hicpp-signed-bitwise)
if (data_fd < 0) {
std::cerr << "Can't open data file '" << data_file << "': " << std::strerror(errno) << "\n";
std::exit(2);
}
// Create the output file which will contain our serialized OSM data
const std::string data_file{output_dir + "/data.osm.ser"};
const int data_fd = ::open(data_file.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666); // NOLINT(hicpp-signed-bitwise)
if (data_fd < 0) {
std::cerr << "Can't open data file '" << data_file << "': " << std::strerror(errno) << "\n";
std::exit(2);
}
#ifdef _WIN32
_setmode(data_fd, _O_BINARY);
_setmode(data_fd, _O_BINARY);
#endif
// These indexes store the offset in the data file where each node, way,
// or relation is stored.
offset_index_type node_index;
offset_index_type way_index;
offset_index_type relation_index;
// These indexes store the offset in the data file where each node, way,
// or relation is stored.
offset_index_type node_index;
offset_index_type way_index;
offset_index_type relation_index;
// This handler will dump the internal data to disk using the given file
// descriptor while updating the indexes.
osmium::handler::DiskStore disk_store_handler{data_fd, node_index, way_index, relation_index};
// This handler will dump the internal data to disk using the given file
// descriptor while updating the indexes.
osmium::handler::DiskStore disk_store_handler{data_fd, node_index, way_index, relation_index};
// These indexes store the mapping from node id to the ids of the ways
// containing this node, and from node/way/relation ids to the ids of the
// relations containing those objects.
map_type map_node2way;
map_type map_node2relation;
map_type map_way2relation;
map_type map_relation2relation;
// These indexes store the mapping from node id to the ids of the ways
// containing this node, and from node/way/relation ids to the ids of the
// relations containing those objects.
map_type map_node2way;
map_type map_node2relation;
map_type map_way2relation;
map_type map_relation2relation;
// This handler will update the map indexes.
osmium::handler::ObjectRelations object_relations_handler{map_node2way, map_node2relation, map_way2relation, map_relation2relation};
// This handler will update the map indexes.
osmium::handler::ObjectRelations object_relations_handler{map_node2way, map_node2relation, map_way2relation, map_relation2relation};
// Read OSM data buffer by buffer.
osmium::io::Reader reader{input_file_name};
// Read OSM data buffer by buffer.
osmium::io::Reader reader{input_file_name};
while (osmium::memory::Buffer buffer = reader.read()) {
// Write buffer to disk and update indexes.
disk_store_handler(buffer);
while (osmium::memory::Buffer buffer = reader.read()) {
// Write buffer to disk and update indexes.
disk_store_handler(buffer);
// Update object relation index maps.
osmium::apply(buffer, object_relations_handler);
}
// Update object relation index maps.
osmium::apply(buffer, object_relations_handler);
}
reader.close();
reader.close();
// Write out node, way, and relation offset indexes to disk.
IndexFile nodes_idx{output_dir + "/nodes.idx"};
node_index.dump_as_list(nodes_idx.fd());
// Write out node, way, and relation offset indexes to disk.
IndexFile nodes_idx{output_dir + "/nodes.idx"};
node_index.dump_as_list(nodes_idx.fd());
IndexFile ways_idx{output_dir + "/ways.idx"};
way_index.dump_as_list(ways_idx.fd());
IndexFile ways_idx{output_dir + "/ways.idx"};
way_index.dump_as_list(ways_idx.fd());
IndexFile relations_idx{output_dir + "/relations.idx"};
relation_index.dump_as_list(relations_idx.fd());
IndexFile relations_idx{output_dir + "/relations.idx"};
relation_index.dump_as_list(relations_idx.fd());
// Sort the maps (so later binary search will work on them) and write
// them to disk.
map_node2way.sort();
IndexFile node2way_idx{output_dir + "/node2way.map"};
map_node2way.dump_as_list(node2way_idx.fd());
// Sort the maps (so later binary search will work on them) and write
// them to disk.
map_node2way.sort();
IndexFile node2way_idx{output_dir + "/node2way.map"};
map_node2way.dump_as_list(node2way_idx.fd());
map_node2relation.sort();
IndexFile node2relation_idx{output_dir + "/node2rel.map"};
map_node2relation.dump_as_list(node2relation_idx.fd());
map_node2relation.sort();
IndexFile node2relation_idx{output_dir + "/node2rel.map"};
map_node2relation.dump_as_list(node2relation_idx.fd());
map_way2relation.sort();
IndexFile way2relation_idx{output_dir + "/way2rel.map"};
map_way2relation.dump_as_list(way2relation_idx.fd());
map_way2relation.sort();
IndexFile way2relation_idx{output_dir + "/way2rel.map"};
map_way2relation.dump_as_list(way2relation_idx.fd());
map_relation2relation.sort();
IndexFile relation2relation_idx{output_dir + "/rel2rel.map"};
map_relation2relation.dump_as_list(relation2relation_idx.fd());
map_relation2relation.sort();
IndexFile relation2relation_idx{output_dir + "/rel2rel.map"};
map_relation2relation.dump_as_list(relation2relation_idx.fd());
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
std::exit(1);
}
}
......@@ -46,47 +46,53 @@ int main(int argc, char* argv[]) {
std::exit(1);
}
// The input file, deduce file format from file suffix.
osmium::io::File input_file{argv[1]};
// The output file, force XML OSM file format.
osmium::io::File output_file{argv[2], "osm"};
// Initialize Reader for the input file.
// Read only changesets (will ignore nodes, ways, and
// relations if there are any).
osmium::io::Reader reader{input_file, osmium::osm_entity_bits::changeset};
// Get the header from the input file.
osmium::io::Header header = reader.header();
// Set the "generator" on the header to ourselves.
header.set("generator", "osmium_filter_discussions");
// Initialize writer for the output file. Use the header from the input
// file for the output file. This will copy over some header information.
// The last parameter will tell the writer that it is allowed to overwrite
// an existing file. Without it, it will refuse to do so.
osmium::io::Writer writer{output_file, header, osmium::io::overwrite::allow};
// Create range of input iterators that will iterator over all changesets
// delivered from input file through the "reader".
auto input_range = osmium::io::make_input_iterator_range<osmium::Changeset>(reader);
// Create an output iterator writing through the "writer" object to the
// output file.
auto output_iterator = osmium::io::make_output_iterator(writer);
// Copy all changesets from input to output that have at least one comment.
std::copy_if(input_range.begin(), input_range.end(), output_iterator, [](const osmium::Changeset& changeset) {
return changeset.num_comments() > 0;
});
// Explicitly close the writer and reader. Will throw an exception if
// there is a problem. If you wait for the destructor to close the writer
// and reader, you will not notice the problem, because destructors must
// not throw.
writer.close();
reader.close();
try {
// The input file, deduce file format from file suffix.
osmium::io::File input_file{argv[1]};
// The output file, force XML OSM file format.
osmium::io::File output_file{argv[2], "osm"};
// Initialize Reader for the input file.
// Read only changesets (will ignore nodes, ways, and
// relations if there are any).
osmium::io::Reader reader{input_file, osmium::osm_entity_bits::changeset};
// Get the header from the input file.
osmium::io::Header header = reader.header();
// Set the "generator" on the header to ourselves.
header.set("generator", "osmium_filter_discussions");
// Initialize writer for the output file. Use the header from the input
// file for the output file. This will copy over some header information.
// The last parameter will tell the writer that it is allowed to overwrite
// an existing file. Without it, it will refuse to do so.
osmium::io::Writer writer{output_file, header, osmium::io::overwrite::allow};
// Create range of input iterators that will iterator over all changesets
// delivered from input file through the "reader".
auto input_range = osmium::io::make_input_iterator_range<osmium::Changeset>(reader);
// Create an output iterator writing through the "writer" object to the
// output file.
auto output_iterator = osmium::io::make_output_iterator(writer);
// Copy all changesets from input to output that have at least one comment.
std::copy_if(input_range.begin(), input_range.end(), output_iterator, [](const osmium::Changeset& changeset) {
return changeset.num_comments() > 0;
});
// Explicitly close the writer and reader. Will throw an exception if
// there is a problem. If you wait for the destructor to close the writer
// and reader, you will not notice the problem, because destructors must