├── test
├── t
│ ├── io
│ │ ├── empty_file
│ │ ├── data.txt
│ │ ├── data-cr.opl
│ │ ├── data-nonl.opl
│ │ ├── data.opl
│ │ ├── data.osm.bz2
│ │ ├── data.osm.gz
│ │ ├── data_gzip.txt.gz
│ │ ├── data-n0w1r3.osm.o5m
│ │ ├── data-n5w0r3.osm.o5m
│ │ ├── data-n5w1r0.osm.o5m
│ │ ├── data-n5w1r3.osm.o5m
│ │ ├── data_bzip2.txt.bz2
│ │ ├── deleted_nodes.osh.pbf
│ │ ├── corrupt_data_gzip.txt.gz
│ │ ├── corrupt_data_bzip2.txt.bz2
│ │ ├── data_pbf_version-1.osm.pbf
│ │ ├── data_pbf_version-1-densenodes.osm.pbf
│ │ ├── data_pbf_version-1.osm
│ │ ├── data.osm
│ │ ├── data-n0w1r3.osm.opl
│ │ ├── test_reader_fileformat.cpp
│ │ ├── deleted_nodes.osh
│ │ ├── data-n5w1r0.osm.opl
│ │ ├── data-n5w0r3.osm.opl
│ │ ├── data-n5w1r3.osm.opl
│ │ ├── data-n5w1r0.osm
│ │ ├── test_print_width.cpp
│ │ ├── test_output_iterator.cpp
│ │ ├── data-n0w1r3.osm
│ │ ├── test_compression_factory.cpp
│ │ ├── data-n5w0r3.osm
│ │ └── data-n5w1r3.osm
│ ├── util
│ │ ├── known_file_size
│ │ ├── .gitattributes
│ │ ├── test_timer_disabled.cpp
│ │ ├── test_memory.cpp
│ │ ├── test_timer_enabled.cpp
│ │ ├── test_double.cpp
│ │ ├── test_minmax.cpp
│ │ └── test_file.cpp
│ ├── geom
│ │ ├── test_exception.cpp
│ │ ├── test_factory_with_projection.cpp
│ │ ├── test_mercator.cpp
│ │ ├── test_projection.cpp
│ │ ├── wnl_helper.hpp
│ │ ├── test_coordinates.cpp
│ │ └── area_helper.hpp
│ ├── index
│ │ ├── test_nwr_array.cpp
│ │ └── test_object_pointer_collection.cpp
│ ├── relations
│ │ ├── dupl_member.osm
│ │ ├── data.osm
│ │ ├── missing_members.osm
│ │ └── test_read_relations.cpp
│ ├── area
│ │ └── test_area_id.cpp
│ ├── thread
│ │ ├── test_queue.cpp
│ │ └── test_util.cpp
│ ├── memory
│ │ └── test_item.cpp
│ ├── osm
│ │ └── test_crc.cpp
│ └── tags
│ │ └── test_operators.cpp
├── data-tests
│ ├── .gitignore
│ ├── include
│ │ ├── testdata-testcases.hpp
│ │ └── common.hpp
│ ├── README.md
│ ├── testdata-testcases.cpp
│ ├── testcases
│ │ ├── test-120.cpp
│ │ ├── test-121.cpp
│ │ ├── test-122.cpp
│ │ ├── test-123.cpp
│ │ ├── test-100.cpp
│ │ ├── test-112.cpp
│ │ ├── test-111.cpp
│ │ ├── test-124.cpp
│ │ ├── test-101.cpp
│ │ ├── test-102.cpp
│ │ ├── test-116.cpp
│ │ ├── test-114.cpp
│ │ ├── test-115.cpp
│ │ └── test-110.cpp
│ └── run-testdata-multipolygon.cmake
├── examples
│ ├── t
│ │ ├── change_tags
│ │ │ ├── .gitattributes
│ │ │ ├── CMakeLists.txt
│ │ │ ├── result.osm
│ │ │ └── data.osm
│ │ ├── read
│ │ │ ├── CMakeLists.txt
│ │ │ └── data.osm
│ │ ├── read_with_progress
│ │ │ ├── CMakeLists.txt
│ │ │ └── data.osm
│ │ ├── count
│ │ │ ├── CMakeLists.txt
│ │ │ └── data.osm
│ │ ├── road_length
│ │ │ └── CMakeLists.txt
│ │ ├── pub_names
│ │ │ ├── pub-noname.osm
│ │ │ ├── pub-node.osm
│ │ │ ├── pub-addr.osm
│ │ │ ├── CMakeLists.txt
│ │ │ └── pub-way.osm
│ │ ├── amenity_list
│ │ │ ├── node.osm
│ │ │ ├── CMakeLists.txt
│ │ │ └── area.osm
│ │ ├── location_cache
│ │ │ ├── way.osm
│ │ │ ├── data.osm
│ │ │ └── CMakeLists.txt
│ │ ├── filter_discussions
│ │ │ ├── CMakeLists.txt
│ │ │ └── changesets.osm
│ │ ├── debug
│ │ │ ├── changesets.osm
│ │ │ ├── data.osm
│ │ │ └── CMakeLists.txt
│ │ ├── create_pois
│ │ │ └── CMakeLists.txt
│ │ ├── tiles
│ │ │ └── CMakeLists.txt
│ │ ├── area_test
│ │ │ ├── CMakeLists.txt
│ │ │ └── data.osm
│ │ ├── dump_internal
│ │ │ ├── CMakeLists.txt
│ │ │ └── data.osm
│ │ ├── convert
│ │ │ └── data.osm
│ │ └── index_lookup
│ │ │ └── CMakeLists.txt
│ └── CMakeLists.txt
├── test_main.cpp
├── README
├── include
│ ├── test_crc.hpp
│ ├── utils.hpp
│ └── win_mkstemp.hpp
└── valgrind.supp
├── .github
├── FUNDING.yml
├── ISSUE_TEMPLATE
│ ├── config.yml
│ └── bug-report.md
├── actions
│ ├── ctest
│ │ └── action.yml
│ ├── build
│ │ └── action.yml
│ ├── install-protozero
│ │ └── action.yml
│ ├── install-macos
│ │ └── action.yml
│ ├── install-windows
│ │ └── action.yml
│ ├── install-ubuntu
│ │ └── action.yml
│ ├── cmake
│ │ └── action.yml
│ └── cmake-windows
│ │ └── action.yml
└── workflows
│ └── clang-tidy.yml
├── cmake
├── README
├── iwyu.sh
├── FindLZ4.cmake
└── FindProtozero.cmake
├── .gitignore
├── .gitmodules
├── .codecov.yml
├── doc
├── README.md
├── osmium.css
├── doc.md
├── CMakeLists.txt
└── header.html
├── benchmarks
├── run_benchmarks.sh
├── run_benchmark_static_vs_dynamic_index.sh
├── run_benchmark_count.sh
├── run_benchmark_count_tag.sh
├── run_benchmark_mercator.sh
├── download_data.sh
├── run_benchmark_index_map.sh
├── run_benchmark_write_pbf.sh
├── setup.sh
├── osmium_benchmark_mercator.cpp
├── osmium_benchmark_write_pbf.cpp
├── osmium_benchmark_index_map.cpp
├── osmium_benchmark_count.cpp
├── osmium_benchmark_count_tag.cpp
├── README.md
└── CMakeLists.txt
├── osmium.imp
├── CONTRIBUTING.md
├── LICENSE
├── examples
├── osmium_read.cpp
├── README.md
├── CMakeLists.txt
└── osmium_read_with_progress.cpp
└── include
└── osmium
├── io
├── ids_output.hpp
├── opl_output.hpp
├── debug_output.hpp
├── overwrite.hpp
├── o5m_input.hpp
├── opl_input.hpp
├── xml_output.hpp
├── xml_input.hpp
├── any_compression.hpp
├── pbf_input.hpp
├── pbf_output.hpp
├── reader_iterator.hpp
├── pbf.hpp
├── writer_options.hpp
└── any_input.hpp
├── version.hpp
├── index
├── multimap
│ ├── all.hpp
│ ├── sparse_file_array.hpp
│ ├── sparse_mem_array.hpp
│ └── sparse_mmap_array.hpp
└── map
│ └── all.hpp
└── util
├── compatibility.hpp
└── endian.hpp
/test/t/io/empty_file:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/t/io/data.txt:
--------------------------------------------------------------------------------
1 | TESTDATA
2 |
--------------------------------------------------------------------------------
/test/data-tests/.gitignore:
--------------------------------------------------------------------------------
1 | multipolygon.qgs~
2 |
--------------------------------------------------------------------------------
/test/t/util/known_file_size:
--------------------------------------------------------------------------------
1 | this file has size 22
2 |
--------------------------------------------------------------------------------
/test/t/util/.gitattributes:
--------------------------------------------------------------------------------
1 | known_file_size text eol=lf
2 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | custom: "https://osmcode.org/sponsors.html"
2 |
--------------------------------------------------------------------------------
/test/examples/t/change_tags/.gitattributes:
--------------------------------------------------------------------------------
1 | result.osm text eol=lf
2 |
--------------------------------------------------------------------------------
/test/test_main.cpp:
--------------------------------------------------------------------------------
1 | #define CATCH_CONFIG_MAIN
2 | #include "catch.hpp"
3 |
--------------------------------------------------------------------------------
/test/t/io/data-cr.opl:
--------------------------------------------------------------------------------
1 | n1 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1.02 y1.02
2 |
--------------------------------------------------------------------------------
/test/t/io/data-nonl.opl:
--------------------------------------------------------------------------------
1 | n1 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1.02 y1.02
--------------------------------------------------------------------------------
/test/t/io/data.opl:
--------------------------------------------------------------------------------
1 | n1 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1.02 y1.02
2 |
--------------------------------------------------------------------------------
/cmake/README:
--------------------------------------------------------------------------------
1 |
2 | FindGem.cmake from https://github.com/rock-core/base-cmake
3 |
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.swp
2 | .ycm_extra_conf.pyc
3 | /_build*
4 | /build
5 | /libosmium-deps
6 | /.vs*
7 |
--------------------------------------------------------------------------------
/test/t/io/data.osm.bz2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osmcode/libosmium/HEAD/test/t/io/data.osm.bz2
--------------------------------------------------------------------------------
/test/t/io/data.osm.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osmcode/libosmium/HEAD/test/t/io/data.osm.gz
--------------------------------------------------------------------------------
/test/t/io/data_gzip.txt.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osmcode/libosmium/HEAD/test/t/io/data_gzip.txt.gz
--------------------------------------------------------------------------------
/test/t/io/data-n0w1r3.osm.o5m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osmcode/libosmium/HEAD/test/t/io/data-n0w1r3.osm.o5m
--------------------------------------------------------------------------------
/test/t/io/data-n5w0r3.osm.o5m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osmcode/libosmium/HEAD/test/t/io/data-n5w0r3.osm.o5m
--------------------------------------------------------------------------------
/test/t/io/data-n5w1r0.osm.o5m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osmcode/libosmium/HEAD/test/t/io/data-n5w1r0.osm.o5m
--------------------------------------------------------------------------------
/test/t/io/data-n5w1r3.osm.o5m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osmcode/libosmium/HEAD/test/t/io/data-n5w1r3.osm.o5m
--------------------------------------------------------------------------------
/test/t/io/data_bzip2.txt.bz2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osmcode/libosmium/HEAD/test/t/io/data_bzip2.txt.bz2
--------------------------------------------------------------------------------
/test/t/io/deleted_nodes.osh.pbf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osmcode/libosmium/HEAD/test/t/io/deleted_nodes.osh.pbf
--------------------------------------------------------------------------------
/test/t/io/corrupt_data_gzip.txt.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osmcode/libosmium/HEAD/test/t/io/corrupt_data_gzip.txt.gz
--------------------------------------------------------------------------------
/test/t/io/corrupt_data_bzip2.txt.bz2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osmcode/libosmium/HEAD/test/t/io/corrupt_data_bzip2.txt.bz2
--------------------------------------------------------------------------------
/test/t/io/data_pbf_version-1.osm.pbf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osmcode/libosmium/HEAD/test/t/io/data_pbf_version-1.osm.pbf
--------------------------------------------------------------------------------
/test/examples/t/read/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_test(NAME examples_read
3 | COMMAND osmium_read ${CMAKE_CURRENT_SOURCE_DIR}/data.osm)
4 |
5 |
--------------------------------------------------------------------------------
/test/t/io/data_pbf_version-1-densenodes.osm.pbf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osmcode/libosmium/HEAD/test/t/io/data_pbf_version-1-densenodes.osm.pbf
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "test/data-tests/osm-testdata"]
2 | path = test/data-tests/osm-testdata
3 | url = https://github.com/osmcode/osm-testdata
4 |
--------------------------------------------------------------------------------
/.codecov.yml:
--------------------------------------------------------------------------------
1 |
2 | ignore:
3 | - "include/gdalcpp.hpp"
4 | - "include/protozero"
5 | - "include/utf8"
6 | - "test/include/catch.hpp"
7 |
8 |
--------------------------------------------------------------------------------
/test/t/io/data_pbf_version-1.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/test/examples/t/read_with_progress/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_test(NAME examples_read_with_progress
3 | COMMAND osmium_read_with_progress ${CMAKE_CURRENT_SOURCE_DIR}/data.osm)
4 |
5 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | contact_links:
2 | - name: Official OpenStreetMap forum
3 | url: https://community.openstreetmap.org/
4 | about: Ask questions and get support from the community.
5 |
--------------------------------------------------------------------------------
/doc/README.md:
--------------------------------------------------------------------------------
1 |
2 | The `header.html` is created with:
3 |
4 | `doxygen -w html header.html footer.html stylesheet.css`
5 |
6 | This might have to be run again for newer Doxygen versions. After that add
7 | changes back in.
8 |
9 |
--------------------------------------------------------------------------------
/.github/actions/ctest/action.yml:
--------------------------------------------------------------------------------
1 | name: Test
2 |
3 | runs:
4 | using: composite
5 | steps:
6 | - name: Test
7 | run: ctest --output-on-failure -C Release
8 | shell: bash
9 | working-directory: build
10 |
--------------------------------------------------------------------------------
/.github/actions/build/action.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 |
3 | runs:
4 | using: composite
5 | steps:
6 | - name: Build
7 | run: cmake --build . --config Release --verbose
8 | shell: bash
9 | working-directory: build
10 |
--------------------------------------------------------------------------------
/test/t/io/data.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/test/data-tests/include/testdata-testcases.hpp:
--------------------------------------------------------------------------------
1 | #ifndef TESTDATA_TESTCASES_HPP
2 | #define TESTDATA_TESTCASES_HPP
3 |
4 | #include
5 |
6 | #include
7 |
8 | extern std::string dirname;
9 |
10 | #endif // TESTDATA_TESTCASES_HPP
11 |
--------------------------------------------------------------------------------
/.github/actions/install-protozero/action.yml:
--------------------------------------------------------------------------------
1 | name: Install Protozero from git
2 |
3 | runs:
4 | using: composite
5 | steps:
6 | - name: Install from git
7 | run: git clone --quiet --depth 1 https://github.com/mapbox/protozero.git ../protozero
8 | shell: bash
9 |
--------------------------------------------------------------------------------
/.github/actions/install-macos/action.yml:
--------------------------------------------------------------------------------
1 | name: Install homebrew packages on macOS
2 |
3 | runs:
4 | using: composite
5 | steps:
6 | - name: Install homebrew packages
7 | run: |
8 | brew install \
9 | boost \
10 | gdal
11 | shell: bash
12 |
--------------------------------------------------------------------------------
/test/examples/t/count/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_test(NAME examples_count
3 | COMMAND osmium_count ${CMAKE_CURRENT_SOURCE_DIR}/data.osm)
4 |
5 | set_tests_properties(examples_count PROPERTIES
6 | PASS_REGULAR_EXPRESSION "^Nodes: 2\nWays: 1\nRelations: 1\n\nMemory used:"
7 | )
8 |
9 |
--------------------------------------------------------------------------------
/test/examples/t/road_length/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_test(NAME examples_road_length
3 | COMMAND osmium_road_length ${CMAKE_CURRENT_SOURCE_DIR}/road.osm)
4 |
5 | set_tests_properties(examples_road_length PROPERTIES
6 | PASS_REGULAR_EXPRESSION "^Length: 0\\.405.*km\n$"
7 | )
8 |
9 |
--------------------------------------------------------------------------------
/benchmarks/run_benchmarks.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # run_benchmarks.sh
4 | #
5 | # Run all benchmarks.
6 | #
7 |
8 | set -e
9 |
10 | for benchmark in @CMAKE_BINARY_DIR@/benchmarks/run_benchmark_*.sh; do
11 | name=`basename $benchmark`
12 | echo "Running $name..."
13 | $benchmark
14 | done
15 |
16 |
--------------------------------------------------------------------------------
/test/README:
--------------------------------------------------------------------------------
1 | Osmium uses Catch (https://github.com/catchorg/Catch2/) for its unit tests.
2 |
3 | Currently we are still using version 1.
4 |
5 | Only one header file is needed (catch.hpp) which can be downloaded from
6 | https://github.com/catchorg/Catch2/tree/Catch1.x and put into the include
7 | directory.
8 |
9 |
--------------------------------------------------------------------------------
/test/examples/t/pub_names/pub-noname.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/test/t/io/data-n0w1r3.osm.opl:
--------------------------------------------------------------------------------
1 | w20 v1 dV c1 t2014-01-01T00:00:00Z i1 utest Thighway=primary Nn10,n11
2 | r30 v1 dV c1 t2014-01-01T00:00:00Z i1 utest Ttype=test Mn10@none
3 | r31 v1 dV c1 t2014-01-01T00:00:00Z i1 utest Ttype=restriction Mw20@from,n11@via,w22@to
4 | r32 v1 dV c1 t2014-01-01T00:00:00Z i1 utest Ttest=relinrel Mr30@none
5 |
--------------------------------------------------------------------------------
/test/t/io/test_reader_fileformat.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include "utils.hpp"
4 |
5 | #include
6 |
7 | TEST_CASE("Reader throws on unsupported file format") {
8 | REQUIRE_THROWS_AS(osmium::io::Reader{with_data_dir("t/io/data.osm")}, osmium::unsupported_file_format_error);
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/test/examples/t/pub_names/pub-node.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/test/examples/t/amenity_list/node.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/test/t/io/deleted_nodes.osh:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/test/t/geom/test_exception.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include
4 |
5 | #include
6 |
7 | TEST_CASE("Geometry exception") {
8 |
9 | const osmium::geometry_error e{"some error message", "node", 17};
10 | REQUIRE(e.id() == 17);
11 | REQUIRE(std::string{e.what()} == "some error message (node_id=17)");
12 |
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/test/t/io/data-n5w1r0.osm.opl:
--------------------------------------------------------------------------------
1 | n10 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1 y1
2 | n11 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1.1 y1
3 | n12 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1.2 y1
4 | n13 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1.3 y1
5 | n14 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1.4 y1
6 | w20 v1 dV c1 t2014-01-01T00:00:00Z i1 utest Thighway=primary Nn10,n11
7 |
--------------------------------------------------------------------------------
/test/examples/t/location_cache/way.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/test/t/util/test_timer_disabled.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include
4 |
5 | #include
6 | #include
7 |
8 | TEST_CASE("timer") {
9 | osmium::Timer timer;
10 | timer.start();
11 | std::this_thread::sleep_for(std::chrono::milliseconds(1));
12 | timer.stop();
13 | REQUIRE(timer.elapsed_microseconds() == 0);
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/test/t/util/test_memory.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include
4 |
5 | TEST_CASE("Check memory usage") {
6 | #ifdef __linux__
7 | const osmium::MemoryUsage m1;
8 | REQUIRE(m1.current() > 1);
9 | REQUIRE(m1.peak() > 1);
10 | #else
11 | const osmium::MemoryUsage m;
12 | REQUIRE(m.current() == 0);
13 | REQUIRE(m.peak() == 0);
14 | #endif
15 | }
16 |
17 |
--------------------------------------------------------------------------------
/test/t/util/test_timer_enabled.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include
4 | #include
5 |
6 | #define OSMIUM_WITH_TIMER
7 | #include
8 |
9 | TEST_CASE("timer") {
10 | osmium::Timer timer;
11 | timer.start();
12 | std::this_thread::sleep_for(std::chrono::milliseconds(1));
13 | timer.stop();
14 | REQUIRE(timer.elapsed_microseconds() > 900);
15 | }
16 |
17 |
--------------------------------------------------------------------------------
/test/data-tests/README.md:
--------------------------------------------------------------------------------
1 | # OSM Testdata
2 |
3 | This directory contains software that can be used with the osm-testdata
4 | repository at https://github.com/osmcode/osm-testdata . To use it, clone
5 | the `osm-testdata` repository in the same directory where you cloned the
6 | `libosmium` repository.
7 |
8 | Tests will be built if the CMake option `BUILD_DATA_TESTS` is set and run as
9 | part of the `ctest` run.
10 |
11 |
--------------------------------------------------------------------------------
/.github/actions/install-windows/action.yml:
--------------------------------------------------------------------------------
1 | name: Install vcpkg packages on Windows
2 |
3 | runs:
4 | using: composite
5 | steps:
6 | - name: Install packages
7 | run: |
8 | vcpkg install \
9 | boost-crc:x64-windows \
10 | boost-variant:x64-windows \
11 | bzip2:x64-windows \
12 | expat:x64-windows \
13 | lz4:x64-windows \
14 | zlib:x64-windows
15 | shell: bash
16 |
--------------------------------------------------------------------------------
/test/include/test_crc.hpp:
--------------------------------------------------------------------------------
1 | #ifndef OSMIUM_TEST_CRC_HPP
2 | #define OSMIUM_TEST_CRC_HPP
3 |
4 | #ifdef OSMIUM_TEST_CRC_USE_BOOST
5 |
6 | /* Use the CRC32 implementation from boost. */
7 | #include
8 | using crc_type = boost::crc_32_type;
9 |
10 | #else
11 |
12 | /* Use the CRC32 implementation from zlib. */
13 | #include
14 | using crc_type = osmium::CRC_zlib;
15 |
16 | #endif
17 |
18 | #endif // OSMIUM_TEST_CRC_HPP
19 |
--------------------------------------------------------------------------------
/doc/osmium.css:
--------------------------------------------------------------------------------
1 |
2 | body {
3 | font-family: "Droid Sans",Helvetica,Arial,sans-serif;
4 | background-color: #ffffff;
5 | color: #202060;
6 | }
7 |
8 | .tabs, .tabs2, .tabs3, .navpath ul, .tablist li {
9 | background-image: none;
10 | }
11 |
12 | .tabs, .tabs2, .tabs3 {
13 | border-top: 1px solid #202060;
14 | }
15 |
16 | div.contents {
17 | margin: 0px;
18 | padding-top: 10px;
19 | padding-left: 12px;
20 | padding-right: 8px;
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/test/examples/t/filter_discussions/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_test(NAME examples_filter_discussions
3 | COMMAND osmium_filter_discussions ${CMAKE_CURRENT_SOURCE_DIR}/changesets.osm -)
4 |
5 | set_tests_properties(examples_filter_discussions PROPERTIES
6 | FAIL_REGULAR_EXPRESSION "
4 | #include
5 |
6 | #include
7 |
8 | TEST_CASE("Projection using MercatorProjection class to WKT") {
9 | const osmium::geom::WKTFactory factory{2};
10 |
11 | const std::string wkt{factory.create_point(osmium::Location{3.2, 4.2})};
12 | REQUIRE(wkt == "POINT(356222.37 467961.14)");
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/test/examples/t/pub_names/pub-addr.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/test/examples/t/debug/changesets.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.github/actions/install-ubuntu/action.yml:
--------------------------------------------------------------------------------
1 | name: Install apt packages on Ubuntu/Debian
2 |
3 | runs:
4 | using: composite
5 | steps:
6 | - name: Install packages
7 | run: |
8 | sudo apt-get update -qq
9 | sudo apt-get install -yq \
10 | doxygen \
11 | libboost-dev \
12 | libbz2-dev \
13 | libgdal-dev \
14 | libgeos++-dev \
15 | liblz4-dev \
16 | ruby-json \
17 | spatialite-bin
18 | shell: bash
19 |
--------------------------------------------------------------------------------
/benchmarks/run_benchmark_static_vs_dynamic_index.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # run_benchmark_static_vs_dynamic_index.sh
4 | #
5 |
6 | set -e
7 |
8 | BENCHMARK_NAME=static_vs_dynamic_index
9 |
10 | . @CMAKE_BINARY_DIR@/benchmarks/setup.sh
11 |
12 | CMD=$OB_DIR/osmium_benchmark_$BENCHMARK_NAME
13 |
14 | for data in $OB_DATA_FILES; do
15 | filesize=`stat --format="%s" --dereference $data`
16 | if [ $filesize -lt 500000000 ]; then
17 | echo "========================"
18 | $CMD $data
19 | fi
20 | done
21 |
22 |
--------------------------------------------------------------------------------
/test/t/io/data-n5w0r3.osm.opl:
--------------------------------------------------------------------------------
1 | n10 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1 y1
2 | n11 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1.1 y1
3 | n12 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1.2 y1
4 | n13 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1.3 y1
5 | n14 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1.4 y1
6 | r30 v1 dV c1 t2014-01-01T00:00:00Z i1 utest Ttype=test Mn10@none
7 | r31 v1 dV c1 t2014-01-01T00:00:00Z i1 utest Ttype=restriction Mw20@from,n11@via,w22@to
8 | r32 v1 dV c1 t2014-01-01T00:00:00Z i1 utest Ttest=relinrel Mr30@none
9 |
--------------------------------------------------------------------------------
/.github/actions/cmake/action.yml:
--------------------------------------------------------------------------------
1 | name: CMake
2 |
3 | runs:
4 | using: composite
5 | steps:
6 | - name: Create build directory
7 | run: mkdir build
8 | shell: bash
9 | - name: Configure
10 | run: |
11 | cmake -LA .. \
12 | -DBUILD_DATA_TESTS=ON \
13 | -DUSE_CPP_VERSION=${CPP_VERSION} \
14 | -DPROTOZERO_INCLUDE_DIR=${GITHUB_WORKSPACE}/../protozero/include \
15 | -DCMAKE_BUILD_TYPE=${BUILD_TYPE}
16 | shell: bash
17 | working-directory: build
18 |
--------------------------------------------------------------------------------
/test/examples/t/amenity_list/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_test(NAME examples_amenity_list_node
3 | COMMAND osmium_amenity_list ${CMAKE_CURRENT_SOURCE_DIR}/node.osm)
4 |
5 | set_tests_properties(examples_amenity_list_node PROPERTIES
6 | PASS_REGULAR_EXPRESSION " 8\\.8721, 53\\.0966 post_office")
7 |
8 | add_test(NAME examples_amenity_list_area
9 | COMMAND osmium_amenity_list ${CMAKE_CURRENT_SOURCE_DIR}/area.osm)
10 |
11 | set_tests_properties(examples_amenity_list_area PROPERTIES
12 | PASS_REGULAR_EXPRESSION " 8\\.5839, 53\\.5602 restaurant")
13 |
14 |
--------------------------------------------------------------------------------
/test/t/io/data-n5w1r3.osm.opl:
--------------------------------------------------------------------------------
1 | n10 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1 y1
2 | n11 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1.1 y1
3 | n12 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1.2 y1
4 | n13 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1.3 y1
5 | n14 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1.4 y1
6 | w20 v1 dV c1 t2014-01-01T00:00:00Z i1 utest Thighway=primary Nn10,n11
7 | r30 v1 dV c1 t2014-01-01T00:00:00Z i1 utest Ttype=test Mn10@none
8 | r31 v1 dV c1 t2014-01-01T00:00:00Z i1 utest Ttype=restriction Mw20@from,n11@via,w22@to
9 | r32 v1 dV c1 t2014-01-01T00:00:00Z i1 utest Ttest=relinrel Mr30@none
10 |
--------------------------------------------------------------------------------
/.github/actions/cmake-windows/action.yml:
--------------------------------------------------------------------------------
1 | name: Windows CMake
2 |
3 | runs:
4 | using: composite
5 | steps:
6 | - name: Create build directory
7 | run: mkdir build
8 | shell: bash
9 | - name: Configure
10 | run: |
11 | cmake -LA .. \
12 | -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake \
13 | -DBUILD_HEADERS=OFF \
14 | -DBUILD_BENCHMARKS=ON \
15 | -DOsmium_DEBUG=TRUE \
16 | -DPROTOZERO_INCLUDE_DIR=${GITHUB_WORKSPACE}/../protozero/include
17 | shell: bash
18 | working-directory: build
19 |
--------------------------------------------------------------------------------
/test/t/index/test_nwr_array.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include
4 |
5 | TEST_CASE("nwr_array") {
6 | osmium::nwr_array a;
7 | a(osmium::item_type::node) = 1;
8 | a(osmium::item_type::way) = 2;
9 | a(osmium::item_type::relation) = 3;
10 |
11 | REQUIRE(a(osmium::item_type::node) == 1);
12 | REQUIRE(a(osmium::item_type::way) == 2);
13 | REQUIRE(a(osmium::item_type::relation) == 3);
14 |
15 | auto it = a.cbegin();
16 | REQUIRE(*it++ == 1);
17 | REQUIRE(*it++ == 2);
18 | REQUIRE(*it++ == 3);
19 | REQUIRE(it == a.cend());
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/test/examples/t/create_pois/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_test(NAME examples_create_pois_okay
3 | COMMAND osmium_create_pois -)
4 |
5 | set_tests_properties(examples_create_pois_okay PROPERTIES
6 | PASS_REGULAR_EXPRESSION "^n-1 v1 dV c0 t....-..-..T..:..:..Z i0 u Tamenity=post_box x1\\.23 y3\\.45\nn-2 v1 dV c0 t....-..-..T..:..:..Z i0 u Tamenity=restaurant,name=Chez%20%OSM x1\\.24 y3\\.46\n$"
7 | )
8 |
9 | add_test(NAME examples_create_pois_unknown_file_type
10 | COMMAND osmium_create_pois foo)
11 |
12 | set_tests_properties(examples_create_pois_unknown_file_type PROPERTIES WILL_FAIL true)
13 |
14 |
--------------------------------------------------------------------------------
/test/examples/t/location_cache/data.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/benchmarks/run_benchmark_count.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # run_benchmark_count.sh
4 | #
5 |
6 | set -e
7 |
8 | BENCHMARK_NAME=count
9 |
10 | . @CMAKE_BINARY_DIR@/benchmarks/setup.sh
11 |
12 | CMD=$OB_DIR/osmium_benchmark_$BENCHMARK_NAME
13 |
14 | echo "# file size num mem time cpu_kernel cpu_user cpu_percent cmd options"
15 | for data in $OB_DATA_FILES; do
16 | filename=`basename $data`
17 | filesize=`stat --format="%s" --dereference $data`
18 | for n in $OB_SEQ; do
19 | $OB_TIME_CMD -f "$filename $filesize $n $OB_TIME_FORMAT" $CMD $data 2>&1 >/dev/null | sed -e "s%$DATA_DIR/%%" | sed -e "s%$OB_DIR/%%"
20 | done
21 | done
22 |
23 |
--------------------------------------------------------------------------------
/benchmarks/run_benchmark_count_tag.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # run_benchmark_count_tag.sh
4 | #
5 |
6 | set -e
7 |
8 | BENCHMARK_NAME=count_tag
9 |
10 | . @CMAKE_BINARY_DIR@/benchmarks/setup.sh
11 |
12 | CMD=$OB_DIR/osmium_benchmark_$BENCHMARK_NAME
13 |
14 | echo "# file size num mem time cpu_kernel cpu_user cpu_percent cmd options"
15 | for data in $OB_DATA_FILES; do
16 | filename=`basename $data`
17 | filesize=`stat --format="%s" --dereference $data`
18 | for n in $OB_SEQ; do
19 | $OB_TIME_CMD -f "$filename $filesize $n $OB_TIME_FORMAT" $CMD $data 2>&1 >/dev/null | sed -e "s%$DATA_DIR/%%" | sed -e "s%$OB_DIR/%%"
20 | done
21 | done
22 |
23 |
--------------------------------------------------------------------------------
/benchmarks/run_benchmark_mercator.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # run_benchmark_mercator.sh
4 | #
5 |
6 | set -e
7 |
8 | BENCHMARK_NAME=mercator
9 |
10 | . @CMAKE_BINARY_DIR@/benchmarks/setup.sh
11 |
12 | CMD=$OB_DIR/osmium_benchmark_$BENCHMARK_NAME
13 |
14 | echo "# file size num mem time cpu_kernel cpu_user cpu_percent cmd options"
15 | for data in $OB_DATA_FILES; do
16 | filename=`basename $data`
17 | filesize=`stat --format="%s" --dereference $data`
18 | for n in $OB_SEQ; do
19 | $OB_TIME_CMD -f "$filename $filesize $n $OB_TIME_FORMAT" $CMD $data 2>&1 >/dev/null | sed -e "s%$DATA_DIR/%%" | sed -e "s%$OB_DIR/%%"
20 | done
21 | done
22 |
23 |
--------------------------------------------------------------------------------
/test/examples/t/count/data.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/test/examples/t/tiles/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_test(NAME examples_tiles_zoom_too_large
3 | COMMAND osmium_tiles 50 1 1)
4 |
5 | set_tests_properties(examples_tiles_zoom_too_large PROPERTIES WILL_FAIL true)
6 |
7 | add_test(NAME examples_tiles_location_invalid
8 | COMMAND osmium_tiles 1 200 200)
9 |
10 | set_tests_properties(examples_tiles_location_invalid PROPERTIES WILL_FAIL true)
11 |
12 | add_test(NAME examples_tiles_okay
13 | COMMAND osmium_tiles 8 55.3 11.7)
14 |
15 | set_tests_properties(examples_tiles_okay PROPERTIES
16 | PASS_REGULAR_EXPRESSION "^WGS84: lon=55.3 lat=11.7\nMercator: x=.*\nTile: zoom=8 x=167 y=119\n$"
17 | )
18 |
19 |
--------------------------------------------------------------------------------
/benchmarks/download_data.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # download_data.sh
4 | #
5 |
6 | cd $DATA_DIR
7 | curl --location --output 1_liechtenstein.osm.pbf https://download.geofabrik.de/europe/liechtenstein-latest.osm.pbf # about 2 MB
8 | curl --location --output 2_bremen.osm.pbf https://download.geofabrik.de/europe/germany/bremen-latest.osm.pbf # about 16 MB
9 | curl --location --output 3_sachsen.osm.pbf https://download.geofabrik.de/europe/germany/sachsen-latest.osm.pbf # about 160 MB
10 | curl --location --output 4_germany.osm.pbf https://download.geofabrik.de/europe/germany-latest.osm.pbf # about 3 GB
11 | curl --location --output 5_planet.osm.pbf https://planet.osm.org/pbf/planet-latest.osm.pbf # about 35 GB
12 |
13 |
--------------------------------------------------------------------------------
/test/examples/t/debug/data.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/test/t/util/test_double.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include
4 |
5 | #include
6 |
7 | TEST_CASE("Check double2string function") {
8 | std::string s1;
9 | osmium::double2string(s1, 1.123, 7);
10 | REQUIRE(s1 == "1.123");
11 |
12 | std::string s2;
13 | osmium::double2string(s2, 1.000, 7);
14 | REQUIRE(s2 == "1");
15 |
16 | std::string s3;
17 | osmium::double2string(s3, 0.0, 7);
18 | REQUIRE(s3 == "0");
19 |
20 | std::string s4;
21 | osmium::double2string(s4, 0.020, 7);
22 | REQUIRE(s4 == "0.02");
23 |
24 | std::string s5;
25 | osmium::double2string(s5, -0.020, 7);
26 | REQUIRE(s5 == "-0.02");
27 |
28 | std::string s6;
29 | osmium::double2string(s6, -0.0, 7);
30 | REQUIRE(s6 == "-0");
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/osmium.imp:
--------------------------------------------------------------------------------
1 | #-----------------------------------------------------------------------------
2 | #
3 | # Configuration for Include-What-You-Use tool
4 | #
5 | # https://include-what-you-use.org/
6 | #
7 | #-----------------------------------------------------------------------------
8 | [
9 | { "include": ["", "private", "", "public"] },
10 | { "include": ["", "private", "", "public"] },
11 | { "include": ["", "public", "", "public"] },
12 | { "include": ['"utf8/checked.h"', "private", "", "public"] },
13 | { "include": ['"utf8/unchecked.h"', "private", "", "public"] },
14 | { "include": ["", "public", "", "public"] },
15 | { "include": ["", "public", "", "public"] }
16 | ]
17 |
--------------------------------------------------------------------------------
/test/examples/t/filter_discussions/changesets.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | fake comment
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/test/data-tests/include/common.hpp:
--------------------------------------------------------------------------------
1 | #ifndef COMMON_HPP
2 | #define COMMON_HPP
3 |
4 | #include
5 | #include
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | using index_neg_type = osmium::index::map::Dummy;
14 | using index_pos_type = osmium::index::map::SparseMemArray;
15 | using location_handler_type = osmium::handler::NodeLocationsForWays;
16 |
17 | #include "check_basics_handler.hpp"
18 | #include "check_wkt_handler.hpp"
19 |
20 | #include "testdata-testcases.hpp"
21 |
22 | #endif // COMMON_HPP
23 |
--------------------------------------------------------------------------------
/test/data-tests/testdata-testcases.cpp:
--------------------------------------------------------------------------------
1 |
2 | #define CATCH_CONFIG_RUNNER
3 |
4 | #include "testdata-testcases.hpp"
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | std::string dirname; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
11 |
12 | int main(int argc, char* argv[]) {
13 | const char* testcases_dir = getenv("TESTCASES_DIR");
14 | if (testcases_dir) {
15 | dirname = testcases_dir;
16 | std::cerr << "Running tests from '" << dirname << "' (from TESTCASES_DIR environment variable)\n";
17 | } else {
18 | std::cerr << "Please set TESTCASES_DIR environment variable.\n";
19 | return 1;
20 | }
21 |
22 | try {
23 | return Catch::Session().run(argc, argv);
24 | } catch (const std::exception& e) {
25 | std::cerr << e.what() << '\n';
26 | return 1;
27 | }
28 |
29 | return 0;
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 |
2 | Some rules for contributing to this project:
3 |
4 | * Please open a separate issue for each problem, question, or comment you have.
5 | Do not re-use existing issues for other topics, even if they are similar. This
6 | keeps issues small and manageable and makes it much easier to follow through
7 | and make sure each problem is taken care of.
8 |
9 | * We'd love for you to send pull requests for fixes you have made or new features
10 | you have added. Please read the [notes for developers](NOTES_FOR_DEVELOPERS.md)
11 | beforehand which contains some coding guidelines.
12 |
13 | If you are reporting a problem:
14 |
15 | * Describe exactly what you were trying to achieve, what you did, what you
16 | expected to happen and what did happen instead. Include relevant information
17 | about the platform, OS version etc. you are using. Include shell commands you
18 | typed in, log files, errors messages etc.
19 |
20 |
--------------------------------------------------------------------------------
/test/t/io/data-n5w1r0.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/test/examples/t/change_tags/result.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/doc/doc.md:
--------------------------------------------------------------------------------
1 |
2 | Osmium is a fast and flexible C++ library for working with OpenStreetMap
3 | data.
4 |
5 | This is the API documentation that was automatically created from the
6 | source code. For more information about the Osmium Library see
7 | https://osmcode.org/libosmium .
8 |
9 | Osmium is free software and available under the Boost Software License.
10 | The source code is available at https://github.com/osmcode/libosmium .
11 |
12 | Osmium is a header-only library. You do not need to compile and link it,
13 | just include the headers you need.
14 |
15 | Everything in namespaces called "detail" is for internal Osmium use only,
16 | do not depend on it in your code. Do not include any include files in
17 | directories named "detail" directly. Include files in directories called
18 | "experimental" and everything in namespaces called "experimental" is
19 | unsupported and may change at any time regardless of the status of the rest
20 | of the library.
21 |
22 |
--------------------------------------------------------------------------------
/test/t/io/test_print_width.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include
4 |
5 | TEST_CASE("Calculate width of a number") {
6 | REQUIRE(osmium::io::detail::print_width(0) == 1);
7 | REQUIRE(osmium::io::detail::print_width(1) == 1);
8 | REQUIRE(osmium::io::detail::print_width(2) == 1);
9 | REQUIRE(osmium::io::detail::print_width(9) == 1);
10 | REQUIRE(osmium::io::detail::print_width(10) == 1); // 0 .. 9
11 | REQUIRE(osmium::io::detail::print_width(11) == 2);
12 | REQUIRE(osmium::io::detail::print_width(42) == 2);
13 | REQUIRE(osmium::io::detail::print_width(99) == 2);
14 | REQUIRE(osmium::io::detail::print_width(100) == 2); // 0 .. 99
15 | REQUIRE(osmium::io::detail::print_width(101) == 3);
16 | REQUIRE(osmium::io::detail::print_width(999) == 3);
17 | REQUIRE(osmium::io::detail::print_width(1000) == 3); // 0 .. 100
18 | REQUIRE(osmium::io::detail::print_width(1001) == 4);
19 | }
20 |
--------------------------------------------------------------------------------
/benchmarks/run_benchmark_index_map.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # run_benchmark_index_map.sh
4 | #
5 |
6 | set -e
7 |
8 | BENCHMARK_NAME=index_map
9 |
10 | . @CMAKE_BINARY_DIR@/benchmarks/setup.sh
11 |
12 | CMD=$OB_DIR/osmium_benchmark_$BENCHMARK_NAME
13 |
14 | #MAPS="sparse_mem_map sparse_mem_table sparse_mem_array sparse_mmap_array sparse_file_array dense_mem_array dense_mmap_array dense_file_array"
15 | MAPS="sparse_mem_map sparse_mem_table sparse_mem_array sparse_mmap_array sparse_file_array"
16 |
17 | echo "# file size num mem time cpu_kernel cpu_user cpu_percent cmd options"
18 | for data in $OB_DATA_FILES; do
19 | filename=`basename $data`
20 | filesize=`stat --format="%s" --dereference $data`
21 | for map in $MAPS; do
22 | for n in $OB_SEQ; do
23 | $OB_TIME_CMD -f "$filename $filesize $n $OB_TIME_FORMAT" $CMD $data $map 2>&1 >/dev/null | sed -e "s%$DATA_DIR/%%" | sed -e "s%$OB_DIR/%%"
24 | done
25 | done
26 | done
27 |
28 |
--------------------------------------------------------------------------------
/test/include/utils.hpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | #ifndef _WIN32
6 | # include
7 | # include
8 |
9 | // This function counts the number of open file descriptors. It is used in
10 | // some tests to make sure that we are not leaking file descriptors.
11 | inline int count_fds() noexcept {
12 | int count = 0;
13 | for (int fd = 0; fd < 100; ++fd) {
14 | if (fcntl(fd, F_GETFD) == 0) {
15 | ++count;
16 | }
17 | }
18 | return count;
19 | }
20 |
21 | #else
22 | // Dummy for Windows which doesn't have fcntl
23 | inline int count_fds() noexcept {
24 | return 0;
25 | }
26 | #endif
27 |
28 |
29 | inline std::string with_data_dir(const char* filename) {
30 | const char* data_dir = getenv("OSMIUM_TEST_DATA_DIR");
31 |
32 | std::string result;
33 | if (data_dir) {
34 | result = data_dir;
35 | result += '/';
36 | }
37 |
38 | result += filename;
39 |
40 | return result;
41 | }
42 |
43 |
--------------------------------------------------------------------------------
/benchmarks/run_benchmark_write_pbf.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # run_benchmark_write_pbf.sh
4 | #
5 | # Will read the input file and after reading it into memory completely,
6 | # write it to /dev/null. Because this will need the time to read *and* write
7 | # the file, it will report the times for reading and writing. You can
8 | # subtract the times needed for the "count" benchmark to (roughly) get the
9 | # write times.
10 | #
11 |
12 | set -e
13 |
14 | BENCHMARK_NAME=write_pbf
15 |
16 | . @CMAKE_BINARY_DIR@/benchmarks/setup.sh
17 |
18 | CMD=$OB_DIR/osmium_benchmark_$BENCHMARK_NAME
19 |
20 | echo "# file size num mem time cpu_kernel cpu_user cpu_percent cmd options"
21 | for data in $OB_DATA_FILES; do
22 | filename=`basename $data`
23 | filesize=`stat --format="%s" --dereference $data`
24 | for n in $OB_SEQ; do
25 | $OB_TIME_CMD -f "$filename $filesize $n $OB_TIME_FORMAT" $CMD $data /dev/null 2>&1 >/dev/null | sed -e "s%$DATA_DIR/%%" | sed -e "s%$OB_DIR/%%"
26 | done
27 | done
28 |
29 |
--------------------------------------------------------------------------------
/test/t/io/test_output_iterator.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | TEST_CASE("Output iterator should be copy constructable and incrementable") {
8 | const osmium::io::Header header{};
9 | osmium::io::Writer writer{"test.osm", header, osmium::io::overwrite::allow};
10 |
11 | const osmium::io::OutputIterator out1{writer};
12 | osmium::io::OutputIterator out2{out1};
13 |
14 | ++out2;
15 | }
16 |
17 | TEST_CASE("Output iterator should be copy assignable") {
18 | const osmium::io::Header header{};
19 | osmium::io::Writer writer1{"test1.osm", header, osmium::io::overwrite::allow};
20 | osmium::io::Writer writer2{"test2.osm", header, osmium::io::overwrite::allow};
21 |
22 | const osmium::io::OutputIterator out1{writer1};
23 | osmium::io::OutputIterator out2{writer2};
24 |
25 | out2 = out1;
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/test/examples/t/pub_names/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_test(NAME examples_pub_names_node
3 | COMMAND osmium_pub_names ${CMAKE_CURRENT_SOURCE_DIR}/pub-node.osm)
4 | set_tests_properties(examples_pub_names_node PROPERTIES
5 | PASS_REGULAR_EXPRESSION "^Im Holze\n$")
6 |
7 | add_test(NAME examples_pub_names_way
8 | COMMAND osmium_pub_names ${CMAKE_CURRENT_SOURCE_DIR}/pub-way.osm)
9 | set_tests_properties(examples_pub_names_way PROPERTIES
10 | PASS_REGULAR_EXPRESSION "^Vereinsheim\n$")
11 |
12 | add_test(NAME examples_pub_names_noname
13 | COMMAND osmium_pub_names ${CMAKE_CURRENT_SOURCE_DIR}/pub-noname.osm)
14 | set_tests_properties(examples_pub_names_noname PROPERTIES
15 | PASS_REGULAR_EXPRESSION "^pub with unknown name\n$")
16 |
17 | add_test(NAME examples_pub_names_addr
18 | COMMAND osmium_pub_names ${CMAKE_CURRENT_SOURCE_DIR}/pub-addr.osm)
19 | set_tests_properties(examples_pub_names_addr PROPERTIES
20 | PASS_REGULAR_EXPRESSION "^Im Holze\n addr:city: Bremen\n")
21 |
22 |
--------------------------------------------------------------------------------
/test/data-tests/testcases/test-120.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | #include "common.hpp"
6 |
7 | class TestHandler120 : public osmium::handler::Handler {
8 |
9 | public:
10 |
11 | TestHandler120() :
12 | osmium::handler::Handler() {
13 | }
14 |
15 | void way(const osmium::Way& way) const {
16 | if (way.id() == 120800) {
17 | REQUIRE(way.version() == 1);
18 | REQUIRE(way.nodes().empty());
19 | } else {
20 | throw std::runtime_error{"Unknown ID"};
21 | }
22 | }
23 |
24 | }; // class TestHandler120
25 |
26 | TEST_CASE("120") {
27 | osmium::io::Reader reader{dirname + "/1/120/data.osm"};
28 |
29 | index_pos_type index_pos;
30 | index_neg_type index_neg;
31 | location_handler_type location_handler{index_pos, index_neg};
32 | location_handler.ignore_errors();
33 |
34 | CheckBasicsHandler check_basics_handler{120, 0, 1, 0};
35 | TestHandler120 test_handler;
36 |
37 | osmium::apply(reader, location_handler, check_basics_handler, test_handler);
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/test/examples/t/change_tags/data.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/test/t/relations/dupl_member.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/test/t/area/test_area_id.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include
4 | #include
5 |
6 | TEST_CASE("object_id to area_id conversion") {
7 | REQUIRE( 46 == osmium::object_id_to_area_id( 23, osmium::item_type::way));
8 | REQUIRE( 47 == osmium::object_id_to_area_id( 23, osmium::item_type::relation));
9 | REQUIRE( 0 == osmium::object_id_to_area_id( 0, osmium::item_type::way));
10 | REQUIRE( 1 == osmium::object_id_to_area_id( 0, osmium::item_type::relation));
11 | REQUIRE(-24 == osmium::object_id_to_area_id(-12, osmium::item_type::way));
12 | REQUIRE(-25 == osmium::object_id_to_area_id(-12, osmium::item_type::relation));
13 | }
14 |
15 | TEST_CASE("area_id to object_id conversion") {
16 | REQUIRE( 23 == osmium::area_id_to_object_id( 46));
17 | REQUIRE( 23 == osmium::area_id_to_object_id( 47));
18 | REQUIRE( 0 == osmium::area_id_to_object_id( 0));
19 | REQUIRE( 0 == osmium::area_id_to_object_id( 1));
20 | REQUIRE(-12 == osmium::area_id_to_object_id(-24));
21 | REQUIRE(-12 == osmium::area_id_to_object_id(-25));
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/test/t/io/data-n0w1r3.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/test/t/io/test_compression_factory.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include
4 |
5 | TEST_CASE("Create compressor using factory") {
6 | const auto& factory = osmium::io::CompressionFactory::instance();
7 | REQUIRE(factory.create_compressor(osmium::io::file_compression::none, -1, osmium::io::fsync::no));
8 | }
9 |
10 | TEST_CASE("Create decompressor using factory") {
11 | const auto& factory = osmium::io::CompressionFactory::instance();
12 | REQUIRE(factory.create_decompressor(osmium::io::file_compression::none, nullptr, 0));
13 | }
14 |
15 | TEST_CASE("Compression factory fails on undefined compression") {
16 | const auto& factory = osmium::io::CompressionFactory::instance();
17 | REQUIRE_THROWS_AS(factory.create_compressor(osmium::io::file_compression::gzip, -1, osmium::io::fsync::no),
18 | osmium::unsupported_file_format_error);
19 | REQUIRE_THROWS_WITH(factory.create_compressor(osmium::io::file_compression::gzip, -1, osmium::io::fsync::no),
20 | "Support for compression 'gzip' not compiled into this binary");
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/test/examples/t/area_test/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_test(NAME examples_area_test_help
3 | COMMAND osmium_area_test -h)
4 |
5 | set_tests_properties(examples_area_test_help PROPERTIES
6 | PASS_REGULAR_EXPRESSION "^osmium_area_test .* OSMFILE")
7 |
8 | add_test(NAME examples_area_test_data
9 | COMMAND osmium_area_test -o ${CMAKE_CURRENT_SOURCE_DIR}/data.osm)
10 |
11 | set_tests_properties(examples_area_test_data PROPERTIES
12 | PASS_REGULAR_EXPRESSION "\nWarning! Some member ways missing for these multipolygon relations: 701901\n$")
13 |
14 | add_test(NAME examples_area_test_dump
15 | COMMAND osmium_area_test -o ${CMAKE_CURRENT_SOURCE_DIR}/data.osm)
16 |
17 | set_tests_properties(examples_area_test_dump PROPERTIES
18 | PASS_REGULAR_EXPRESSION " id=1403801")
19 |
20 | add_test(NAME examples_area_test_wkt
21 | COMMAND osmium_area_test -w ${CMAKE_CURRENT_SOURCE_DIR}/data.osm)
22 |
23 | set_tests_properties(examples_area_test_wkt PROPERTIES
24 | PASS_REGULAR_EXPRESSION "MULTIPOLYGON\\(\\(\\(7.11 1.01,7.14 1.01,7.14 1.04,7.11 1.04,7.11 1.01\\)\\)\\)\n")
25 |
26 |
--------------------------------------------------------------------------------
/test/data-tests/testcases/test-121.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | #include "common.hpp"
6 |
7 | class TestHandler121 : public osmium::handler::Handler {
8 |
9 | public:
10 |
11 | TestHandler121() :
12 | osmium::handler::Handler() {
13 | }
14 |
15 | void way(const osmium::Way& way) const {
16 | if (way.id() == 121800) {
17 | REQUIRE(way.version() == 1);
18 | REQUIRE(way.nodes().size() == 1);
19 | } else {
20 | throw std::runtime_error{"Unknown ID"};
21 | }
22 | }
23 |
24 | }; // class TestHandler121
25 |
26 | TEST_CASE("121") {
27 | osmium::io::Reader reader{dirname + "/1/121/data.osm"};
28 |
29 | index_pos_type index_pos;
30 | index_neg_type index_neg;
31 | location_handler_type location_handler{index_pos, index_neg};
32 | location_handler.ignore_errors();
33 |
34 | CheckBasicsHandler check_basics_handler{121, 1, 1, 0};
35 | CheckWKTHandler check_wkt_handler{dirname, 121};
36 | TestHandler121 test_handler;
37 |
38 | osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/test/valgrind.supp:
--------------------------------------------------------------------------------
1 | #-----------------------------------------------------------------------------
2 | #
3 | # This file describes messages that Valgrind should suppress, because they
4 | # are about problems outside Libosmium that we can't fix anyway.
5 | #
6 | # See http://valgrind.org/docs/manual/manual-core.html#manual-core.suppress
7 | #
8 | #-----------------------------------------------------------------------------
9 |
10 | {
11 | dl_error1
12 | Memcheck:Cond
13 | fun:index
14 | fun:expand_dynamic_string_token
15 | fun:fillin_rpath
16 | fun:_dl_init_paths
17 | fun:dl_main
18 | fun:_dl_sysdep_start
19 | fun:_dl_start
20 | }
21 | {
22 | dl_error2
23 | Memcheck:Cond
24 | fun:index
25 | fun:expand_dynamic_string_token
26 | fun:_dl_map_object
27 | fun:map_doit
28 | fun:_dl_catch_error
29 | fun:do_preload
30 | fun:dl_main
31 | fun:_dl_sysdep_start
32 | fun:_dl_start
33 | }
34 | {
35 | libpoppler_leak
36 | Memcheck:Leak
37 | fun:malloc
38 | fun:gmalloc
39 | fun:copyString
40 | }
41 | {
42 | tmpfile
43 | Memcheck:Leak
44 | fun:malloc
45 | fun:fdopen@@GLIBC_*
46 | fun:tmpfile@@GLIBC_*
47 | }
48 |
--------------------------------------------------------------------------------
/test/data-tests/testcases/test-122.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | #include "common.hpp"
6 |
7 | class TestHandler122 : public osmium::handler::Handler {
8 |
9 | public:
10 |
11 | TestHandler122() :
12 | osmium::handler::Handler() {
13 | }
14 |
15 | void way(const osmium::Way& way) const {
16 | if (way.id() == 122800) {
17 | REQUIRE(way.version() == 1);
18 | REQUIRE(way.nodes().size() == 2);
19 | REQUIRE(way.nodes()[0] == way.nodes()[1]);
20 | } else {
21 | throw std::runtime_error{"Unknown ID"};
22 | }
23 | }
24 |
25 | }; // class TestHandler122
26 |
27 | TEST_CASE("122") {
28 | osmium::io::Reader reader{dirname + "/1/122/data.osm"};
29 |
30 | index_pos_type index_pos;
31 | index_neg_type index_neg;
32 | location_handler_type location_handler{index_pos, index_neg};
33 | location_handler.ignore_errors();
34 |
35 | CheckBasicsHandler check_basics_handler{122, 1, 1, 0};
36 | CheckWKTHandler check_wkt_handler{dirname, 122};
37 | TestHandler122 test_handler;
38 |
39 | osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/benchmarks/setup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # setup.sh
4 | #
5 |
6 | if [ -z $DATA_DIR ]; then
7 | echo "Please set DATA_DIR environment variable before running benchmark"
8 | exit 1
9 | fi
10 |
11 | OB_DIR=@CMAKE_BINARY_DIR@/benchmarks
12 | OB_BUILD_TYPE=@CMAKE_BUILD_TYPE@
13 | OB_COMPILER=@CMAKE_CXX_COMPILER@
14 | OB_COMPILER_VERSION=`$OB_COMPILER --version | head -1`
15 | OB_CXXFLAGS="@_cxx_flags@"
16 |
17 | OB_RUNS=3
18 | OB_SEQ=`seq -s' ' 1 $OB_RUNS`
19 |
20 | OB_TIME_CMD=/usr/bin/time
21 | OB_TIME_FORMAT="%M %e %S %U %P %C"
22 |
23 | OB_DATA_FILES=`find -L $DATA_DIR -mindepth 1 -maxdepth 1 -type f | sort`
24 |
25 | echo "BENCHMARK: $BENCHMARK_NAME"
26 | echo "---------------------"
27 | echo "BUILD:"
28 | echo "build type\t: $OB_BUILD_TYPE"
29 | echo "compiler\t: $OB_COMPILER"
30 | echo "CXX version\t: $OB_COMPILER_VERSION"
31 | echo "CXX flags\t: $OB_CXXFLAGS"
32 | echo "---------------------"
33 | echo "CPU:"
34 | grep '^model name' /proc/cpuinfo | tail -1
35 | grep '^cpu MHz' /proc/cpuinfo | tail -1
36 | grep '^cpu cores' /proc/cpuinfo | tail -1
37 | grep '^siblings' /proc/cpuinfo | tail -1
38 |
39 | echo "---------------------"
40 | echo "MEMORY:"
41 | free
42 | echo "---------------------"
43 | echo "RESULTS:"
44 |
45 |
--------------------------------------------------------------------------------
/doc/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | #-----------------------------------------------------------------------------
2 | #
3 | # CMake Config
4 | #
5 | # Libosmium documentation
6 | #
7 | #-----------------------------------------------------------------------------
8 |
9 | message(STATUS "Configuring documentation")
10 |
11 | message(STATUS "Looking for doxygen")
12 | find_package(Doxygen)
13 |
14 | if(DOXYGEN_FOUND)
15 | message(STATUS "Looking for doxygen - found")
16 | configure_file(header.html ${CMAKE_CURRENT_BINARY_DIR}/header.html @ONLY)
17 | configure_file(Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
18 | add_custom_target(doc
19 | ${DOXYGEN_EXECUTABLE}
20 | ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
21 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
22 | COMMENT "Generating API documentation with Doxygen" VERBATIM
23 | )
24 | else()
25 | message(STATUS "Looking for doxygen - not found")
26 | message(STATUS " Disabled making of documentation.")
27 | endif()
28 |
29 | #-----------------------------------------------------------------------------
30 | message(STATUS "Configuring documentation - done")
31 |
32 |
33 | #-----------------------------------------------------------------------------
34 |
--------------------------------------------------------------------------------
/benchmarks/osmium_benchmark_mercator.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | The code in this file is released into the Public Domain.
4 |
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #include
14 | #include
15 | #include
16 | #include
17 |
18 | struct GeomHandler : public osmium::handler::Handler {
19 |
20 | osmium::geom::WKBFactory factory;
21 |
22 | void node(const osmium::Node& node) {
23 | const std::string geom = factory.create_point(node);
24 | }
25 |
26 | };
27 |
28 | int main(int argc, char* argv[]) {
29 | if (argc != 2) {
30 | std::cerr << "Usage: " << argv[0] << " OSMFILE\n";
31 | return 1;
32 | }
33 |
34 | try {
35 | const std::string input_filename{argv[1]};
36 |
37 | osmium::io::Reader reader{input_filename};
38 |
39 | GeomHandler handler;
40 | osmium::apply(reader, handler);
41 | reader.close();
42 | } catch (const std::exception& e) {
43 | std::cerr << e.what() << '\n';
44 | return 1;
45 | }
46 |
47 | return 0;
48 | }
49 |
50 |
--------------------------------------------------------------------------------
/test/examples/t/amenity_list/area.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/include/win_mkstemp.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * mkstemp.c
3 | *
4 | * Provides a trivial replacement for the POSIX `mkstemp()' function,
5 | * suitable for use in MinGW (Win32) applications.
6 | *
7 | * This file is part of the MinGW32 package set.
8 | *
9 | * Contributed by Keith Marshall
10 | * Patched to VS2013 by alex85k
11 | * THIS SOFTWARE IS NOT COPYRIGHTED
12 | *
13 | * This source code is offered for use in the public domain. You may
14 | * use, modify or distribute it freely.
15 | *
16 | * This code is distributed in the hope that it will be useful but
17 | * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
18 | * DISCLAIMED. This includes but is not limited to warranties of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 | */
21 |
22 | #ifndef WIN_MKSTEMP_H
23 | #define WIN_MKSTEMP_H
24 |
25 | #include
26 | #include
27 | #include
28 |
29 | inline int mkstemp( char *templ )
30 | {
31 | int maxtry = 26, rtn = -1;
32 |
33 | while( maxtry-- && (rtn < 0) )
34 | {
35 | char *r = _mktemp( templ );
36 | if( r == NULL )
37 | return -1;
38 | rtn = sopen( r, O_RDWR | O_CREAT | O_EXCL | O_BINARY, SH_DENYRW, 0600 );
39 | }
40 | return rtn;
41 | }
42 | #endif
43 |
--------------------------------------------------------------------------------
/test/data-tests/testcases/test-123.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | #include "common.hpp"
6 |
7 | class TestHandler123 : public osmium::handler::Handler {
8 |
9 | public:
10 |
11 | TestHandler123() :
12 | osmium::handler::Handler() {
13 | }
14 |
15 | void way(const osmium::Way& way) const {
16 | if (way.id() == 123800) {
17 | REQUIRE(way.version() == 1);
18 | REQUIRE(way.nodes().size() == 2);
19 | REQUIRE(way.nodes()[0] != way.nodes()[1]);
20 | REQUIRE(way.nodes()[0].location() == way.nodes()[1].location());
21 | } else {
22 | throw std::runtime_error{"Unknown ID"};
23 | }
24 | }
25 |
26 | }; // class TestHandler123
27 |
28 | TEST_CASE("123") {
29 | osmium::io::Reader reader{dirname + "/1/123/data.osm"};
30 |
31 | index_pos_type index_pos;
32 | index_neg_type index_neg;
33 | location_handler_type location_handler{index_pos, index_neg};
34 | location_handler.ignore_errors();
35 |
36 | CheckBasicsHandler check_basics_handler{123, 2, 1, 0};
37 | CheckWKTHandler check_wkt_handler{dirname, 123};
38 | TestHandler123 test_handler;
39 |
40 | osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
41 | }
42 |
43 |
--------------------------------------------------------------------------------
/benchmarks/osmium_benchmark_write_pbf.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | The code in this file is released into the Public Domain.
4 |
5 | */
6 |
7 | #include
8 | #include
9 |
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 |
16 | int main(int argc, char* argv[]) {
17 | if (argc != 3) {
18 | std::cerr << "Usage: " << argv[0] << " INPUT-FILE OUTPUT-FILE\n";
19 | return 1;
20 | }
21 |
22 | try {
23 | const std::string input_filename{argv[1]};
24 | const std::string output_filename{argv[2]};
25 |
26 | osmium::io::Reader reader{input_filename};
27 | const osmium::io::File output_file{output_filename, "pbf"};
28 | const osmium::io::Header header;
29 | osmium::io::Writer writer{output_file, header, osmium::io::overwrite::allow};
30 |
31 | 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
32 | writer(std::move(buffer));
33 | }
34 |
35 | writer.close();
36 | reader.close();
37 | } catch (const std::exception& e) {
38 | std::cerr << e.what() << '\n';
39 | return 1;
40 | }
41 |
42 | return 0;
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/test/data-tests/testcases/test-100.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | #include "common.hpp"
6 |
7 | class TestHandler100 : public osmium::handler::Handler {
8 |
9 | public:
10 |
11 | TestHandler100() :
12 | osmium::handler::Handler() {
13 | }
14 |
15 | void node(const osmium::Node& node) const {
16 | constexpr const double epsilon = 0.00000001;
17 | if (node.id() == 100000) {
18 | REQUIRE(node.version() == 1);
19 | REQUIRE(node.timestamp() == osmium::Timestamp{"2014-01-01T00:00:00Z"});
20 | REQUIRE(node.uid() == 1);
21 | REQUIRE(!std::strcmp(node.user(), "test"));
22 | REQUIRE(node.changeset() == 1);
23 | REQUIRE(node.location().lon() == Approx(1.02).epsilon(epsilon));
24 | REQUIRE(node.location().lat() == Approx(1.02).epsilon(epsilon));
25 | } else {
26 | throw std::runtime_error{"Unknown ID"};
27 | }
28 | }
29 |
30 | }; // class TestHandler100
31 |
32 | TEST_CASE("100") {
33 | osmium::io::Reader reader{dirname + "/1/100/data.osm"};
34 |
35 | CheckBasicsHandler check_basics_handler{100, 1, 0, 0};
36 | CheckWKTHandler check_wkt_handler{dirname, 100};
37 | TestHandler100 test_handler;
38 |
39 | osmium::apply(reader, check_basics_handler, check_wkt_handler, test_handler);
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/test/data-tests/testcases/test-112.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | #include "common.hpp"
6 |
7 | class TestHandler112 : public osmium::handler::Handler {
8 |
9 | public:
10 |
11 | TestHandler112() :
12 | osmium::handler::Handler() {
13 | }
14 |
15 | void way(const osmium::Way& way) const {
16 | if (way.id() == 112800) {
17 | REQUIRE(way.version() == 1);
18 | REQUIRE(way.nodes().size() == 5);
19 | REQUIRE(way.is_closed());
20 |
21 | const char *test_id = way.tags().get_value_by_key("test:id");
22 | REQUIRE(test_id);
23 | REQUIRE(!std::strcmp(test_id, "112"));
24 | } else {
25 | throw std::runtime_error{"Unknown ID"};
26 | }
27 | }
28 |
29 | }; // class TestHandler112
30 |
31 | TEST_CASE("112") {
32 | osmium::io::Reader reader{dirname + "/1/112/data.osm"};
33 |
34 | index_pos_type index_pos;
35 | index_neg_type index_neg;
36 | location_handler_type location_handler{index_pos, index_neg};
37 | location_handler.ignore_errors();
38 |
39 | CheckBasicsHandler check_basics_handler{112, 4, 1, 0};
40 | CheckWKTHandler check_wkt_handler{dirname, 112};
41 | TestHandler112 test_handler;
42 |
43 | osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/test/data-tests/testcases/test-111.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | #include "common.hpp"
6 |
7 | class TestHandler111 : public osmium::handler::Handler {
8 |
9 | public:
10 |
11 | TestHandler111() :
12 | osmium::handler::Handler() {
13 | }
14 |
15 | void way(const osmium::Way& way) const {
16 | if (way.id() == 111800) {
17 | REQUIRE(way.version() == 1);
18 | REQUIRE(way.nodes().size() == 4);
19 | REQUIRE_FALSE(way.is_closed());
20 |
21 | const char *test_id = way.tags().get_value_by_key("test:id");
22 | REQUIRE(test_id);
23 | REQUIRE(!std::strcmp(test_id, "111"));
24 | } else {
25 | throw std::runtime_error{"Unknown ID"};
26 | }
27 | }
28 |
29 | }; // class TestHandler111
30 |
31 | TEST_CASE("111") {
32 | osmium::io::Reader reader{dirname + "/1/111/data.osm"};
33 |
34 | index_pos_type index_pos;
35 | index_neg_type index_neg;
36 | location_handler_type location_handler{index_pos, index_neg};
37 | location_handler.ignore_errors();
38 |
39 | CheckBasicsHandler check_basics_handler{111, 4, 1, 0};
40 | CheckWKTHandler check_wkt_handler{dirname, 111};
41 | TestHandler111 test_handler;
42 |
43 | osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/test/t/thread/test_queue.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include
4 |
5 | TEST_CASE("Basic use of thread-safe queue") {
6 | osmium::thread::Queue queue;
7 | REQUIRE(queue.empty());
8 | queue.push(22);
9 | REQUIRE_FALSE(queue.empty());
10 | REQUIRE(queue.size() == 1);
11 | int value = 0;
12 | queue.wait_and_pop(value);
13 | REQUIRE(value == 22);
14 | REQUIRE(queue.empty());
15 | }
16 |
17 | TEST_CASE("Queue can have max elements and can be named") {
18 | const osmium::thread::Queue queue{100, "Queue of max size 100"};
19 | }
20 |
21 | TEST_CASE("When queue is shut down, nothing goes in or out") {
22 | osmium::thread::Queue queue;
23 | REQUIRE(queue.in_use());
24 | REQUIRE(queue.empty());
25 | queue.push("foo");
26 | queue.push("bar");
27 | queue.push("baz");
28 | REQUIRE(queue.size() == 3);
29 |
30 | std::string value;
31 |
32 | queue.wait_and_pop(value);
33 | REQUIRE(value == "foo");
34 | REQUIRE(queue.size() == 2);
35 | REQUIRE(queue.in_use());
36 | queue.shutdown();
37 | REQUIRE_FALSE(queue.in_use());
38 | REQUIRE(queue.empty());
39 | queue.push("lost");
40 | REQUIRE(queue.empty());
41 |
42 | value.clear();
43 | queue.try_pop(value);
44 | REQUIRE(value.empty());
45 | queue.wait_and_pop(value);
46 | REQUIRE(value.empty());
47 | }
48 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Boost Software License - Version 1.0 - August 17th, 2003
2 |
3 | Permission is hereby granted, free of charge, to any person or organization
4 | obtaining a copy of the software and accompanying documentation covered by
5 | this license (the "Software") to use, reproduce, display, distribute,
6 | execute, and transmit the Software, and to prepare derivative works of the
7 | Software, and to permit third-parties to whom the Software is furnished to
8 | do so, all subject to the following:
9 |
10 | The copyright notices in the Software and this entire statement, including
11 | the above license grant, this restriction and the following disclaimer,
12 | must be included in all copies of the Software, in whole or in part, and
13 | all derivative works of the Software, unless such copies or derivative
14 | works are solely in the form of machine-executable object code generated by
15 | a source language processor.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 | DEALINGS IN THE SOFTWARE.
24 |
--------------------------------------------------------------------------------
/test/examples/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | #-----------------------------------------------------------------------------
2 | #
3 | # CMake Config
4 | #
5 | # Libosmium example tests
6 | #
7 | #-----------------------------------------------------------------------------
8 |
9 | message(STATUS "Configuring example tests")
10 |
11 | set(EXAMPLE_TESTS
12 | amenity_list
13 | area_test
14 | change_tags
15 | convert
16 | count
17 | create_pois
18 | debug
19 | dump_internal
20 | filter_discussions
21 | index_lookup
22 | location_cache
23 | pub_names
24 | read
25 | read_with_progress
26 | road_length
27 | tiles
28 | )
29 |
30 | # This is the list of all tests that are in the repository. It should be the
31 | # same as the configured list above, if not we'll find out about that below
32 | # and create a fatal error.
33 | file(GLOB _dirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/t ${CMAKE_CURRENT_SOURCE_DIR}/t/*)
34 |
35 | foreach(_dir ${EXAMPLE_TESTS})
36 | message(STATUS " adding test: ${_dir}")
37 | add_subdirectory("t/${_dir}")
38 | list(REMOVE_ITEM _dirs ${_dir})
39 | endforeach()
40 |
41 | if(NOT ${_dirs} STREQUAL "")
42 | message(FATAL_ERROR "Found example tests that are not configured: ${_dirs}")
43 | endif()
44 |
45 | message(STATUS "Configuring example tests - done")
46 |
47 |
48 | #-----------------------------------------------------------------------------
49 |
--------------------------------------------------------------------------------
/test/data-tests/testcases/test-124.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | #include "common.hpp"
6 |
7 | class TestHandler124 : public osmium::handler::Handler {
8 |
9 | public:
10 |
11 | TestHandler124() :
12 | osmium::handler::Handler() {
13 | }
14 |
15 | void way(const osmium::Way& way) const {
16 | if (way.id() == 124800) {
17 | REQUIRE(way.version() == 1);
18 | REQUIRE(way.nodes().size() == 3);
19 | REQUIRE(way.nodes()[0] != way.nodes()[1]);
20 | REQUIRE(way.nodes()[0].location() == way.nodes()[1].location());
21 | REQUIRE(way.nodes()[0] != way.nodes()[2]);
22 | REQUIRE(way.nodes()[0].location() != way.nodes()[2].location());
23 | } else {
24 | throw std::runtime_error{"Unknown ID"};
25 | }
26 | }
27 |
28 | }; // class TestHandler124
29 |
30 | TEST_CASE("124") {
31 | osmium::io::Reader reader{dirname + "/1/124/data.osm"};
32 |
33 | index_pos_type index_pos;
34 | index_neg_type index_neg;
35 | location_handler_type location_handler{index_pos, index_neg};
36 | location_handler.ignore_errors();
37 |
38 | CheckBasicsHandler check_basics_handler{124, 3, 1, 0};
39 | CheckWKTHandler check_wkt_handler{dirname, 124};
40 | TestHandler124 test_handler;
41 |
42 | osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/test/data-tests/testcases/test-101.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 |
4 | #include "common.hpp"
5 |
6 | class TestHandler101 : public osmium::handler::Handler {
7 |
8 | public:
9 |
10 | TestHandler101() :
11 | osmium::handler::Handler() {
12 | }
13 |
14 | void node(const osmium::Node& node) const {
15 | constexpr const double epsilon = 0.00000001;
16 | if (node.id() == 101000) {
17 | REQUIRE(node.version() == 1);
18 | REQUIRE(node.location().lon() == Approx(1.12).epsilon(epsilon));
19 | REQUIRE(node.location().lat() == Approx(1.02).epsilon(epsilon));
20 | } else if (node.id() == 101001) {
21 | REQUIRE(node.version() == 1);
22 | REQUIRE(node.location().lon() == Approx(1.12).epsilon(epsilon));
23 | REQUIRE(node.location().lat() == Approx(1.03).epsilon(epsilon));
24 | } else if (node.id() == 101002) {
25 | } else if (node.id() == 101003) {
26 | } else {
27 | throw std::runtime_error{"Unknown ID"};
28 | }
29 | }
30 |
31 | }; // class TestHandler101
32 |
33 | TEST_CASE("101") {
34 | osmium::io::Reader reader{dirname + "/1/101/data.osm"};
35 |
36 | CheckBasicsHandler check_basics_handler{101, 4, 0, 0};
37 | CheckWKTHandler check_wkt_handler{dirname, 101};
38 | TestHandler101 test_handler;
39 |
40 | osmium::apply(reader, check_basics_handler, check_wkt_handler, test_handler);
41 | }
42 |
43 |
--------------------------------------------------------------------------------
/test/examples/t/pub_names/pub-way.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/cmake/iwyu.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This will run IWYU (Include What You Use) on includes files. The iwyu
4 | # program isn't very reliable and crashes often, but is still useful.
5 | #
6 | # TODO: This script should be integrated with cmake in some way...
7 | #
8 |
9 | # If these are set, the wrong compiler is used by iwyu and there will be
10 | # errors about missing includes.
11 | unset CC
12 | unset CXX
13 |
14 | cmdline="iwyu -Xiwyu --mapping_file=osmium.imp -std=c++11 -I include"
15 |
16 | log=build/iwyu.log
17 |
18 | mkdir -p build/check_reports
19 |
20 | echo "INCLUDE WHAT YOU USE REPORT:" >$log
21 |
22 | allok=yes
23 |
24 | for file in `find include/osmium -name \*.hpp | sort`; do
25 | mkdir -p `dirname build/check_reports/$file`
26 | ifile="build/check_reports/${file%.hpp}.iwyu"
27 | $cmdline $file >$ifile 2>&1
28 | if grep -q 'has correct #includes/fwd-decls' ${ifile}; then
29 | echo "\n\033[1m\033[32m========\033[0m \033[1m${file}\033[0m" >>$log
30 | echo "[OK] ${file}"
31 | elif grep -q 'Assertion failed' ${ifile}; then
32 | echo "\n\033[1m======== ${file}\033[0m" >>$log
33 | echo "[--] ${file}"
34 | allok=no
35 | else
36 | echo "\n\033[1m\033[31m========\033[0m \033[1m${file}\033[0m" >>$log
37 | echo "[ ] ${file}"
38 | allok=no
39 | fi
40 | cat $ifile >>$log
41 | done
42 |
43 | if [ "$allok" = "yes" ]; then
44 | echo "All files OK"
45 | else
46 | echo "There were errors"
47 | fi
48 |
49 |
--------------------------------------------------------------------------------
/test/data-tests/testcases/test-102.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 |
4 | #include "common.hpp"
5 |
6 | class TestHandler102 : public osmium::handler::Handler {
7 |
8 | osmium::Location location;
9 |
10 | public:
11 |
12 | TestHandler102() :
13 | osmium::handler::Handler() {
14 | }
15 |
16 | void node(const osmium::Node& node) {
17 | constexpr const double epsilon = 0.00000001;
18 | if (node.id() == 102000) {
19 | REQUIRE(node.version() == 1);
20 | REQUIRE(node.location().lon() == Approx(1.24).epsilon(epsilon));
21 | REQUIRE(node.location().lat() == Approx(1.02).epsilon(epsilon));
22 | location = node.location();
23 | } else if (node.id() == 102001) {
24 | REQUIRE(node.version() == 1);
25 | REQUIRE(node.location().lon() == Approx(1.24).epsilon(epsilon));
26 | REQUIRE(node.location().lat() == Approx(1.02).epsilon(epsilon));
27 | REQUIRE(node.location() == location);
28 | } else {
29 | throw std::runtime_error{"Unknown ID"};
30 | }
31 | }
32 |
33 | }; // class TestHandler102
34 |
35 | TEST_CASE("102") {
36 | osmium::io::Reader reader{dirname + "/1/102/data.osm"};
37 |
38 | CheckBasicsHandler check_basics_handler{102, 2, 0, 0};
39 | CheckWKTHandler check_wkt_handler{dirname, 102};
40 | TestHandler102 test_handler;
41 |
42 | osmium::apply(reader, check_basics_handler, check_wkt_handler, test_handler);
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/test/t/io/data-n5w0r3.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/examples/osmium_read.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | EXAMPLE osmium_read
4 |
5 | Reads and discards the contents of the input file.
6 | (It can be used for timing.)
7 |
8 | DEMONSTRATES USE OF:
9 | * file input
10 |
11 | LICENSE
12 | The code in this example file is released into the Public Domain.
13 |
14 | */
15 |
16 | #include
17 | #include // for std::cerr
18 |
19 | // Allow any format of input files (XML, PBF, ...)
20 | #include
21 |
22 | int main(int argc, char* argv[]) {
23 | if (argc != 2) {
24 | std::cerr << "Usage: " << argv[0] << " OSMFILE\n";
25 | return 1;
26 | }
27 |
28 | try {
29 | // The Reader is initialized here with an osmium::io::File, but could
30 | // also be directly initialized with a file name.
31 | const osmium::io::File input_file{argv[1]};
32 | osmium::io::Reader reader{input_file};
33 |
34 | // OSM data comes in buffers, read until there are no more.
35 | while (const osmium::memory::Buffer buffer = reader.read()) {
36 | // do nothing
37 | }
38 |
39 | // You do not have to close the Reader explicitly, but because the
40 | // destructor can't throw, you will not see any errors otherwise.
41 | reader.close();
42 | } catch (const std::exception& e) {
43 | // All exceptions used by the Osmium library derive from std::exception.
44 | std::cerr << e.what() << '\n';
45 | return 1;
46 | }
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/test/data-tests/testcases/test-116.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | #include "common.hpp"
6 |
7 | class TestHandler116 : public osmium::handler::Handler {
8 |
9 | public:
10 |
11 | TestHandler116() :
12 | osmium::handler::Handler() {
13 | }
14 |
15 | void way(const osmium::Way& way) const {
16 | if (way.id() == 116800) {
17 | REQUIRE(way.version() == 1);
18 | REQUIRE(way.nodes().size() == 2);
19 | REQUIRE_FALSE(way.is_closed());
20 | REQUIRE(way.nodes()[0].ref() == 116000);
21 | REQUIRE(way.nodes()[1].ref() == 116001);
22 | } else if (way.id() == 116801) {
23 | REQUIRE(way.nodes().size() == 2);
24 | } else if (way.id() == 116802) {
25 | REQUIRE(way.nodes().size() == 4);
26 | } else {
27 | throw std::runtime_error{"Unknown ID"};
28 | }
29 | }
30 |
31 | }; // class TestHandler116
32 |
33 | TEST_CASE("116") {
34 | osmium::io::Reader reader{dirname + "/1/116/data.osm"};
35 |
36 | index_pos_type index_pos;
37 | index_neg_type index_neg;
38 | location_handler_type location_handler{index_pos, index_neg};
39 | location_handler.ignore_errors();
40 |
41 | CheckBasicsHandler check_basics_handler{116, 5, 3, 0};
42 | CheckWKTHandler check_wkt_handler{dirname, 116};
43 | TestHandler116 test_handler;
44 |
45 | osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
46 | }
47 |
48 |
--------------------------------------------------------------------------------
/cmake/FindLZ4.cmake:
--------------------------------------------------------------------------------
1 | find_path(LZ4_INCLUDE_DIR
2 | NAMES lz4.h
3 | DOC "lz4 include directory")
4 | mark_as_advanced(LZ4_INCLUDE_DIR)
5 | find_library(LZ4_LIBRARY
6 | NAMES lz4 liblz4
7 | DOC "lz4 library")
8 | mark_as_advanced(LZ4_LIBRARY)
9 |
10 | if (LZ4_INCLUDE_DIR)
11 | file(STRINGS "${LZ4_INCLUDE_DIR}/lz4.h" _lz4_version_lines
12 | REGEX "#define[ \t]+LZ4_VERSION_(MAJOR|MINOR|RELEASE)")
13 | string(REGEX REPLACE ".*LZ4_VERSION_MAJOR *\([0-9]*\).*" "\\1" _lz4_version_major "${_lz4_version_lines}")
14 | string(REGEX REPLACE ".*LZ4_VERSION_MINOR *\([0-9]*\).*" "\\1" _lz4_version_minor "${_lz4_version_lines}")
15 | string(REGEX REPLACE ".*LZ4_VERSION_RELEASE *\([0-9]*\).*" "\\1" _lz4_version_release "${_lz4_version_lines}")
16 | set(LZ4_VERSION "${_lz4_version_major}.${_lz4_version_minor}.${_lz4_version_release}")
17 | unset(_lz4_version_major)
18 | unset(_lz4_version_minor)
19 | unset(_lz4_version_release)
20 | unset(_lz4_version_lines)
21 | endif ()
22 |
23 | include(FindPackageHandleStandardArgs)
24 | find_package_handle_standard_args(LZ4
25 | REQUIRED_VARS LZ4_LIBRARY LZ4_INCLUDE_DIR
26 | VERSION_VAR LZ4_VERSION)
27 |
28 | if (LZ4_FOUND)
29 | set(LZ4_INCLUDE_DIRS "${LZ4_INCLUDE_DIR}")
30 | set(LZ4_LIBRARIES "${LZ4_LIBRARY}")
31 |
32 | if (NOT TARGET LZ4::LZ4)
33 | add_library(LZ4::LZ4 UNKNOWN IMPORTED)
34 | set_target_properties(LZ4::LZ4 PROPERTIES
35 | IMPORTED_LOCATION "${LZ4_LIBRARY}"
36 | INTERFACE_INCLUDE_DIRECTORIES "${LZ4_INCLUDE_DIR}")
37 | endif ()
38 | endif ()
39 |
--------------------------------------------------------------------------------
/benchmarks/osmium_benchmark_index_map.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | The code in this file is released into the Public Domain.
4 |
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 |
18 | using index_type = osmium::index::map::Map;
19 |
20 | using location_handler_type = osmium::handler::NodeLocationsForWays;
21 |
22 | int main(int argc, char* argv[]) {
23 | if (argc != 3) {
24 | std::cerr << "Usage: " << argv[0] << " OSMFILE FORMAT\n";
25 | return 1;
26 | }
27 |
28 | try {
29 | const std::string input_filename{argv[1]};
30 | const std::string location_store{argv[2]};
31 |
32 | osmium::io::Reader reader{input_filename};
33 |
34 | const auto& map_factory = osmium::index::MapFactory::instance();
35 | std::unique_ptr index = map_factory.create_map(location_store);
36 | location_handler_type location_handler{*index};
37 | location_handler.ignore_errors();
38 |
39 | osmium::apply(reader, location_handler);
40 | reader.close();
41 | } catch (const std::exception& e) {
42 | std::cerr << e.what() << '\n';
43 | return 1;
44 | }
45 |
46 | return 0;
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug-report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Report problems with the software
3 | about: You found a (possible) bug in libosmium
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 |
13 |
14 | ## What version of libosmium are you using?
15 |
16 |
19 |
20 |
21 | ## What operating system and compiler are you using?
22 |
23 |
24 |
25 |
26 | ## Tell us something about your system
27 |
28 |
29 |
30 |
31 | ## What did you do exactly?
32 |
33 |
35 |
36 |
37 | ## What did you expect to happen?
38 |
39 |
40 |
41 |
42 | ## What did happen instead?
43 |
44 |
46 |
47 |
48 | ## What did you do to try analyzing the problem?
49 |
50 |
52 |
53 |
--------------------------------------------------------------------------------
/test/data-tests/run-testdata-multipolygon.cmake:
--------------------------------------------------------------------------------
1 | #-----------------------------------------------------------------------------
2 | #
3 | # Helper script that runs the 'multipolygon' test.
4 | #
5 | #-----------------------------------------------------------------------------
6 |
7 | # Remove files that might be left over from previous run
8 | file(REMOVE multipolygon.db multipolygon-tests.json)
9 |
10 |
11 | #-----------------------------------------------------------------------------
12 | #
13 | # Create multipolygons from test data.
14 | #
15 | #-----------------------------------------------------------------------------
16 | execute_process(
17 | COMMAND ${EXECUTABLE} ${OSM_TESTDATA}/grid/data/all.osm
18 | RESULT_VARIABLE _result
19 | OUTPUT_FILE multipolygon.log
20 | ERROR_FILE multipolygon.log
21 | )
22 |
23 | if(_result)
24 | message(FATAL_ERROR "Error running testdata-multipolygon command")
25 | endif()
26 |
27 |
28 | #-----------------------------------------------------------------------------
29 | #
30 | # Compare created multipolygons with reference data.
31 | #
32 | #-----------------------------------------------------------------------------
33 | execute_process(
34 | COMMAND ${RUBY} ${OSM_TESTDATA}/bin/compare-areas.rb
35 | ${OSM_TESTDATA}/grid/data/tests.json
36 | multipolygon-tests.json
37 | RESULT_VARIABLE _result
38 | )
39 |
40 | if(_result)
41 | message(FATAL_ERROR "Error running compare-areas command")
42 | endif()
43 |
44 |
45 | #-----------------------------------------------------------------------------
46 |
--------------------------------------------------------------------------------
/benchmarks/osmium_benchmark_count.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | The code in this file is released into the Public Domain.
4 |
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | struct CountHandler : public osmium::handler::Handler {
18 |
19 | uint64_t nodes = 0;
20 | uint64_t ways = 0;
21 | uint64_t relations = 0;
22 |
23 | void node(const osmium::Node& /*node*/) {
24 | ++nodes;
25 | }
26 |
27 | void way(const osmium::Way& /*way*/) {
28 | ++ways;
29 | }
30 |
31 | void relation(const osmium::Relation& /*relation*/) {
32 | ++relations;
33 | }
34 |
35 | };
36 |
37 | int main(int argc, char* argv[]) {
38 | if (argc != 2) {
39 | std::cerr << "Usage: " << argv[0] << " OSMFILE\n";
40 | return 1;
41 | }
42 |
43 | try {
44 | const std::string input_filename{argv[1]};
45 |
46 | osmium::io::Reader reader{input_filename};
47 |
48 | CountHandler handler;
49 | osmium::apply(reader, handler);
50 | reader.close();
51 |
52 | std::cout << "Nodes: " << handler.nodes << '\n';
53 | std::cout << "Ways: " << handler.ways << '\n';
54 | std::cout << "Relations: " << handler.relations << '\n';
55 | } catch (const std::exception& e) {
56 | std::cerr << e.what() << '\n';
57 | return 1;
58 | }
59 |
60 | return 0;
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/benchmarks/osmium_benchmark_count_tag.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | The code in this file is released into the Public Domain.
4 |
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | struct CountHandler : public osmium::handler::Handler {
18 |
19 | uint64_t counter = 0;
20 | uint64_t all = 0;
21 |
22 | void node(const osmium::Node& node) {
23 | ++all;
24 | const char* amenity = node.tags().get_value_by_key("amenity");
25 | if (amenity && !strcmp(amenity, "post_box")) {
26 | ++counter;
27 | }
28 | }
29 |
30 | void way(const osmium::Way& /*way*/) {
31 | ++all;
32 | }
33 |
34 | void relation(const osmium::Relation& /*relation*/) {
35 | ++all;
36 | }
37 |
38 | };
39 |
40 | int main(int argc, char* argv[]) {
41 | if (argc != 2) {
42 | std::cerr << "Usage: " << argv[0] << " OSMFILE\n";
43 | return 1;
44 | }
45 |
46 | try {
47 | const std::string input_filename{argv[1]};
48 |
49 | osmium::io::Reader reader{input_filename};
50 |
51 | CountHandler handler;
52 | osmium::apply(reader, handler);
53 | reader.close();
54 |
55 | std::cout << "r_all=" << handler.all << " r_counter=" << handler.counter << '\n';
56 | } catch (const std::exception& e) {
57 | std::cerr << e.what() << '\n';
58 | return 1;
59 | }
60 |
61 | return 0;
62 | }
63 |
64 |
--------------------------------------------------------------------------------
/test/data-tests/testcases/test-114.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | #include "common.hpp"
6 |
7 | class TestHandler114 : public osmium::handler::Handler {
8 |
9 | public:
10 |
11 | TestHandler114() :
12 | osmium::handler::Handler() {
13 | }
14 |
15 | void way(const osmium::Way& way) const {
16 | if (way.id() == 114800) {
17 | REQUIRE(way.version() == 1);
18 | REQUIRE(way.nodes().size() == 2);
19 | REQUIRE_FALSE(way.is_closed());
20 | REQUIRE(way.nodes()[0].ref() == 114000);
21 | REQUIRE(way.nodes()[1].ref() == 114001);
22 | } else if (way.id() == 114801) {
23 | REQUIRE(way.version() == 1);
24 | REQUIRE(way.nodes().size() == 2);
25 | REQUIRE_FALSE(way.is_closed());
26 | REQUIRE(way.nodes()[0].ref() == 114001);
27 | REQUIRE(way.nodes()[1].ref() == 114002);
28 | } else {
29 | throw std::runtime_error{"Unknown ID"};
30 | }
31 | }
32 |
33 | }; // class TestHandler114
34 |
35 | TEST_CASE("114") {
36 | osmium::io::Reader reader{dirname + "/1/114/data.osm"};
37 |
38 | index_pos_type index_pos;
39 | index_neg_type index_neg;
40 | location_handler_type location_handler{index_pos, index_neg};
41 | location_handler.ignore_errors();
42 |
43 | CheckBasicsHandler check_basics_handler{114, 3, 2, 0};
44 | CheckWKTHandler check_wkt_handler{dirname, 114};
45 | TestHandler114 test_handler;
46 |
47 | osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
48 | }
49 |
50 |
--------------------------------------------------------------------------------
/test/data-tests/testcases/test-115.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | #include "common.hpp"
6 |
7 | class TestHandler115 : public osmium::handler::Handler {
8 |
9 | public:
10 |
11 | TestHandler115() :
12 | osmium::handler::Handler() {
13 | }
14 |
15 | void way(const osmium::Way& way) const {
16 | if (way.id() == 115800) {
17 | REQUIRE(way.version() == 1);
18 | REQUIRE(way.nodes().size() == 2);
19 | REQUIRE_FALSE(way.is_closed());
20 | REQUIRE(way.nodes()[0].ref() == 115000);
21 | REQUIRE(way.nodes()[1].ref() == 115001);
22 | } else if (way.id() == 115801) {
23 | REQUIRE(way.version() == 1);
24 | REQUIRE(way.nodes().size() == 2);
25 | REQUIRE_FALSE(way.is_closed());
26 | REQUIRE(way.nodes()[0].ref() == 115002);
27 | REQUIRE(way.nodes()[1].ref() == 115001);
28 | } else {
29 | throw std::runtime_error{"Unknown ID"};
30 | }
31 | }
32 |
33 | }; // class TestHandler115
34 |
35 | TEST_CASE("115") {
36 | osmium::io::Reader reader{dirname + "/1/115/data.osm"};
37 |
38 | index_pos_type index_pos;
39 | index_neg_type index_neg;
40 | location_handler_type location_handler{index_pos, index_neg};
41 | location_handler.ignore_errors();
42 |
43 | CheckBasicsHandler check_basics_handler{115, 3, 2, 0};
44 | CheckWKTHandler check_wkt_handler{dirname, 115};
45 | TestHandler115 test_handler;
46 |
47 | osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
48 | }
49 |
50 |
--------------------------------------------------------------------------------
/benchmarks/README.md:
--------------------------------------------------------------------------------
1 |
2 | # Benchmarks
3 |
4 | Benchmarks check the performance of different parts of Libosmium.
5 |
6 | ## Preparations
7 |
8 | To run the benchmarks first make a directory for the data files somewhere
9 | (outside the repository) and set the `DATA_DIR` environment variable:
10 |
11 | export DATA_DIR=benchmark_data
12 | mkdir $DATA_DIR
13 |
14 | Then copy the OSM files you want to do the benchmarks with into this directory.
15 | You can use the `download_data.sh` script to download a selection of OSM files
16 | in different sizes, but you can use a different selection, too. The benchmarks
17 | will use whatever files you have in the `DATA_DIR` directory.
18 |
19 | The download script will start the data files names with a number in order of
20 | the size of the file from smallest to largest. You can use the same convention
21 | or use a different one. Benchmarks will be run on the files in alphabetical
22 | order.
23 |
24 | The files don't have to be in that directory, you can add soft links from that
25 | directory to the real file locations if that suits you.
26 |
27 | ## Compiling the benchmarks
28 |
29 | To build the benchmarks set the `BUILD_BENCHMARKS` option when configuring with
30 | CMake and run the compilation by calling `make` (or whatever build tool you
31 | are using).
32 |
33 | ## Running the benchmarks
34 |
35 | Go to the build directory and run `benchmarks/run_benchmarks.sh`. You can also
36 | run each benchmark on its own by calling the respective script in the
37 | `benchmarks` directory.
38 |
39 | Results of the benchmarks will be printed to stdout, you might want to redirect
40 | them into a file.
41 |
42 |
--------------------------------------------------------------------------------
/test/examples/t/read/data.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/test/examples/t/read_with_progress/data.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/test/t/util/test_minmax.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include
4 | #include
5 |
6 | #include
7 | #include
8 |
9 | TEST_CASE("min_op numeric") {
10 | osmium::min_op x;
11 | REQUIRE(x() == std::numeric_limits::max());
12 |
13 | x.update(17);
14 | REQUIRE(x() == 17);
15 |
16 | x.update(10);
17 | REQUIRE(x() == 10);
18 |
19 | x.update(22);
20 | REQUIRE(x() == 10);
21 | }
22 |
23 | TEST_CASE("max_op numeric") {
24 | osmium::max_op x;
25 | REQUIRE(x() == 0);
26 |
27 | x.update(17);
28 | REQUIRE(x() == 17);
29 |
30 | x.update(10);
31 | REQUIRE(x() == 17);
32 |
33 | x.update(22);
34 | REQUIRE(x() == 22);
35 | }
36 |
37 | TEST_CASE("min_op timestamp") {
38 | osmium::min_op x;
39 |
40 | x.update(osmium::Timestamp("2010-01-01T00:00:00Z"));
41 | REQUIRE(x().to_iso() == "2010-01-01T00:00:00Z");
42 |
43 | x.update(osmium::Timestamp("2015-01-01T00:00:00Z"));
44 | REQUIRE(x().to_iso() == "2010-01-01T00:00:00Z");
45 |
46 | x.update(osmium::Timestamp("2000-01-01T00:00:00Z"));
47 | REQUIRE(x().to_iso() == "2000-01-01T00:00:00Z");
48 | }
49 |
50 | TEST_CASE("max_op timestamp") {
51 | osmium::max_op x;
52 |
53 | x.update(osmium::Timestamp("2010-01-01T00:00:00Z"));
54 | REQUIRE(x().to_iso() == "2010-01-01T00:00:00Z");
55 |
56 | x.update(osmium::Timestamp("2015-01-01T00:00:00Z"));
57 | REQUIRE(x().to_iso() == "2015-01-01T00:00:00Z");
58 |
59 | x.update(osmium::Timestamp("2000-01-01T00:00:00Z"));
60 | REQUIRE(x().to_iso() == "2015-01-01T00:00:00Z");
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/test/t/io/data-n5w1r3.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/examples/README.md:
--------------------------------------------------------------------------------
1 |
2 | # Osmium example programs
3 |
4 | The programs in this directory are intended as examples for developers. They
5 | contain extensive comments explaining what's going on. Note that the examples
6 | only cover a small part of what Osmium can do, you should also read the manuals
7 | and API documentation.
8 |
9 | All programs can be run without arguments and they will tell you how to use
10 | them.
11 |
12 | ## Very simple examples
13 |
14 | * [`osmium_read`](./osmium_read.cpp)
15 | * [`osmium_count`](./osmium_count.cpp)
16 | * [`osmium_debug`](./osmium_debug.cpp)
17 | * [`osmium_tiles`](./osmium_tiles.cpp)
18 |
19 | ## Still reasonably simple examples
20 |
21 | * [`osmium_amenity_list`](./osmium_amenity_list.cpp)
22 | * [`osmium_read_with_progress`](./osmium_read_with_progress.cpp)
23 | * [`osmium_filter_discussions`](./osmium_filter_discussions.cpp)
24 | * [`osmium_convert`](./osmium_convert.cpp)
25 | * [`osmium_pub_names`](./osmium_pub_names.cpp)
26 | * [`osmium_road_length`](./osmium_road_length.cpp)
27 |
28 | ## More advanced examples
29 |
30 | * [`osmium_area_test`](./osmium_area_test.cpp)
31 | * [`osmium_create_pois`](./osmium_create_pois.cpp)
32 | * [`osmium_tags_filter`](./osmium_tags_filter.cpp)
33 |
34 | ## Even more advanced examples
35 |
36 | * [`osmium_change_tags`](./osmium_change_tags.cpp)
37 | * [`osmium_location_cache_create`](./osmium_location_cache_create.cpp)
38 | * [`osmium_location_cache_use`](./osmium_location_cache_use.cpp)
39 | * [`osmium_dump_internal`](./osmium_dump_internal.cpp)
40 | * [`osmium_index_lookup`](./osmium_index_lookup.cpp)
41 |
42 | ## License
43 |
44 | The code in these example files is released into the Public Domain. Feel free
45 | to copy the code and build on it.
46 |
47 |
--------------------------------------------------------------------------------
/test/t/geom/test_mercator.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include
4 |
5 | TEST_CASE("Mercator projection") {
6 | const osmium::geom::MercatorProjection projection;
7 | REQUIRE(3857 == projection.epsg());
8 | REQUIRE("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs" == projection.proj_string());
9 | }
10 |
11 | TEST_CASE("Low level mercator functions") {
12 | const osmium::geom::Coordinates c1{17.839, -3.249};
13 | const osmium::geom::Coordinates r1 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c1));
14 | REQUIRE(r1.x == Approx(c1.x).epsilon(0.000001));
15 | REQUIRE(r1.y == Approx(c1.y).epsilon(0.000001));
16 |
17 | const osmium::geom::Coordinates c2{-89.2, 15.915};
18 | const osmium::geom::Coordinates r2 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c2));
19 | REQUIRE(r2.x == Approx(c2.x).epsilon(0.000001));
20 | REQUIRE(r2.y == Approx(c2.y).epsilon(0.000001));
21 |
22 | const osmium::geom::Coordinates c3{180.0, 85.0};
23 | const osmium::geom::Coordinates r3 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c3));
24 | REQUIRE(r3.x == Approx(c3.x).epsilon(0.000001));
25 | REQUIRE(r3.y == Approx(c3.y).epsilon(0.000001));
26 | }
27 |
28 | TEST_CASE("Mercator bounds") {
29 | const osmium::Location mmax{180.0, osmium::geom::MERCATOR_MAX_LAT};
30 | const osmium::geom::Coordinates c = osmium::geom::lonlat_to_mercator(mmax);
31 | REQUIRE(c.x == Approx(c.y).epsilon(0.001));
32 | REQUIRE(osmium::geom::detail::y_to_lat(osmium::geom::detail::lon_to_x(180.0)) == Approx(osmium::geom::MERCATOR_MAX_LAT).epsilon(0.0000001));
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/test/t/thread/test_util.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | TEST_CASE("check_for_exception") {
11 | std::promise p;
12 | auto f = p.get_future();
13 |
14 | SECTION("not ready") {
15 | osmium::thread::check_for_exception(f);
16 | }
17 | SECTION("ready") {
18 | p.set_value(3);
19 | osmium::thread::check_for_exception(f);
20 | }
21 | SECTION("no shared state") {
22 | p.set_value(3);
23 | REQUIRE(f.get() == 3);
24 | osmium::thread::check_for_exception(f);
25 | }
26 | }
27 |
28 | TEST_CASE("check_for_exception with exception") {
29 | std::promise p;
30 | auto f = p.get_future();
31 |
32 | try {
33 | throw std::runtime_error{"TEST"};
34 | } catch (...) {
35 | p.set_exception(std::current_exception());
36 | }
37 |
38 | REQUIRE_THROWS_AS(osmium::thread::check_for_exception(f), std::runtime_error);
39 | }
40 |
41 | static_assert(std::is_nothrow_move_constructible::value, "thread_handler must have noexcept move constructor");
42 |
43 | TEST_CASE("empty thread_handler") {
44 | const osmium::thread::thread_handler th;
45 | }
46 |
47 | namespace {
48 |
49 | int foo; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
50 |
51 | void test_func(int value) {
52 | foo = value;
53 | }
54 |
55 | } // anonymous namespace
56 |
57 | TEST_CASE("valid thread_handler") {
58 | foo = 22;
59 | test_func(17);
60 | REQUIRE(foo == 17);
61 | {
62 | const osmium::thread::thread_handler th{test_func, 5};
63 | }
64 | REQUIRE(foo == 5);
65 | }
66 |
67 |
--------------------------------------------------------------------------------
/examples/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | #-----------------------------------------------------------------------------
2 | #
3 | # CMake Config
4 | #
5 | # Libosmium examples
6 | #
7 | #-----------------------------------------------------------------------------
8 |
9 | message(STATUS "Configuring examples")
10 |
11 | set(EXAMPLES
12 | amenity_list
13 | area_test
14 | change_tags
15 | convert
16 | count
17 | create_pois
18 | debug
19 | dump_internal
20 | filter_discussions
21 | index_lookup
22 | location_cache_create
23 | location_cache_use
24 | pub_names
25 | read
26 | read_with_progress
27 | road_length
28 | tags_filter
29 | tiles
30 | CACHE STRING "Example programs"
31 | )
32 |
33 |
34 | #-----------------------------------------------------------------------------
35 | #
36 | # Configure examples
37 | #
38 | #-----------------------------------------------------------------------------
39 | message(STATUS "Configuring examples - Building these examples:")
40 | foreach(example ${EXAMPLES})
41 | message(STATUS " - osmium_${example}")
42 | add_executable(osmium_${example} "osmium_${example}.cpp")
43 | set_pthread_on_target(osmium_${example})
44 | target_link_libraries(osmium_${example} ${OSMIUM_IO_LIBRARIES} ${EXAMPLE_LIBS_${example}})
45 | add_test(NAME examples_usage_${example} COMMAND osmium_${example})
46 | set_tests_properties(examples_usage_${example} PROPERTIES
47 | PASS_REGULAR_EXPRESSION "^Usage: "
48 | )
49 | endforeach()
50 |
51 |
52 | #-----------------------------------------------------------------------------
53 | message(STATUS "Configuring examples - done")
54 |
55 |
56 | #-----------------------------------------------------------------------------
57 |
--------------------------------------------------------------------------------
/test/examples/t/dump_internal/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_test(NAME examples_dump_internal
3 | COMMAND osmium_dump_internal ${CMAKE_CURRENT_SOURCE_DIR}/data.osm ${CMAKE_CURRENT_BINARY_DIR}/out)
4 |
5 |
6 | add_test(NAME examples_dump_internal_index_nodes
7 | COMMAND osmium_index_lookup --list=${CMAKE_CURRENT_BINARY_DIR}/out/nodes.idx --type=offset --dump)
8 |
9 | set_tests_properties(examples_dump_internal_index_nodes PROPERTIES
10 | DEPENDS examples_dump_internal
11 | PASS_REGULAR_EXPRESSION "^701000 .*\n701001 .*\n")
12 |
13 |
14 | add_test(NAME examples_dump_internal_index_ways
15 | COMMAND osmium_index_lookup --list=${CMAKE_CURRENT_BINARY_DIR}/out/ways.idx --type=offset --dump)
16 |
17 | set_tests_properties(examples_dump_internal_index_ways PROPERTIES
18 | DEPENDS examples_dump_internal
19 | PASS_REGULAR_EXPRESSION "^701800 .*\n701801 .*\n")
20 |
21 |
22 | add_test(NAME examples_dump_internal_map_node2way_dump
23 | COMMAND osmium_index_lookup --list=${CMAKE_CURRENT_BINARY_DIR}/out/node2way.map --type=id --dump)
24 |
25 | set_tests_properties(examples_dump_internal_map_node2way_dump PROPERTIES
26 | DEPENDS examples_dump_internal
27 | PASS_REGULAR_EXPRESSION "^701000 701800\n701000 701801\n701001 701800\n")
28 |
29 |
30 | add_test(NAME examples_dump_internal_map_node2way_search
31 | COMMAND osmium_index_lookup --list=${CMAKE_CURRENT_BINARY_DIR}/out/node2way.map --type=id --search=701002)
32 |
33 | set_tests_properties(examples_dump_internal_map_node2way_search PROPERTIES
34 | DEPENDS examples_dump_internal
35 | PASS_REGULAR_EXPRESSION "^701002 701800\n701002 701801\n$")
36 |
37 |
--------------------------------------------------------------------------------
/test/t/memory/test_item.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include
4 |
5 | TEST_CASE("padded length") {
6 | REQUIRE(osmium::memory::padded_length(0) == 0);
7 | REQUIRE(osmium::memory::padded_length(1) == 8);
8 | REQUIRE(osmium::memory::padded_length(2) == 8);
9 | REQUIRE(osmium::memory::padded_length(7) == 8);
10 | REQUIRE(osmium::memory::padded_length(8) == 8);
11 | REQUIRE(osmium::memory::padded_length(9) == 16);
12 |
13 | REQUIRE(osmium::memory::padded_length(2147483647UL) == 2147483648UL);
14 | REQUIRE(osmium::memory::padded_length(2147483648UL) == 2147483648UL);
15 | REQUIRE(osmium::memory::padded_length(2147483650UL) == 2147483656UL);
16 |
17 | // The following checks only make sense on a 64 bit system (with
18 | // sizeof(size_t) == 8), because the numbers are too large for 32 bit.
19 | // The casts to size_t do nothing on a 64 bit system, on a 32 bit system
20 | // they bring the numbers into the right range and everything still works.
21 | REQUIRE(osmium::memory::padded_length(static_cast(4294967295ULL)) == static_cast(4294967296ULL));
22 | REQUIRE(osmium::memory::padded_length(static_cast(4294967296ULL)) == static_cast(4294967296ULL));
23 | REQUIRE(osmium::memory::padded_length(static_cast(4294967297ULL)) == static_cast(4294967304ULL));
24 |
25 | REQUIRE(osmium::memory::padded_length(static_cast(7999999999ULL)) == static_cast(8000000000ULL));
26 | REQUIRE(osmium::memory::padded_length(static_cast(8000000000ULL)) == static_cast(8000000000ULL));
27 | REQUIRE(osmium::memory::padded_length(static_cast(8000000001ULL)) == static_cast(8000000008ULL));
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/test/t/geom/test_projection.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include
4 | #include
5 |
6 | TEST_CASE("Indentity Projection") {
7 | const osmium::geom::IdentityProjection projection;
8 | REQUIRE(4326 == projection.epsg());
9 | REQUIRE("+proj=longlat +datum=WGS84 +no_defs" == projection.proj_string());
10 | }
11 |
12 | TEST_CASE("MercatorProjection: Zero coordinates") {
13 | const osmium::geom::MercatorProjection projection;
14 | const osmium::Location loc{0.0, 0.0};
15 | const osmium::geom::Coordinates c{0.0, 0.0};
16 | REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
17 | REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
18 | }
19 |
20 | TEST_CASE("MercatorProjection: Max longitude") {
21 | const osmium::geom::MercatorProjection projection;
22 | const osmium::Location loc{180.0, 0.0};
23 | const osmium::geom::Coordinates c{20037508.34, 0.0};
24 | REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
25 | REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
26 | }
27 |
28 | TEST_CASE("MercatorProjection: Min longitude") {
29 | const osmium::geom::MercatorProjection projection;
30 | const osmium::Location loc{-180.0, 0.0};
31 | const osmium::geom::Coordinates c{-20037508.34, 0.0};
32 | REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
33 | REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
34 | }
35 |
36 | TEST_CASE("MercatorProjection: Max latitude") {
37 | const osmium::geom::MercatorProjection projection;
38 | const osmium::Location loc{0.0, 85.0511288};
39 | const osmium::geom::Coordinates c{0.0, 20037508.34};
40 | REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
41 | REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
42 | }
43 |
44 |
--------------------------------------------------------------------------------
/test/examples/t/debug/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_test(NAME examples_debug_all
3 | COMMAND osmium_debug ${CMAKE_CURRENT_SOURCE_DIR}/data.osm)
4 |
5 | set_tests_properties(examples_debug_all PROPERTIES
6 | PASS_REGULAR_EXPRESSION " id=1\n.* id=2\n.* id=10\n.* id=20\n"
7 | )
8 |
9 |
10 | add_test(NAME examples_debug_nodes
11 | COMMAND osmium_debug ${CMAKE_CURRENT_SOURCE_DIR}/data.osm n)
12 |
13 | set_tests_properties(examples_debug_nodes PROPERTIES
14 | PASS_REGULAR_EXPRESSION "id=1\n.* id=2\n"
15 | )
16 |
17 | set_tests_properties(examples_debug_nodes PROPERTIES
18 | FAIL_REGULAR_EXPRESSION "id=10\n"
19 | )
20 |
21 |
22 | add_test(NAME examples_debug_ways
23 | COMMAND osmium_debug ${CMAKE_CURRENT_SOURCE_DIR}/data.osm w)
24 |
25 | set_tests_properties(examples_debug_ways PROPERTIES
26 | PASS_REGULAR_EXPRESSION " id=10\n"
27 | )
28 |
29 | set_tests_properties(examples_debug_ways PROPERTIES
30 | FAIL_REGULAR_EXPRESSION "id=20\n"
31 | )
32 |
33 |
34 | add_test(NAME examples_debug_relations
35 | COMMAND osmium_debug ${CMAKE_CURRENT_SOURCE_DIR}/data.osm r)
36 |
37 | set_tests_properties(examples_debug_relations PROPERTIES
38 | PASS_REGULAR_EXPRESSION " id=20\n"
39 | )
40 |
41 | set_tests_properties(examples_debug_relations PROPERTIES
42 | FAIL_REGULAR_EXPRESSION "id=10\n"
43 | )
44 |
45 | add_test(NAME examples_debug_changesets
46 | COMMAND osmium_debug ${CMAKE_CURRENT_SOURCE_DIR}/changesets.osm c)
47 |
48 | set_tests_properties(examples_debug_changesets PROPERTIES
49 | PASS_REGULAR_EXPRESSION " id=15449962\n"
50 | )
51 |
52 | set_tests_properties(examples_debug_changesets PROPERTIES
53 | FAIL_REGULAR_EXPRESSION "id=10\n"
54 | )
55 |
56 |
--------------------------------------------------------------------------------
/include/osmium/io/ids_output.hpp:
--------------------------------------------------------------------------------
1 | #ifndef OSMIUM_IO_IDS_OUTPUT_HPP
2 | #define OSMIUM_IO_IDS_OUTPUT_HPP
3 |
4 | /*
5 |
6 | This file is part of Osmium (https://osmcode.org/libosmium).
7 |
8 | Copyright 2013-2025 Jochen Topf and others (see README).
9 |
10 | Boost Software License - Version 1.0 - August 17th, 2003
11 |
12 | Permission is hereby granted, free of charge, to any person or organization
13 | obtaining a copy of the software and accompanying documentation covered by
14 | this license (the "Software") to use, reproduce, display, distribute,
15 | execute, and transmit the Software, and to prepare derivative works of the
16 | Software, and to permit third-parties to whom the Software is furnished to
17 | do so, all subject to the following:
18 |
19 | The copyright notices in the Software and this entire statement, including
20 | the above license grant, this restriction and the following disclaimer,
21 | must be included in all copies of the Software, in whole or in part, and
22 | all derivative works of the Software, unless such copies or derivative
23 | works are solely in the form of machine-executable object code generated by
24 | a source language processor.
25 |
26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 | DEALINGS IN THE SOFTWARE.
33 |
34 | */
35 |
36 | #include // IWYU pragma: export
37 | #include // IWYU pragma: export
38 |
39 | #endif // OSMIUM_IO_IDS_OUTPUT_HPP
40 |
--------------------------------------------------------------------------------
/include/osmium/io/opl_output.hpp:
--------------------------------------------------------------------------------
1 | #ifndef OSMIUM_IO_OPL_OUTPUT_HPP
2 | #define OSMIUM_IO_OPL_OUTPUT_HPP
3 |
4 | /*
5 |
6 | This file is part of Osmium (https://osmcode.org/libosmium).
7 |
8 | Copyright 2013-2025 Jochen Topf and others (see README).
9 |
10 | Boost Software License - Version 1.0 - August 17th, 2003
11 |
12 | Permission is hereby granted, free of charge, to any person or organization
13 | obtaining a copy of the software and accompanying documentation covered by
14 | this license (the "Software") to use, reproduce, display, distribute,
15 | execute, and transmit the Software, and to prepare derivative works of the
16 | Software, and to permit third-parties to whom the Software is furnished to
17 | do so, all subject to the following:
18 |
19 | The copyright notices in the Software and this entire statement, including
20 | the above license grant, this restriction and the following disclaimer,
21 | must be included in all copies of the Software, in whole or in part, and
22 | all derivative works of the Software, unless such copies or derivative
23 | works are solely in the form of machine-executable object code generated by
24 | a source language processor.
25 |
26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 | DEALINGS IN THE SOFTWARE.
33 |
34 | */
35 |
36 | #include // IWYU pragma: export
37 | #include // IWYU pragma: export
38 |
39 | #endif // OSMIUM_IO_OPL_OUTPUT_HPP
40 |
--------------------------------------------------------------------------------
/include/osmium/io/debug_output.hpp:
--------------------------------------------------------------------------------
1 | #ifndef OSMIUM_IO_DEBUG_OUTPUT_HPP
2 | #define OSMIUM_IO_DEBUG_OUTPUT_HPP
3 |
4 | /*
5 |
6 | This file is part of Osmium (https://osmcode.org/libosmium).
7 |
8 | Copyright 2013-2025 Jochen Topf and others (see README).
9 |
10 | Boost Software License - Version 1.0 - August 17th, 2003
11 |
12 | Permission is hereby granted, free of charge, to any person or organization
13 | obtaining a copy of the software and accompanying documentation covered by
14 | this license (the "Software") to use, reproduce, display, distribute,
15 | execute, and transmit the Software, and to prepare derivative works of the
16 | Software, and to permit third-parties to whom the Software is furnished to
17 | do so, all subject to the following:
18 |
19 | The copyright notices in the Software and this entire statement, including
20 | the above license grant, this restriction and the following disclaimer,
21 | must be included in all copies of the Software, in whole or in part, and
22 | all derivative works of the Software, unless such copies or derivative
23 | works are solely in the form of machine-executable object code generated by
24 | a source language processor.
25 |
26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 | DEALINGS IN THE SOFTWARE.
33 |
34 | */
35 |
36 | #include // IWYU pragma: export
37 | #include // IWYU pragma: export
38 |
39 | #endif // OSMIUM_IO_DEBUG_OUTPUT_HPP
40 |
--------------------------------------------------------------------------------
/test/t/osm/test_crc.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include "test_crc.hpp"
4 |
5 | #include
6 |
7 | TEST_CASE("CRC of bool") {
8 | osmium::CRC crc32;
9 |
10 | crc32.update_bool(true);
11 | crc32.update_bool(false);
12 |
13 | REQUIRE(crc32().checksum() == 0x58c223be);
14 | }
15 |
16 | TEST_CASE("CRC of char") {
17 | osmium::CRC crc32;
18 |
19 | crc32.update_int8('x');
20 | crc32.update_int8('y');
21 |
22 | REQUIRE(crc32().checksum() == 0x8fe62899);
23 | }
24 |
25 | TEST_CASE("CRC of int16") {
26 | osmium::CRC crc32;
27 |
28 | crc32.update_int16(0x0123U);
29 | crc32.update_int16(0x1234U);
30 |
31 | REQUIRE(crc32().checksum() == 0xda923744);
32 | }
33 |
34 | TEST_CASE("CRC of int32") {
35 | osmium::CRC crc32;
36 |
37 | crc32.update_int32(0x01234567UL);
38 | crc32.update_int32(0x12345678UL);
39 |
40 | REQUIRE(crc32().checksum() == 0x9b4e2af3);
41 | }
42 |
43 | TEST_CASE("CRC of int64") {
44 | osmium::CRC crc32;
45 |
46 | crc32.update_int64(0x0123456789abcdefULL);
47 | crc32.update_int64(0x123456789abcdef0ULL);
48 |
49 | REQUIRE(crc32().checksum() == 0x6d8b7267);
50 | }
51 |
52 | TEST_CASE("CRC of string") {
53 | osmium::CRC crc32;
54 |
55 | const char* str = "foobar";
56 | crc32.update_string(str);
57 |
58 | REQUIRE(crc32().checksum() == 0x9ef61f95);
59 | }
60 |
61 | TEST_CASE("CRC of Timestamp") {
62 | osmium::CRC crc32;
63 |
64 | const osmium::Timestamp t{"2015-07-12T13:10:46Z"};
65 | crc32.update(t);
66 |
67 | REQUIRE(crc32().checksum() == 0x58a29d7);
68 | }
69 |
70 | TEST_CASE("CRC of Location") {
71 | osmium::CRC crc32;
72 |
73 | const osmium::Location loc{3.46, 2.001};
74 | crc32.update(loc);
75 |
76 | REQUIRE(crc32().checksum() == 0xddee042c);
77 | }
78 |
79 |
--------------------------------------------------------------------------------
/test/examples/t/location_cache/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_test(NAME examples_location_cache_create
3 | COMMAND osmium_location_cache_create ${CMAKE_CURRENT_SOURCE_DIR}/data.osm ${CMAKE_CURRENT_BINARY_DIR}/locations.idx)
4 |
5 |
6 | # Fails with message if index file doesn't exist
7 | add_test(NAME examples_location_cache_no_file
8 | COMMAND osmium_location_cache_use ${CMAKE_CURRENT_SOURCE_DIR}/way.osm ${CMAKE_CURRENT_BINARY_DIR}/file_does_not_exist)
9 |
10 | set_tests_properties(examples_location_cache_no_file PROPERTIES
11 | PASS_REGULAR_EXPRESSION "Can not open location cache file")
12 |
13 |
14 | add_test(NAME examples_location_cache_use
15 | COMMAND osmium_location_cache_use ${CMAKE_CURRENT_SOURCE_DIR}/way.osm ${CMAKE_CURRENT_BINARY_DIR}/locations.idx)
16 |
17 | set_tests_properties(examples_location_cache_use PROPERTIES
18 | DEPENDS examples_location_cache_create
19 | PASS_REGULAR_EXPRESSION "^way 20\n node 10 \\(7.11,1.01\\)\n node 11 \\(7.11,1.04\\)\n node 12 \\(7.14,1.04\\)\n$")
20 |
21 |
22 | add_test(NAME examples_location_cache_dump
23 | COMMAND osmium_index_lookup --list=${CMAKE_CURRENT_BINARY_DIR}/locations.idx --type=location --dump)
24 |
25 | set_tests_properties(examples_location_cache_dump PROPERTIES
26 | DEPENDS examples_location_cache_create
27 | PASS_REGULAR_EXPRESSION "^10 \\(7.11,1.01\\)\n11 \\(7.11,1.04\\)\n12 \\(7.14,1.04\\)\n13 \\(7.14,1.01\\)\n$")
28 |
29 |
30 | add_test(NAME examples_location_cache_search
31 | COMMAND osmium_index_lookup --list=${CMAKE_CURRENT_BINARY_DIR}/locations.idx --type=location --search=12)
32 |
33 | set_tests_properties(examples_location_cache_search PROPERTIES
34 | DEPENDS examples_location_cache_create
35 | PASS_REGULAR_EXPRESSION "^12 \\(7.14,1.04\\)\n$")
36 |
37 |
--------------------------------------------------------------------------------
/benchmarks/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | #-----------------------------------------------------------------------------
2 | #
3 | # CMake Config
4 | #
5 | # Libosmium benchmarks
6 | #
7 | #-----------------------------------------------------------------------------
8 |
9 | message(STATUS "Configuring benchmarks")
10 |
11 | set(BENCHMARKS
12 | count
13 | count_tag
14 | index_map
15 | mercator
16 | static_vs_dynamic_index
17 | write_pbf
18 | CACHE STRING "Benchmark programs"
19 | )
20 |
21 |
22 | #-----------------------------------------------------------------------------
23 | #
24 | # Configure benchmarks
25 | #
26 | #-----------------------------------------------------------------------------
27 |
28 | message(STATUS "Configuring benchmarks - Building these benchmarks:")
29 | foreach(benchmark ${BENCHMARKS})
30 | message(STATUS " - osmium_benchmark_${benchmark}")
31 | add_executable(osmium_benchmark_${benchmark}
32 | "osmium_benchmark_${benchmark}.cpp")
33 | target_link_libraries(osmium_benchmark_${benchmark}
34 | ${OSMIUM_IO_LIBRARIES}
35 | ${BENCHMARK_LIBS_${benchmark}})
36 | set_pthread_on_target(osmium_benchmark_${benchmark})
37 | configure_file(run_benchmark_${benchmark}.sh
38 | ${CMAKE_CURRENT_BINARY_DIR}/run_benchmark_${benchmark}.sh
39 | @ONLY)
40 | endforeach()
41 |
42 | string(TOUPPER "${CMAKE_BUILD_TYPE}" _cmake_build_type)
43 | set(_cxx_flags "${CMAKE_CXX_FLAGS_${_cmake_build_type}}")
44 | foreach(file setup run_benchmarks)
45 | configure_file(${file}.sh ${CMAKE_CURRENT_BINARY_DIR}/${file}.sh @ONLY)
46 | endforeach()
47 |
48 |
49 | #-----------------------------------------------------------------------------
50 | message(STATUS "Configuring benchmarks - done")
51 |
52 |
53 | #-----------------------------------------------------------------------------
54 |
--------------------------------------------------------------------------------
/test/t/geom/wnl_helper.hpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include
5 |
6 | using namespace osmium::builder::attr;
7 |
8 | inline const osmium::WayNodeList& create_test_wnl_okay(osmium::memory::Buffer& buffer) {
9 | const auto pos = osmium::builder::add_way_node_list(buffer, _nodes({
10 | {1, {3.2, 4.2}},
11 | {3, {3.5, 4.7}},
12 | {4, {3.5, 4.7}},
13 | {2, {3.6, 4.9}}
14 | }));
15 |
16 | return buffer.get(pos);
17 | }
18 |
19 | inline const osmium::WayNodeList& create_test_wnl_closed(osmium::memory::Buffer& buffer) {
20 | const auto pos = osmium::builder::add_way_node_list(buffer, _nodes({
21 | {1, {3.0, 3.0}},
22 | {2, {4.1, 4.1}},
23 | {3, {4.1, 4.1}},
24 | {4, {3.6, 4.1}},
25 | {5, {3.1, 3.5}},
26 | {6, {3.0, 3.0}},
27 | }));
28 |
29 | return buffer.get(pos);
30 | }
31 |
32 | inline const osmium::WayNodeList& create_test_wnl_empty(osmium::memory::Buffer& buffer) {
33 | {
34 | osmium::builder::WayNodeListBuilder wnl_builder(buffer);
35 | }
36 |
37 | return buffer.get(buffer.commit());
38 | }
39 |
40 | inline const osmium::WayNodeList& create_test_wnl_same_location(osmium::memory::Buffer& buffer) {
41 | const auto pos = osmium::builder::add_way_node_list(buffer, _nodes({
42 | {1, {3.5, 4.7}},
43 | {2, {3.5, 4.7}}
44 | }));
45 |
46 | return buffer.get(pos);
47 | }
48 |
49 | inline const osmium::WayNodeList& create_test_wnl_undefined_location(osmium::memory::Buffer& buffer) {
50 | const auto pos = osmium::builder::add_way_node_list(buffer, _nodes({
51 | {1, {3.5, 4.7}},
52 | {2, osmium::Location()}
53 | }));
54 |
55 | return buffer.get(pos);
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/include/osmium/io/overwrite.hpp:
--------------------------------------------------------------------------------
1 | #ifndef OSMIUM_IO_OVERWRITE_HPP
2 | #define OSMIUM_IO_OVERWRITE_HPP
3 |
4 | /*
5 |
6 | This file is part of Osmium (https://osmcode.org/libosmium).
7 |
8 | Copyright 2013-2025 Jochen Topf and others (see README).
9 |
10 | Boost Software License - Version 1.0 - August 17th, 2003
11 |
12 | Permission is hereby granted, free of charge, to any person or organization
13 | obtaining a copy of the software and accompanying documentation covered by
14 | this license (the "Software") to use, reproduce, display, distribute,
15 | execute, and transmit the Software, and to prepare derivative works of the
16 | Software, and to permit third-parties to whom the Software is furnished to
17 | do so, all subject to the following:
18 |
19 | The copyright notices in the Software and this entire statement, including
20 | the above license grant, this restriction and the following disclaimer,
21 | must be included in all copies of the Software, in whole or in part, and
22 | all derivative works of the Software, unless such copies or derivative
23 | works are solely in the form of machine-executable object code generated by
24 | a source language processor.
25 |
26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 | DEALINGS IN THE SOFTWARE.
33 |
34 | */
35 |
36 | #pragma message("Including overwrite.hpp is deprecated, #include instead.")
37 | #include // IWYU pragma: keep
38 |
39 | #endif // OSMIUM_IO_OVERWRITE_HPP
40 |
--------------------------------------------------------------------------------
/test/t/relations/data.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/test/t/util/test_file.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include "utils.hpp"
4 |
5 | #include
6 | #include
7 |
8 | #include
9 | #include
10 |
11 | TEST_CASE("file_size(int) and file_offset() of known file") {
12 | const std::string file_name{with_data_dir("t/util/known_file_size")};
13 | const int fd = osmium::io::detail::open_for_reading(file_name);
14 | REQUIRE(fd > 0);
15 | REQUIRE(osmium::file_size(fd) == 22);
16 | REQUIRE(osmium::file_offset(fd) == 0);
17 | REQUIRE_FALSE(osmium::isatty(fd));
18 | }
19 |
20 | TEST_CASE("file_size(std::string) of known file") {
21 | const std::string file_name{with_data_dir("t/util/known_file_size")};
22 | REQUIRE(osmium::file_size(file_name) == 22);
23 | }
24 |
25 | TEST_CASE("file_size(const char*) of known file") {
26 | const std::string file_name{with_data_dir("t/util/known_file_size")};
27 | REQUIRE(osmium::file_size(file_name.c_str()) == 22);
28 | }
29 |
30 | TEST_CASE("file_size() with illegal fd should throw") {
31 | REQUIRE_THROWS_AS(osmium::file_size(999), std::system_error);
32 | }
33 |
34 | TEST_CASE("file_size() with unused fd should throw") {
35 | // its unlikely that fd 1000 is open...
36 | REQUIRE_THROWS_AS(osmium::file_size(1000), std::system_error);
37 | }
38 |
39 | TEST_CASE("file_size() of unknown file should throw") {
40 | REQUIRE_THROWS_AS(osmium::file_size("unknown file"), std::system_error);
41 | }
42 |
43 | TEST_CASE("resize_file() with illegal fd should throw") {
44 | REQUIRE_THROWS_AS(osmium::resize_file(-1, 10), std::system_error);
45 | }
46 |
47 | TEST_CASE("resize_file() with unused fd should throw") {
48 | // its unlikely that fd 1000 is open...
49 | REQUIRE_THROWS_AS(osmium::resize_file(1000, 10), std::system_error);
50 | }
51 |
52 | TEST_CASE("get_pagesize()") {
53 | REQUIRE(osmium::get_pagesize() > 0);
54 | }
55 |
56 |
--------------------------------------------------------------------------------
/test/examples/t/area_test/data.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/test/examples/t/convert/data.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/test/examples/t/dump_internal/data.osm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/test/t/tags/test_operators.cpp:
--------------------------------------------------------------------------------
1 | #include "catch.hpp"
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | #include
8 |
9 | TEST_CASE("Equality comparison of tags") {
10 | osmium::memory::Buffer buffer1{10240};
11 | {
12 | osmium::builder::TagListBuilder tl_builder{buffer1};
13 | tl_builder.add_tag("highway", "primary");
14 | tl_builder.add_tag("name", "Main Street");
15 | tl_builder.add_tag("source", "GPS");
16 | }
17 | buffer1.commit();
18 |
19 | osmium::memory::Buffer buffer2{10240};
20 | {
21 | osmium::builder::TagListBuilder tl_builder{buffer2};
22 | tl_builder.add_tag("highway", "primary");
23 | }
24 | buffer2.commit();
25 |
26 | const auto& tl1 = buffer1.get(0);
27 | const auto& tl2 = buffer2.get(0);
28 |
29 | auto tagit1 = tl1.begin();
30 | auto tagit2 = tl2.begin();
31 | REQUIRE(*tagit1 == *tagit2);
32 | ++tagit1;
33 | REQUIRE_FALSE(*tagit1 == *tagit2);
34 | }
35 |
36 | TEST_CASE("Ordering of tags") {
37 | osmium::memory::Buffer buffer{10240};
38 | {
39 | osmium::builder::TagListBuilder tl_builder{buffer};
40 | tl_builder.add_tag("highway", "residential");
41 | tl_builder.add_tag("highway", "primary");
42 | tl_builder.add_tag("name", "Main Street");
43 | tl_builder.add_tag("amenity", "post_box");
44 | }
45 | buffer.commit();
46 |
47 | const auto& tag_list = buffer.get(0);
48 | const osmium::Tag& t1 = *(tag_list.begin());
49 | const osmium::Tag& t2 = *(std::next(tag_list.begin(), 1));
50 | const osmium::Tag& t3 = *(std::next(tag_list.begin(), 2));
51 | const osmium::Tag& t4 = *(std::next(tag_list.begin(), 3));
52 |
53 | REQUIRE(t2 < t1);
54 | REQUIRE(t1 < t3);
55 | REQUIRE(t2 < t3);
56 | REQUIRE(t4 < t1);
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/include/osmium/io/o5m_input.hpp:
--------------------------------------------------------------------------------
1 | #ifndef OSMIUM_IO_O5M_INPUT_HPP
2 | #define OSMIUM_IO_O5M_INPUT_HPP
3 |
4 | /*
5 |
6 | This file is part of Osmium (https://osmcode.org/libosmium).
7 |
8 | Copyright 2013-2025 Jochen Topf and others (see README).
9 |
10 | Boost Software License - Version 1.0 - August 17th, 2003
11 |
12 | Permission is hereby granted, free of charge, to any person or organization
13 | obtaining a copy of the software and accompanying documentation covered by
14 | this license (the "Software") to use, reproduce, display, distribute,
15 | execute, and transmit the Software, and to prepare derivative works of the
16 | Software, and to permit third-parties to whom the Software is furnished to
17 | do so, all subject to the following:
18 |
19 | The copyright notices in the Software and this entire statement, including
20 | the above license grant, this restriction and the following disclaimer,
21 | must be included in all copies of the Software, in whole or in part, and
22 | all derivative works of the Software, unless such copies or derivative
23 | works are solely in the form of machine-executable object code generated by
24 | a source language processor.
25 |
26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 | DEALINGS IN THE SOFTWARE.
33 |
34 | */
35 |
36 | /**
37 | * @file
38 | *
39 | * Include this file if you want to read OSM o5m and o5c files.
40 | */
41 |
42 | #include // IWYU pragma: export
43 | #include // IWYU pragma: export
44 |
45 | #endif // OSMIUM_IO_O5M_INPUT_HPP
46 |
--------------------------------------------------------------------------------
/include/osmium/io/opl_input.hpp:
--------------------------------------------------------------------------------
1 | #ifndef OSMIUM_IO_OPL_INPUT_HPP
2 | #define OSMIUM_IO_OPL_INPUT_HPP
3 |
4 | /*
5 |
6 | This file is part of Osmium (https://osmcode.org/libosmium).
7 |
8 | Copyright 2013-2025 Jochen Topf and others (see README).
9 |
10 | Boost Software License - Version 1.0 - August 17th, 2003
11 |
12 | Permission is hereby granted, free of charge, to any person or organization
13 | obtaining a copy of the software and accompanying documentation covered by
14 | this license (the "Software") to use, reproduce, display, distribute,
15 | execute, and transmit the Software, and to prepare derivative works of the
16 | Software, and to permit third-parties to whom the Software is furnished to
17 | do so, all subject to the following:
18 |
19 | The copyright notices in the Software and this entire statement, including
20 | the above license grant, this restriction and the following disclaimer,
21 | must be included in all copies of the Software, in whole or in part, and
22 | all derivative works of the Software, unless such copies or derivative
23 | works are solely in the form of machine-executable object code generated by
24 | a source language processor.
25 |
26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 | DEALINGS IN THE SOFTWARE.
33 |
34 | */
35 |
36 | /**
37 | * @file
38 | *
39 | * Include this file if you want to read OSM OPL files.
40 | *
41 | */
42 |
43 | #include // IWYU pragma: export
44 | #include // IWYU pragma: export
45 |
46 | #endif // OSMIUM_IO_OPL_INPUT_HPP
47 |
--------------------------------------------------------------------------------
/.github/workflows/clang-tidy.yml:
--------------------------------------------------------------------------------
1 | name: clang-tidy
2 |
3 | on: workflow_dispatch
4 |
5 | jobs:
6 | clang-tidy:
7 | runs-on: ubuntu-latest
8 | strategy:
9 | fail-fast: false
10 | matrix:
11 | image: ["debian:trixie", "debian:testing"]
12 | include:
13 | - image: "debian:trixie"
14 | clang: 19
15 | - image: "debian:testing"
16 | clang: 21
17 | # - image: "debian:experimental"
18 | # clang: 21
19 | container:
20 | image: ${{ matrix.image }}
21 | env:
22 | BUILD_TYPE: Dev
23 | CC: clang-${{ matrix.clang }}
24 | CXX: clang++-${{ matrix.clang }}
25 | CPP_VERSION: c++14
26 | APT_LISTCHANGES_FRONTEND: none
27 | DEBIAN_FRONTEND: noninteractive
28 | steps:
29 | - name: Prepare container (apt)
30 | run: |
31 | apt-get update -qq
32 | apt-get install -yq \
33 | clang-${{ matrix.clang }} \
34 | clang-tidy-${{ matrix.clang }} \
35 | cmake \
36 | git \
37 | libboost-dev \
38 | libbz2-dev \
39 | libexpat1-dev \
40 | libgdal-dev \
41 | libgeos++-dev \
42 | liblz4-dev \
43 | make \
44 | zlib1g-dev
45 | shell: bash
46 | - uses: actions/checkout@v4
47 | with:
48 | submodules: true
49 | - uses: ./.github/actions/install-protozero
50 | - uses: ./.github/actions/cmake
51 | - name: Run clang-tidy
52 | run: make clang-tidy | tee libosmium-${{ github.sha }}-clang-tidy-${{ matrix.clang }}.log
53 | shell: bash
54 | working-directory: build
55 | - name: Upload clang-tidy log
56 | uses: actions/upload-artifact@v4
57 | if: always()
58 | with:
59 | name: libosmium-${{ github.sha }}-clang-tidy-${{ matrix.clang }}-log
60 | path: build/libosmium-${{ github.sha }}-clang-tidy-${{ matrix.clang }}.log
61 |
--------------------------------------------------------------------------------
/test/data-tests/testcases/test-110.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | #include "common.hpp"
6 |
7 | class TestHandler110 : public osmium::handler::Handler {
8 |
9 | public:
10 |
11 | TestHandler110() :
12 | osmium::handler::Handler() {
13 | }
14 |
15 | void node(const osmium::Node& node) const {
16 | constexpr const double epsilon = 0.00000001;
17 | if (node.id() == 110000) {
18 | REQUIRE(node.location().lon() == Approx(1.02).epsilon(epsilon));
19 | REQUIRE(node.location().lat() == Approx(1.12).epsilon(epsilon));
20 | } else if (node.id() == 110001) {
21 | REQUIRE(node.location().lon() == Approx(1.07).epsilon(epsilon));
22 | REQUIRE(node.location().lat() == Approx(1.13).epsilon(epsilon));
23 | } else {
24 | throw std::runtime_error{"Unknown ID"};
25 | }
26 | }
27 |
28 | void way(const osmium::Way& way) const {
29 | if (way.id() == 110800) {
30 | REQUIRE(way.version() == 1);
31 | REQUIRE(way.nodes().size() == 2);
32 | REQUIRE_FALSE(way.is_closed());
33 |
34 | const char *test_id = way.tags().get_value_by_key("test:id");
35 | REQUIRE(test_id);
36 | REQUIRE(!std::strcmp(test_id, "110"));
37 | } else {
38 | throw std::runtime_error{"Unknown ID"};
39 | }
40 | }
41 |
42 | }; // class TestHandler110
43 |
44 | TEST_CASE("110") {
45 | osmium::io::Reader reader{dirname + "/1/110/data.osm"};
46 |
47 | index_pos_type index_pos;
48 | index_neg_type index_neg;
49 | location_handler_type location_handler{index_pos, index_neg};
50 | location_handler.ignore_errors();
51 |
52 | CheckBasicsHandler check_basics_handler{110, 2, 1, 0};
53 | CheckWKTHandler check_wkt_handler{dirname, 110};
54 | TestHandler110 test_handler;
55 |
56 | osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/include/osmium/version.hpp:
--------------------------------------------------------------------------------
1 | #ifndef OSMIUM_VERSION_HPP
2 | #define OSMIUM_VERSION_HPP
3 |
4 | /*
5 |
6 | This file is part of Osmium (https://osmcode.org/libosmium).
7 |
8 | Copyright 2013-2025 Jochen Topf and others (see README).
9 |
10 | Boost Software License - Version 1.0 - August 17th, 2003
11 |
12 | Permission is hereby granted, free of charge, to any person or organization
13 | obtaining a copy of the software and accompanying documentation covered by
14 | this license (the "Software") to use, reproduce, display, distribute,
15 | execute, and transmit the Software, and to prepare derivative works of the
16 | Software, and to permit third-parties to whom the Software is furnished to
17 | do so, all subject to the following:
18 |
19 | The copyright notices in the Software and this entire statement, including
20 | the above license grant, this restriction and the following disclaimer,
21 | must be included in all copies of the Software, in whole or in part, and
22 | all derivative works of the Software, unless such copies or derivative
23 | works are solely in the form of machine-executable object code generated by
24 | a source language processor.
25 |
26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 | DEALINGS IN THE SOFTWARE.
33 |
34 | */
35 |
36 | // NOLINTNEXTLINE(modernize-macro-to-enum)
37 | #define LIBOSMIUM_VERSION_MAJOR 2
38 |
39 | // NOLINTNEXTLINE(modernize-macro-to-enum)
40 | #define LIBOSMIUM_VERSION_MINOR 22
41 |
42 | // NOLINTNEXTLINE(modernize-macro-to-enum)
43 | #define LIBOSMIUM_VERSION_PATCH 0
44 |
45 | #define LIBOSMIUM_VERSION_STRING "2.22.0"
46 |
47 | #endif // OSMIUM_VERSION_HPP
48 |
--------------------------------------------------------------------------------
/test/examples/t/index_lookup/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_test(NAME examples_index_lookup_help
3 | COMMAND osmium_index_lookup -h)
4 |
5 | set_tests_properties(examples_index_lookup_help PROPERTIES
6 | PASS_REGULAR_EXPRESSION "^Usage: osmium_index_lookup")
7 |
8 | # Fails with message if index file doesn't exist
9 | add_test(NAME examples_index_lookup_no_file
10 | COMMAND osmium_index_lookup --list=file_does_not_exist --type=location --dump)
11 |
12 | set_tests_properties(examples_index_lookup_no_file PROPERTIES
13 | PASS_REGULAR_EXPRESSION "^Can not open file")
14 |
15 |
16 | # Fails with message if --type option is not used
17 | add_test(NAME examples_index_lookup_no_type_option
18 | COMMAND osmium_index_lookup --list=file_does_not_exist --dump)
19 |
20 | set_tests_properties(examples_index_lookup_no_type_option PROPERTIES
21 | PASS_REGULAR_EXPRESSION "^Need --type argument.")
22 |
23 |
24 | # Fails with message if --type option is used with unknown type
25 | add_test(NAME examples_index_lookup_unknown_type
26 | COMMAND osmium_index_lookup --list=file_does_not_exist --type=UNKNOWN --dump)
27 |
28 | set_tests_properties(examples_index_lookup_unknown_type PROPERTIES
29 | PASS_REGULAR_EXPRESSION "^Unknown type 'UNKNOWN'")
30 |
31 |
32 | # Fails with message when combining options --array and --list
33 | add_test(NAME examples_index_lookup_array_list
34 | COMMAND osmium_index_lookup --list=a --array=b)
35 |
36 | set_tests_properties(examples_index_lookup_array_list PROPERTIES
37 | PASS_REGULAR_EXPRESSION "^Need option --array or --list, but not both\n$")
38 |
39 |
40 | # Fails with message when combining options --dump and --search
41 | add_test(NAME examples_index_lookup_dump_search
42 | COMMAND osmium_index_lookup --list=x --dump --search=123)
43 |
44 | set_tests_properties(examples_index_lookup_dump_search PROPERTIES
45 | PASS_REGULAR_EXPRESSION "Need option --dump or --search, but not both")
46 |
47 |
--------------------------------------------------------------------------------
/include/osmium/io/xml_output.hpp:
--------------------------------------------------------------------------------
1 | #ifndef OSMIUM_IO_XML_OUTPUT_HPP
2 | #define OSMIUM_IO_XML_OUTPUT_HPP
3 |
4 | /*
5 |
6 | This file is part of Osmium (https://osmcode.org/libosmium).
7 |
8 | Copyright 2013-2025 Jochen Topf and others (see README).
9 |
10 | Boost Software License - Version 1.0 - August 17th, 2003
11 |
12 | Permission is hereby granted, free of charge, to any person or organization
13 | obtaining a copy of the software and accompanying documentation covered by
14 | this license (the "Software") to use, reproduce, display, distribute,
15 | execute, and transmit the Software, and to prepare derivative works of the
16 | Software, and to permit third-parties to whom the Software is furnished to
17 | do so, all subject to the following:
18 |
19 | The copyright notices in the Software and this entire statement, including
20 | the above license grant, this restriction and the following disclaimer,
21 | must be included in all copies of the Software, in whole or in part, and
22 | all derivative works of the Software, unless such copies or derivative
23 | works are solely in the form of machine-executable object code generated by
24 | a source language processor.
25 |
26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 | DEALINGS IN THE SOFTWARE.
33 |
34 | */
35 |
36 | /**
37 | * @file
38 | *
39 | * Include this file if you want to write OSM XML files.
40 | *
41 | * @attention If you include this file, you'll need to enable multithreading.
42 | */
43 |
44 | #include // IWYU pragma: export
45 | #include // IWYU pragma: export
46 |
47 | #endif // OSMIUM_IO_XML_OUTPUT_HPP
48 |
--------------------------------------------------------------------------------
/include/osmium/index/multimap/all.hpp:
--------------------------------------------------------------------------------
1 | #ifndef OSMIUM_INDEX_MULTIMAP_ALL_HPP
2 | #define OSMIUM_INDEX_MULTIMAP_ALL_HPP
3 |
4 | /*
5 |
6 | This file is part of Osmium (https://osmcode.org/libosmium).
7 |
8 | Copyright 2013-2025 Jochen Topf and others (see README).
9 |
10 | Boost Software License - Version 1.0 - August 17th, 2003
11 |
12 | Permission is hereby granted, free of charge, to any person or organization
13 | obtaining a copy of the software and accompanying documentation covered by
14 | this license (the "Software") to use, reproduce, display, distribute,
15 | execute, and transmit the Software, and to prepare derivative works of the
16 | Software, and to permit third-parties to whom the Software is furnished to
17 | do so, all subject to the following:
18 |
19 | The copyright notices in the Software and this entire statement, including
20 | the above license grant, this restriction and the following disclaimer,
21 | must be included in all copies of the Software, in whole or in part, and
22 | all derivative works of the Software, unless such copies or derivative
23 | works are solely in the form of machine-executable object code generated by
24 | a source language processor.
25 |
26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 | DEALINGS IN THE SOFTWARE.
33 |
34 | */
35 |
36 | #include // IWYU pragma: keep
37 | #include // IWYU pragma: keep
38 | #include // IWYU pragma: keep
39 | #include // IWYU pragma: keep
40 |
41 | #endif // OSMIUM_INDEX_MULTIMAP_ALL_HPP
42 |
--------------------------------------------------------------------------------
/examples/osmium_read_with_progress.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | EXAMPLE osmium_read_with_progress
4 |
5 | Reads the contents of the input file showing a progress bar.
6 |
7 | DEMONSTRATES USE OF:
8 | * file input
9 | * ProgressBar utility function
10 |
11 | SIMPLER EXAMPLES you might want to understand first:
12 | * osmium_read
13 |
14 | LICENSE
15 | The code in this example file is released into the Public Domain.
16 |
17 | */
18 |
19 | #include
20 | #include // for std::cerr
21 |
22 | // Allow any format of input files (XML, PBF, ...)
23 | #include
24 |
25 | // Get access to isatty utility function and progress bar utility class.
26 | #include
27 | #include
28 |
29 | int main(int argc, char* argv[]) {
30 | if (argc != 2) {
31 | std::cerr << "Usage: " << argv[0] << " OSMFILE\n";
32 | return 1;
33 | }
34 |
35 | try {
36 | // The Reader is initialized here with an osmium::io::File, but could
37 | // also be directly initialized with a file name.
38 | const osmium::io::File input_file{argv[1]};
39 | osmium::io::Reader reader{input_file};
40 |
41 | // Initialize progress bar, enable it only if STDERR is a TTY.
42 | osmium::ProgressBar progress{reader.file_size(), osmium::isatty(2)};
43 |
44 | // OSM data comes in buffers, read until there are no more.
45 | while (const osmium::memory::Buffer buffer = reader.read()) {
46 | // Update progress bar for each buffer.
47 | progress.update(reader.offset());
48 | }
49 |
50 | // Progress bar is done.
51 | progress.done();
52 |
53 | // You do not have to close the Reader explicitly, but because the
54 | // destructor can't throw, you will not see any errors otherwise.
55 | reader.close();
56 | } catch (const std::exception& e) {
57 | // All exceptions used by the Osmium library derive from std::exception.
58 | std::cerr << e.what() << '\n';
59 | return 1;
60 | }
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/include/osmium/io/xml_input.hpp:
--------------------------------------------------------------------------------
1 | #ifndef OSMIUM_IO_XML_INPUT_HPP
2 | #define OSMIUM_IO_XML_INPUT_HPP
3 |
4 | /*
5 |
6 | This file is part of Osmium (https://osmcode.org/libosmium).
7 |
8 | Copyright 2013-2025 Jochen Topf and others (see README).
9 |
10 | Boost Software License - Version 1.0 - August 17th, 2003
11 |
12 | Permission is hereby granted, free of charge, to any person or organization
13 | obtaining a copy of the software and accompanying documentation covered by
14 | this license (the "Software") to use, reproduce, display, distribute,
15 | execute, and transmit the Software, and to prepare derivative works of the
16 | Software, and to permit third-parties to whom the Software is furnished to
17 | do so, all subject to the following:
18 |
19 | The copyright notices in the Software and this entire statement, including
20 | the above license grant, this restriction and the following disclaimer,
21 | must be included in all copies of the Software, in whole or in part, and
22 | all derivative works of the Software, unless such copies or derivative
23 | works are solely in the form of machine-executable object code generated by
24 | a source language processor.
25 |
26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 | DEALINGS IN THE SOFTWARE.
33 |
34 | */
35 |
36 | /**
37 | * @file
38 | *
39 | * Include this file if you want to read OSM XML files.
40 | *
41 | * @attention If you include this file, you'll need to link with
42 | * `libexpat`, and enable multithreading.
43 | */
44 |
45 | #include // IWYU pragma: export
46 | #include // IWYU pragma: export
47 |
48 | #endif // OSMIUM_IO_XML_INPUT_HPP
49 |
--------------------------------------------------------------------------------
/include/osmium/io/any_compression.hpp:
--------------------------------------------------------------------------------
1 | #ifndef OSMIUM_IO_ANY_COMPRESSION_HPP
2 | #define OSMIUM_IO_ANY_COMPRESSION_HPP
3 |
4 | /*
5 |
6 | This file is part of Osmium (https://osmcode.org/libosmium).
7 |
8 | Copyright 2013-2025 Jochen Topf and others (see README).
9 |
10 | Boost Software License - Version 1.0 - August 17th, 2003
11 |
12 | Permission is hereby granted, free of charge, to any person or organization
13 | obtaining a copy of the software and accompanying documentation covered by
14 | this license (the "Software") to use, reproduce, display, distribute,
15 | execute, and transmit the Software, and to prepare derivative works of the
16 | Software, and to permit third-parties to whom the Software is furnished to
17 | do so, all subject to the following:
18 |
19 | The copyright notices in the Software and this entire statement, including
20 | the above license grant, this restriction and the following disclaimer,
21 | must be included in all copies of the Software, in whole or in part, and
22 | all derivative works of the Software, unless such copies or derivative
23 | works are solely in the form of machine-executable object code generated by
24 | a source language processor.
25 |
26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 | DEALINGS IN THE SOFTWARE.
33 |
34 | */
35 |
36 | /**
37 | * @file
38 | *
39 | * Include this file if you want to read or write compressed OSM XML files.
40 | *
41 | * @attention If you include this file, you'll need to link with `libz`
42 | * and `libbz2`.
43 | */
44 |
45 | #include // IWYU pragma: export
46 | #include // IWYU pragma: export
47 |
48 | #endif // OSMIUM_IO_ANY_COMPRESSION_HPP
49 |
--------------------------------------------------------------------------------
/include/osmium/util/compatibility.hpp:
--------------------------------------------------------------------------------
1 | #ifndef OSMIUM_UTIL_COMPATIBILITY_HPP
2 | #define OSMIUM_UTIL_COMPATIBILITY_HPP
3 |
4 | /*
5 |
6 | This file is part of Osmium (https://osmcode.org/libosmium).
7 |
8 | Copyright 2013-2025 Jochen Topf and others (see README).
9 |
10 | Boost Software License - Version 1.0 - August 17th, 2003
11 |
12 | Permission is hereby granted, free of charge, to any person or organization
13 | obtaining a copy of the software and accompanying documentation covered by
14 | this license (the "Software") to use, reproduce, display, distribute,
15 | execute, and transmit the Software, and to prepare derivative works of the
16 | Software, and to permit third-parties to whom the Software is furnished to
17 | do so, all subject to the following:
18 |
19 | The copyright notices in the Software and this entire statement, including
20 | the above license grant, this restriction and the following disclaimer,
21 | must be included in all copies of the Software, in whole or in part, and
22 | all derivative works of the Software, unless such copies or derivative
23 | works are solely in the form of machine-executable object code generated by
24 | a source language processor.
25 |
26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 | DEALINGS IN THE SOFTWARE.
33 |
34 | */
35 |
36 | // Set OSMIUM_DEFINE_EXPORT before including any osmium headers to add
37 | // the special attributes to all exception classes.
38 | #ifdef OSMIUM_DEFINE_EXPORT
39 | # ifdef _MSC_VER
40 | # define OSMIUM_EXPORT __declspec(dllexport)
41 | # else
42 | # define OSMIUM_EXPORT __attribute__ ((visibility("default")))
43 | # endif
44 | #else
45 | # define OSMIUM_EXPORT
46 | #endif
47 |
48 | #endif // OSMIUM_UTIL_COMPATIBILITY_HPP
49 |
--------------------------------------------------------------------------------
/include/osmium/io/pbf_input.hpp:
--------------------------------------------------------------------------------
1 | #ifndef OSMIUM_IO_PBF_INPUT_HPP
2 | #define OSMIUM_IO_PBF_INPUT_HPP
3 |
4 | /*
5 |
6 | This file is part of Osmium (https://osmcode.org/libosmium).
7 |
8 | Copyright 2013-2025 Jochen Topf and others (see README).
9 |
10 | Boost Software License - Version 1.0 - August 17th, 2003
11 |
12 | Permission is hereby granted, free of charge, to any person or organization
13 | obtaining a copy of the software and accompanying documentation covered by
14 | this license (the "Software") to use, reproduce, display, distribute,
15 | execute, and transmit the Software, and to prepare derivative works of the
16 | Software, and to permit third-parties to whom the Software is furnished to
17 | do so, all subject to the following:
18 |
19 | The copyright notices in the Software and this entire statement, including
20 | the above license grant, this restriction and the following disclaimer,
21 | must be included in all copies of the Software, in whole or in part, and
22 | all derivative works of the Software, unless such copies or derivative
23 | works are solely in the form of machine-executable object code generated by
24 | a source language processor.
25 |
26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 | DEALINGS IN THE SOFTWARE.
33 |
34 | */
35 |
36 | /**
37 | * @file
38 | *
39 | * Include this file if you want to read OSM PBF files.
40 | *
41 | * @attention If you include this file, you'll need to link with
42 | * `libz`, and enable multithreading.
43 | */
44 |
45 | #include // IWYU pragma: export
46 | #include // IWYU pragma: export
47 | #include // IWYU pragma: export
48 |
49 | #endif // OSMIUM_IO_PBF_INPUT_HPP
50 |
--------------------------------------------------------------------------------
/include/osmium/io/pbf_output.hpp:
--------------------------------------------------------------------------------
1 | #ifndef OSMIUM_IO_PBF_OUTPUT_HPP
2 | #define OSMIUM_IO_PBF_OUTPUT_HPP
3 |
4 | /*
5 |
6 | This file is part of Osmium (https://osmcode.org/libosmium).
7 |
8 | Copyright 2013-2025 Jochen Topf and others (see README).
9 |
10 | Boost Software License - Version 1.0 - August 17th, 2003
11 |
12 | Permission is hereby granted, free of charge, to any person or organization
13 | obtaining a copy of the software and accompanying documentation covered by
14 | this license (the "Software") to use, reproduce, display, distribute,
15 | execute, and transmit the Software, and to prepare derivative works of the
16 | Software, and to permit third-parties to whom the Software is furnished to
17 | do so, all subject to the following:
18 |
19 | The copyright notices in the Software and this entire statement, including
20 | the above license grant, this restriction and the following disclaimer,
21 | must be included in all copies of the Software, in whole or in part, and
22 | all derivative works of the Software, unless such copies or derivative
23 | works are solely in the form of machine-executable object code generated by
24 | a source language processor.
25 |
26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 | DEALINGS IN THE SOFTWARE.
33 |
34 | */
35 |
36 | /**
37 | * @file
38 | *
39 | * Include this file if you want to write OSM PBF files.
40 | *
41 | * @attention If you include this file, you'll need to link with
42 | * `libz`, and enable multithreading.
43 | */
44 |
45 | #include // IWYU pragma: export
46 | #include // IWYU pragma: export
47 | #include // IWYU pragma: export
48 |
49 | #endif // OSMIUM_IO_PBF_OUTPUT_HPP
50 |
--------------------------------------------------------------------------------
/include/osmium/util/endian.hpp:
--------------------------------------------------------------------------------
1 | #ifndef OSMIUM_UTIL_ENDIAN_HPP
2 | #define OSMIUM_UTIL_ENDIAN_HPP
3 |
4 | /*
5 |
6 | This file is part of Osmium (https://osmcode.org/libosmium).
7 |
8 | Copyright 2013-2025 Jochen Topf and others (see README).
9 |
10 | Boost Software License - Version 1.0 - August 17th, 2003
11 |
12 | Permission is hereby granted, free of charge, to any person or organization
13 | obtaining a copy of the software and accompanying documentation covered by
14 | this license (the "Software") to use, reproduce, display, distribute,
15 | execute, and transmit the Software, and to prepare derivative works of the
16 | Software, and to permit third-parties to whom the Software is furnished to
17 | do so, all subject to the following:
18 |
19 | The copyright notices in the Software and this entire statement, including
20 | the above license grant, this restriction and the following disclaimer,
21 | must be included in all copies of the Software, in whole or in part, and
22 | all derivative works of the Software, unless such copies or derivative
23 | works are solely in the form of machine-executable object code generated by
24 | a source language processor.
25 |
26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 | DEALINGS IN THE SOFTWARE.
33 |
34 | */
35 |
36 | // Windows is only available for little endian architectures
37 | // https://stackoverflow.com/questions/6449468/can-i-safely-assume-that-windows-installations-will-always-be-little-endian
38 | #if defined(__FreeBSD__) || defined(__DragonFly__)
39 | # include