Squashed 'third_party/libosmium/' changes from d2c1d872b..cd892f98e

cd892f98e Release v2.20.0
e3de973e9 Disable false positive warning from GCC
938b98970 Optionally allow fractional seconds in timestamps
345d19054 Remove broken Appveyor build
8540bd4b5 Disable readability-convert-member-functions-to-static warning
8bda57bcc Fix some clang-tidy constness warnings
61d415bd8 Avoid C-style casts
4fa920809 Use default member initialization
e80a04c34 We do want macros for the version numbers
7b3ebb52a Make string global in test to avoid sanitizer errors
b904200aa Github actions: Disable "integer" sanitizer checks
d0c0741e4 Github actions: Disable dangling-reference warnings
2fcd1947d Github action: Cleanup build
8acce311b Github action: Use newer OS versions for builds
253b68795 Bugfix: Don't use class template arguments on constructor definition
58b313d3e Enable posix_fadvise usage on FreeBSD
d81d4c809 Github actions: Really disable stretch build...
a85834cf9 Github actions: Remove build on (unsupported) Debian stretch
94674ed90 Make parsing PBFs a bit less picky
f73731a1c Fix comment
5af0a4b48 Update README.md: Remove appveyor and codecov links
a44ae7be0 Release v2.19.0
d74ee5178 Update change log
af0e728c1 Update copyright date to 2023
3a76dfc4f Mark RapidJSON support as deprecated
866cdbdf1 Remove YCM config
752742ad3 Update included Catch to v2.13.10
c19fd7f16 Use PROJ_DATA in addition to PROJ_LIB
86c983378 Github actions: Cleanup
e6376a5aa Github actions: Update actions/upload-artifact to v3
2adf892d7 Github actions: Update config
146cc02f6 Github action: Update config
4e6ab3798 Revert "Remove deprecated functions in RelationsMapIndex"
7781aeb6f Remove deprecated functions in RelationsMapIndex
7314118a3 Remove deprecated BoolVector class
f6e6b1873 Remove deprecated NWRIdSet class
1676d386e Remove deprecated AssemblerConfig constructor
098f5f81e Remove comments referring to deprecated functions recently removed
4b3f18a9f Github actions: Disable Fedora 34 build
f8f54de13 Make conversion to double explicit
62b8ebe93 Various cleanups based on clang-tidy warnings
95016bf9c Use modern member initialization
3dc22331f Add lots of const's
7b9b68667 CMake config: Also check for newer clang-tidy versions
3ed568f74 Print start of offending string in overlong string exception
5663f7781 Github action: Build on Fedora 36 instead of 34
dcb34b53e Make bzip2 unit tests pass on musl-based systems
73d3594b7 Github action: Fix build on Ubuntu 22.04
a65d90902 Add lz4 library to AppVeyor build
a9416a981 Github actions: Build with Ubuntu 22.04 instead of outdated 21.04
4acdcfd40 Fix bug in members database test case
04506b22f Merge pull request #348 from AMDmi3/thread-name-freebsd
4d01c4f09 Implement set_thread_name() on FreeBSD
1fb34f931 Merge pull request #347 from a-balashov/master
6a34529d1 Fix return type.
5cec5e9c7 Fix compilation problem in example
9c50fde42 Release v2.18.0
8ab3ec47a Add a note in the source code about missing changeset id in CRC
d9264f597 Remove code that has been deprecated for a while
4ee289652 Update change log
50fe2b633 Formatting
a9ed5f93d Modernize some code
3cd09750a Rule of 5 for IdSetSmall
172f01b19 Use noexcept for move constructor/assignement
53ad0fa06 Remove OSMIUM_NORETURN macro
83002751c Use system_error instead of runtime_error where it fits better
35aecff32 Formatting fix
88c97620f Release v2.17.3
49d07bd8c Github actions: Give slow macOS machines more time
5971549fc Update change log
5aa70017c Update included Catch framework to v2.13.8
6683867cf Bugfix: Removed deadlock when shutting down active Reader
9c1cfc06b Update copyright date to 2022
481c77ed6 License file was renamed a couple of years ago
9e709fe3b Release v2.17.2
55f2a9423 Fix various formatting issues
9b94aa798 Fix detection of std::variant availability
97c6c282d Update change log
29b9ca1eb Use std::variant instead of boost::variant if available
5aea3bffb Add note about deprecated code to be removed to change log
67ca42393 Mark osmium::geom::CRS and Projection classes as deprecated
d7907274a Remove unused include
322fd9396 Don't install (deprecated) sparsehash on msys2 build
ac5a20e64 Github actions: Use lz4 library in CI builds
83af3efe7 Remove various workarounds for Windows compiler
156a4600f Github action: Also build benchmarks on Windows CI builds
38741c61e Bugfix: Possible dereference of invalid iterator in area assembler
0a51d0e69 Declare support of sparsehash based index deprecated
c7f136fb9 Remove dependency on boost::filter_iterator
a58a869c2 Disable clang-tidy warning
0af04dcf3 Add missing virtual destructors and use rule of 5
437461fa6 Add explicit explicit
da202152d Github actions: Add clang-tidy workflow (runs only on demand)
205ad0347 Various small cleanups based on clang-tidy findings
b6fed6b48 Avoid bugprone-implicit-widening-of-multiplication-result warning
8cad37cb8 Use `return` or `throw` instead of std::exit where possible
b89da1374 Various clang-tidy fixes
555918726 Better variable name
4e16fd340 Use explicit constructor
e51709efa Github CI: Also test on Windows 2022 (beta)
d8e4acba5 Do increment test together with copy constructor test
bbb0e169e Remove dependency on boost::indirect_iterator
5962b26be Github actions: Add Fedora 35 CI build
7180195f4 Github actions: Fix Debian testing gcc build
a3a1974c2 Switch from catch version 1 to catch2 as test framework
f031f8e26 Fix signed/unsigned comparisons
f3c8f86ab Get file size in Reader earlier, before we use fd in other thread
0d910154e Remove unused variables
d063e894b Bugfix: Do not read from queue that might be empty.
5c1d8d619 Modernize clang-tidy config
8e09b1c99 Pass by value and move std::string
56506a35f Github Actions CI: Remove build with thread sanitizer
68dbf631d Set timeouts on Github action workflows
346a92232 Remove superfluous buffer.commit()
d9167bfb9 Rework Github actions
b9582997d Fix stringop-overflow warning on GCC
5977dde02 Bugfix: Checking of ID order
44c05bf6f Add offending IDs to out-of-order exception messages
421814b3f Add more object comparison tests
090e70064 Workaround for GCC in C++17 mode
0901c5aee Set CMake minimum version to 2.8.12
ddce269e7 Remove unused includes/libraries from test
10520b3a9 Fix threading problem
ae90568c9 Make integer type conversion explicit
6ebfbb2a7 Revert "Make integer type conversion explicit"
ea58b8100 Replace std::forward with std::move for clarity
309fac854 Cast unicode literals in C++20
351209de9 Put two enum constants we are using together into same enum
e933414c1 Use std::invoke_result_t instead of std::result_of from C++17
134fcfb77 Use explicit casts from enum constants to double
568d7dee7 Make integer type conversion explicit
a11e77db1 Add missing initialization
a2c4f5031 Make some member functions static
f75e01e9f Make member functions static in examples
489e19dd1 Small cleanups in Reader
b6d6c5b90 Fix include order
aa684d06c Avoid warnign in CMake script for finding gem
78e28d1f5 Add Github sponsoring button
d124e2ea7 Release v2.17.1
30f5c4a95 Link to help.osm.org as further support option
f277d1379 Add github issue template
315709f08 Update change log
068c7405b Store offset in Reader directly from Decompressor
586d9fbb6 Make tracking of file size the responsibility of the Reader
5dcc2fe89 Mark page cache blocks as DONT_NEED later,
0cf064c8c Fix file_size()/offset() functions for PBF files
15d594fe6 Better implementation of integer parser for OPL parser
85633a023 Only set OSMIUM_EXPORT when OSMIUM_DEFINE_EXPORT is set
e2de86aff Add missing initializer in test
17f251c91 Add support for fadvise DONT_NEED to the PBF reader
313a3e598 Check env var OSMIUM_CLEAN_PAGE_CACHE_AFTER_READ
8a000cf89 Add option to use or not use fadvise in decompressors
7f9c48654 Read PBF files without an extra thread
cd7d5fa45 Add osmium_tags_filter example showing use of tags filter
b4901a312 Use newest version of gdal.hpp
02d26a97e Mock out OSMIUM_EXPORT macro for header checks
5d50405a8 Explicitly export exception types.
4bdb688c0 Remove Ubuntu 16 CI runs
f94e1218d Use #ifdef instead of #if to check if a macro is set
19d4e5f46 Allow integers with up to 18 digits in OPL parser
7316c657e Rename confusing variable name
8f5a85235 Remove unnecessary int -> double -> int conversion in PBF output
e970573a4 Add Writer::set_header() function to set header after constructing
9d5b890f7 Do not try to compile osmium/geom/projection.hpp without proj lib
c95404d78 Make compile/test with proj lib optional
5e8e6630d Github actions: Remove broken coverage workflow
111529b3c Do fewer string allocations in PBF reader
daae73d58 Check OSMIUM_USE_POOL_THREADS_FOR_PBF_PARSING env var only once
b263ba5e8 Release v2.17.0
d484726ed Update the notes for developers
e0045079a Update change log
7e0a0867f Cleanup and some new asserts for o5m parser code
66c5efe2f Bugfix: Another OPL parser bug
a4a57b1d6 Bugfix: Access beyond end of buffer in OPL parser
4dd1f9a11 Bugfix: Avoid integer overflow in o5m parser
c236ceb5d Update to newest osm-testdata submodule
f17bd7af9 Bugfix: OPL parser stumbled on "%%" in text
f8d031311 Add value accessor function to DeltaDecode class
3d88936fb Fix msys2 build
56b023608 Add convenient access functions to nwr_array
aa88c1c3c Add version of osmium::memory::Buffer::purge_removed without callback
dd2788554 Update change log
5702748fc Disable clang-tidy check that has false positives
b36d6c998 Code cleanup
44c6286a8 Avoid type confusion on Windows
d5aa671c0 Github actions: Install missing compilers
d6ea0da09 Fix failing test missing initializer
58839058f Add flag osmium::io::buffers_type for Reader
ef6f0a614 Remove code duplication in OSM file input parsing
ae936b158 Add recent changes to changelog
61da2e4e2 Add Github action GCC 10 Dev build
fa152fb8b Disable spurious warning generated by GCC >=8
bffdb24a5 Revert "Disable spurious warning generated by older gcc versions"
cb35dd02a Rename variables to avoid shadowing other function/variable names
2a929cc19 Tinker with cppcheck warning suppression
c81e76595 Reference parameter can be const
b6fc08347 Reduce scope of "visible" variable
b6e211116 Use shared_ptr instead of unique_ptr
8a78ac477 Disable clang checks about global variables in some tests
06a1efc9b Disable spurious warning generated by older gcc versions
39a518a93 Remove github actions Windows workflow
445fc4ecd Add "ids" output format
69ab990f3 Better bucket_count tracking without global
8a9679c3e Move more of the pbf serialization code into pool threads
5ced435b9 Cleaner implementation of PrimitiveBlock that doesn't need reuse
770cd8a89 We don't need the type() function
7cdf0765e We know how many nodes there usually are in a DenseNode block
f81469d63 Make a copy of the output options in the PrimitiveBlock
1cfe4818f Don't use references as class members
c488a14d1 Use DenseNodes only when needed in PrimitiveBlock
d38d6635c Move SerializeBlob class down in the file
953fdd57f Remove superfluous std::move()
9bb70f968 Optimization: Wrap check for future in atomic bool check
e9ab79c39 Use memset/memcpy instead of std::fill_n and std::copy
d24ca6b77 Different varint decoding for faster PBF decoding
1b24ed181 Adapt cppcheck suppression for newer cppcheck versions
bc915d487 Bugfix: Can't use std::forward multiple times on the same object
4679374a9 Remove superfluous std::forwards
b8fcdfbf8 std::forward not needed
4e406564a Can't use std::forward twice on a parameter
0d5d92ab8 Can't use std::forward twice on a parameter
f75faf2e8 Avoid strange segfault on Windows
b81deee17 Remove Windows build on Github actions
9543c8898 Correct formatting for cppcheck supression
f3bdabde7 Remove unnecessary test
77a5d0b15 Sprinkle some const's around the code
644efeaa7 Use assert instead of exception in "can not happen" situation
d9b1c12c8 Use const buffer (because we can)
f79e46d86 Wrap unmap() in try/catch on Windows also
b8621fb78 lat/lon_without_check() can be noexcept
7302bcc6d Rename some local variables to not shadow member functions
aaa983625 Fix functions accessing borders of box (noexcept)
36c4cc2d8 Another call to posix_fadvice() that should only happen on Linux
016305de6 Check we don't have a negative offset before calling fadvise
c3e877e0e Only call posix_fadvise() on Linux
94a5c9063 Use fadvise to tell kernel about our reading patterns
6a4f553a6 Add functions to access storage from node_locations_for_ways handler
3aef811e2 Add polygon output to WKB factory
04720be8c Add convenience functions to access box boundaries
1705adb8a Remove undefined behaviour
072612ab9 Ignore metadata setting on reader for history/change files
d7a880873 Update docs related to read_meta setting
336001aba Merge pull request #321 from fxcoudert/patch-1
c587e53e8 Update catch.hpp
b293e96db Fix: Test failure because of ordering by address, not string
46c063928 Release v2.16.0
a91eac694 User cmake helper for finding LZ4
6009389e3 Disable data test because it doesn't work (No Spatialite in OGR)
4160d2378 Update CI workflow
6318f51fa Remove old build.bat
78ac3abda Disable some clang-tidy warnings
efcebbfe5 Use simple return instead of std::exit
b5cec1a9b Avoid else after return
2fb593a56 CMake config: Update list of clang-tidy versions we look for
c2da87d08 Update change log
54894fdbb Make number of bytes written to an OSM file accessible from Writer
0e47ca0d2 Use std::stable_sort instead of std::sort in area assembler
3d5c90750 Add function to show supported pbf compression types
d22b419c9 Do not use pkg-config to find LZ4 library
366c3f5ac Make pbf_compression into an enum class
87e492aad Replace unordered_set by vector
9ca43812a Fix broken comment
ce88a2a08 Use proper name "macOS"
6cec53471 Update copyright date
2c9ab8627 Only try to compile lz4 code if it is enabled
9be3779b1 Make zlib_default_compression_level() function constexpr
4d629c91b Error out if zstd compressed data is detected in a PBF file
e3a8b2af4 Add support for LZ4 compression in PBF files
78f70e50c Prepare for more (optional) PBF compression types
5cd5bd6f6 Add support for setting zlib compression level when writing PBF files
23d662260 Add optional compression_level parameter to zlib_compress()
f077b8351 Add lz4_data and zstd_data fields in protobuf Blob message
35939b2cc Make some file helper functions noexcept
b74047957 Update submodule
cce503a44 Add some casts in CRC code to avoid undefined behaviour
5e72f050f Make timer class member functions non-static again
729b0317b Replace two timers by a single one, we only ever use one or the other
98268aa95 Switch from Travis CI to github actions
6c4ee8b6b Fix appveyor build
91350d7cd Iterate over const ref to avoid copy
0e14ef635 Fix cast so we don't get UB
26144743b Array iterator isn't necessarily a pointer
1109d7347 Range-for loop iterates over values not references in this case
ce09cb7b8 Also check for clang-tidy versions 11 and 12
fd106ff08 Disable some clang-tidy checks
2bee7dd34 Avoid const return values so automatic move will work
fe3f00dad Make member functions const if possible
a82bc94f6 Use member initializer where possible
c757a1d5f Always initialize variables even if not strictly necessary
efd7e0799 Make some member functions static
89134cafb Use qualified auto where it makes sense
a1cbd7cd2 Merge pull request #314 from tomhughes/dependency
ec65b9f44 Fix typo in test dependency
c965256e3 Derive exception class from std::exception
4352b68ca Mark overridden destructors as override
3f64f0189 Add some documentation around the use of the thread pool
be04b4d58 Use stable sort when sorting ObjectPointerCollection
1bd2059f2 Release v2.15.6
378305f4c Avoid wrong integer promotion
9fc63bc5e Update change log
ae649700c Quick fix: Restrict recursion depth to 20 when building areas
e9368b642 Add getter function for object_id to problem reporter
9599aa447 Mark classes as final instead of individual member functions
e076b6d27 Add IdSetSmall::merge_sorted function
fd7b1e9c9 Little optimization for IdSetSmall
69113a832 Release v2.15.5
1af498ad6 Update change log
312a537c9 Update travis config according to the newest fashion
a5f61f66f Revert "Remove YCM config"
4db1ab3c0 Mark projection classes using PROJ library as deprecated
dae2898db Revert "Also support API of modern PROJ library (version 6 and above)"
2c9ea591a Revert struct initialization because old GCCs don't like it
c2d4734d7 Various small cleanups
f960e9c5f Update change log
d0cd61337 Make OPL parser more strict: Attributes can only be specified once
d5a76e635 Also support API of modern PROJ library (version 6 and above)
cd580daae Remove YCM config
531828135 Merge pull request #304 from zhaitianduo/master
3fa9a2f47 Stick to west const convention
42fc3238f fix parsing lat bug from pbf densenode
a2df9f058 Make available_space() always return 0 on Windows
00471e02c Merge pull request #303 from CloudNiner/patch-1
fb305564a Fix location attr variable name typo
e532f5938 Add additional constructor for member_type(_string) taking char type
872338442 Add iterator to nwr_array
2709257c3 Check how much space is available in file system before resizing file
c8920d819 Disable our own deprecation warning when checking our headers
392f31c87 Update copyright date
51d15f8bd Document that location and box parameters are WGS84
01bf91a45 Bugfix: Do not close stdout after writing OSM file to it
31cc17dc4 TagMatcher now remembers whether it has a value matcher.
0bb6f48b2 Simpler emptyness test.
a2baf014e Split up large test cases.
e571f87fb New builder::attr::_t() function to set tags from comma-separated string
a9793a429 Doc fix: Not a question.
2010af4d1 Remove unused header include
f56d7a2ef cleanup code
07589f471 Allow single C string or std::string as argument for _tag.
cf5d3b2b0 Make distance function noexcept and use std versions of math funcs
3c605280f Make two almost identical overloads of haversine for pyosmium
7d85f5538 Make haversine function take a NodeRefList instead of WayNodeList
a43ffb61c Release v2.15.4
a77b99dbd Various small code improvements in area assembly code.
13ba60cb7 Reduce memory consumption in area builder
2e1d7f05b Keep track of recursion depth in area builder.
e8a7d81eb Make debug output for complex multipolygons slightly more verbose.
23c7341de Revert "Travis: Also try building on ARM."
49f8c54c7 Travis: Also try building on ARM.
e0bc0e55e Travis: Remove failing old OSX build.
a83406e45 Add osmium::Options::empty() for consistency with STL containers.
8fb753a6f Release v2.15.3
5eea80c50 New header option "sorting" when reading and writing PBFs.
46a6e4399 Bugfix: Do not propagate C++ exception through C code.
c47366d3f Release v2.15.2
1c5762f65 Change member variable init to make GCC 4.8/4.9 happy.
2503f94c9 Initialize array.
e2c10a1b3 Use std::array for nwr_array class.
8c95a6605 Workaround for old compiler.
91d63d1a5 Use larger int so we don't get narrowing conversion warnings.
96d963155 Make clang-tidy happy.
180ad2e0c Bugfix: Call parent constructor in IdSetDense copy constructor.
d0554c9d4 Add swap, copy constructor and assignment operator to IdSetDense.
b30715ed8 Retire use of OSMIUM_NORETURN macro. Use [[noreturn]] instead.
12e5f69ad Make wrapper class constructor explicit.
aeb514563 Update included catch.hpp to 1.12.2.
07322bd94 Update change log.
1bd037197 The apply function can now also take lambdas.
618e4af0a Fix Appveyor badge.
162694bda Merge pull request #285 from tusharpm/appveyor_fix_msys
820798c6a Use workaround for spatialite - readline
c3e05d977 Travis: Better homebrew config and also run on OSX 11.
6df0bbea8 Fold one-liner function only used once into code at call site.
e7f1f0ccc Make member functions of Timer class non-static again.
0204aa980 Remove assert, because check is not needed.
e3e60312a Revert "Use ftruncate64 instead of ftruncate."
9fa018323 Enable use of the old proj API in proj version 6.
9d046b4c8 Use ftruncate64 instead of ftruncate.
1a7654b05 Make some member function static.
98ce21919 Disable more clang-tidy warnings.
ba8502702 CMake config: Also look for clang-tidy-10.
90391c15a Use explicit cast and document why it is okay.
ebc5164f7 Disable narrowing conversion warning here.
1b4bbcb37 Make it clear that we are intending a conversion to double here.
cbe2e2f3e Build some of travis builds on dist bionic.
e7e4031ff Fix integer conversion algorithm.
c664fc4be Disable another clang-tidy warning.
df23ce407 Disable overstrict clang-tidy warning.
39e69d7b7 Use const ref instead of value parameters.
42e480430 Disable clang-tidy avoid-c-arrays checks.
032ee4c31 Use std::array instead of C style arrays.
60b936229 Use uppercase letters for integer literal suffixes.
f0e7d1281 Disable clang-tidy checks.
accb19c6e Disable clang-tidy check in test.
d0ebf2668 Disable clang-tidy warning cppcoreguidelines-avoid-magic-numbers.
bbbb246ef Replace c-style arrays by std::array in some places.
631e39c12 Use uppercase letters for integer literal suffixes.
c59fac3d7 Give name to unused function parameters to make clang-tidy happy.
91151ad52 Remove const from return types because it doesn't do anything.
49dea1c31 Do not use multiple declarations on a single line (readability).
90115a5bd Do not return pointer to local string.
546681234 Also look for newer clang-tidy versions in CMake config.
5858c491a Better error messages when parsing a timestamp fails.
5c06fbb60 Ignore <bbox> or <bounds> subelement of <way> or <relation>.
90f26c772 Document that valid values must be used for projections.
65a75b7d2 Make some compilers happy.
7d82a43aa Do not build areas with more than 100 locations where rings touch.
f3003e774 Fix wrong comment.
35f184f08 Release v2.15.1
3553d03bd Update copyright date to 2019.
ffa35e0c2 Appveyor config: Move the slow MSYS2 compilation to the back.
d6024a9d6 Update change log.
10ecb1335 Fix bugprone-forwarding-reference-overload clang-tidy warnings.
b66bc888d Disable bugprone-macro-parentheses clang-tidy check.
40bf6614e Switch appveyor badge
c19e26906 Disable a warning on new GCC compilers.
28c753846 Fix signed bitwise operation.
1304ad246 Bugfix: Function is not noexcept.
ce5867ea1 Put try/catch around most of main() in benchmark and test programs.
bfe1c5384 Fix exception specifications.
6c1ade020 Put try/catch around most of main() in example programs.
345359a2a Bugfix: Integer truncation on 32 bit systems.
7b66ff706 Fix or disable some clang-tidy warnings.
538e0f52f Bugfix: correctly throw exception.
c582ebdcf CMake config: also find clang-tidy-7.
0ec6cda55 Add some assertions testing alignment.
e40fc3ff0 Cheat compiler so we don't get a warning.
882f01e64 Compile with NDEBUG in RelWithDebInfo mode.
9600bcdaf Merge pull request #275 from Nakaner/test_dump_as_list
0e9344f9b replace std::bind by lambdas, replace hardcoded type
8e8a4dbd8 test Map::dump_as_list
a70e4accb Merge pull request #274 from Nakaner/index-test-cleanup
aa2555ef5 fix typo
b48567a17 test SparseMmapArray as well
825859f9d Release v2.15.0
bde2d0024 Give Buffer a better move constructor and move assignment.
0bd61ba95 Some cleanup.
a46ea362b Fixed some clang-tidy warnings.
5c9d3c2de Add function to mark tags on OSM objects as removed.
da5f083c7 Make chunk_bits in IdSetDense configurable.
e5600bbc6 Make the result type of TagsFilter configurable.
b107e964b Some code cleanup.
99ea830e0 Use explicit type instead of auto.
baff26c29 More efficient use of Buffers in XML/OPL/O5M parsers.
6e4fc2ed3 Various formatting fixes and small cleanups.
dc5d08d54 Consolidate queue config code.
2a336d445 Update change log.
968f88152 Stackless implementation of Reader.
7b14860ff Formatting.
1dd2a9f1f Tweak buffer size for PBF decoder.
d11ab7db2 Make grow_internal a private method.
a8737494c Fix default initialization of Buffer.
f6b98df70 Rewrite initializer of unique_ptr.
1efcc32e8 Remove redundant get() call.
bef66b861 Experimental code using nested buffers to reduce memory consumption.
2302da299 Clean up error handling code of bzip compression.
67786d98c Clean up error handling code of gzip compression.
dd507e322 Move coverage settings before configuration type settings.
07162475f Fix windows build.
e1912a8c2 Also implement compression tests for writer side.
16d7800a3 Remove two const_casts.
a5e3bd8af Cleanup of compression code and more tests.
f42e68745 Fix typo.
a1f88fe44 Update travis config to xenial.
5bb5db6a3 Disable clang-tidy warning.
4af366a30 Move appveyor config to new Visual Studio version.
75fc34c0b Revert use of some enums (because of problems with MSVC).
86e9d4393 Use enums for some more constants.
392347512 Force underlying type for some enums.
f4ecfc9fe Disable some clang-tidy warnings.
09d785414 Reduce the number of builds on travis.
2056202de Merge pull request #273 from Nakaner/test-missing-rel-member
ba511d204 Use enums for integer constants.
59ebb9120 Use const where possible.
5f9ac226c Fix formatting.
f5e996670 Use enums for integer constants.
4280437be Remove unused enum names.
76bbf25b2 Test that RelationsManagerBase::get_member_object returns nullptr
091a75f5a Hardcode %lld format instead of using <cinttypes> PRI macro.
d6abc4dd7 Travis: Also build with gcc 7.
fdf45be5d Update travis conf with newer OSX builds.
e4b3d8f31 CMake config: Fatal error with better message if libosmium isn't found.
0632d6007 Formatting/Cleanup.
b190b95e5 Set the xml_josm_upload header option when reading XML files.
4a3cbe0f1 Disable docker builds on travis. They are being phased out by travis.
a5cb873bc Sort includes.
0e4c57a09 Merge pull request #271 from DennisOSRM/patch-2
13dfd56e1 Minor: Wrong order of qualifiers
1bb69ec62 Code cleanup.
54ae75658 Merge pull request #269 from Nakaner/dump_sparse_as_array
bb1a4e3e8 make const what can be const
d44c79a5e remove duplicated initialization with empty values
c2ef6a67e also test SparseMemArray and don't test SparseMmapArray on OS X
31f10bb2f add comments and check all entries in the index
c30845bcf code style issues
5ff69d536 use std::fill_n
78939b47a remove unnecessary variable
93e747244 style fixes
a76385a2e simplify test
364830df3 use a simpler loop
393be1270 fix code style issues, use std::unique_ptr instead of bare pointers
309e890bf write empty values during each iteration
0aa4c914e Update to newest gdalcpp.
6fea0e82a tidy up unit test
d0fce0ac3 don't confuse the number of elements and the size of the array
98923b8bb MinGW appveyor build is broken again. Try this workaround again.
d9c7e25e0 Merge pull request #266 from Nakaner/dump_and_load_index_test
ccbcea885 use better name for variable
d91f9c8a1 Make sure assert() is not defined in test.
f8dc3aad4 implement SparseMmapArray::dump_as_array
02b2ebde1 Add DenseMemArray and run DenseMmapArray only on Linux
8ba350a9b use the file index, not the mmaped index
15f215095 add unit test checking dumping and loading of dense indexes
2d5244a24 Remove workaround.
058cd3a36 Release v2.14.2
ff16782fb Rewrite code to be byte-order independent.
c7e76743a Add workaround for gdal problem on MinGW appveyor build.
75d1b48b1 Remove test that doesn't work reliably on all architectures.
269066889 Release v2.14.1
f21bf5738 Write assert in a way it also works on 32 bit machines.
748917839 Refactored some SECTIONs from test cases into TEST_CASEs.
3af83c68a Fix a WKB test which was too sensitive to tiny arithmetic errors.
a198b06ba Update change log.
3dfc97fc2 Split up large test cases.
4cae84b1d Add missing includes.
dd2a0caf8 Use auto after static_cast to avoid duplication of type.
6fdda54ae Use our internal functions for writing out locations in box output.
060b0ec59 Use unsigned in bit operation.
bd8b76eee Remove utfcpp library from libosmium.
467e1a1f1 Add UTF8 to Unicode codepoint conversion.
68c981313 Use our own function for unicode codepoint to tf8 conversion.
2a35ad727 Use protozero::byteswap_inplace instead of htonl/ntohl.
452f56e87 Add Timestamp::to_iso_all() function which also outputs the 0 value.
5f6638f88 Ask for the newest Protozero version.
b9886c58b Do a static_cast to avoid compiler warnings.
954b9e5a4 Move test case SECTIONs into their own TEST_CASEs.
be99d53ef Add some asserts, docs, and noexcepts.
6ce3bcb10 Replace some SECTIONs by TEST_CASEs in test code.
05841f16f Disable the last clang-tidy warning we are seeing.
e16b4ad1e Disable warning about struct initialization.
d7e033672 Correct way to disable clang-diagnostic warning in clang-tidy.
f60c8fa0a Proper initialization.
6aa3929e1 Resolve some clang-tidy reports.
5bb84716d Mark static_cast_with_assert as deprecated.
e51b8e3af Remove remaining use of static_cast_with_assert.
d19d97c46 Refactor StringTable to minimize casts needed.
cbf0c6e1a Fix naming of member functions that are not found by doxygen.
cd3a18a53 Add support for using the CRC32 implementation from the zlib library.
874a79133 Document use of mutable in DiffIterator class.
07985a68e Fix compilation error when fileno() is a macro.
eee3d0af6 Use https links where possible.
6465f9ff2 Use https URL for osmcode.org.
60b3bcc16 Make two functions noexcept.
ff160aa30 Add clear_user() function to OSMObject and Changeset.
63a6cf4b4 Use {} for constructors.
47b66ed46 Merge pull request #255 from DennisOSRM/patch-1
3e015b4c7 Make sure -stdlib=libc++ is only set on Mac when compiling with Clang
7674775c1 Document MultipolygonCollector class as deprecated.
e114fefb9 Travis: build with clang 6.0, remove clang 4.0
8be488572 CMake config: Also look for clang-tidy version 7.
2e7eb285e Fix namespace closing comment.

git-subtree-dir: third_party/libosmium
git-subtree-split: cd892f98e8e355f5d0a4b717c153c7de0d15bb0d
This commit is contained in:
Siarhei Fedartsou 2024-07-13 14:22:42 +02:00
parent a3a7a822e1
commit 89b30b26e5
374 changed files with 26370 additions and 16018 deletions

View File

@ -1,14 +1,31 @@
---
Checks: '*,-android-cloexec-*,-cert-dcl21-cpp,-cert-err58-cpp,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-static-cast-downcast,-cppcoreguidelines-pro-type-vararg,-fuchsia-*,-google-runtime-references,-hicpp-invalid-access-moved,-hicpp-no-array-decay,-hicpp-no-assembler,-hicpp-vararg,-misc-macro-parentheses,-misc-unused-parameters,-modernize-make-unique,-modernize-raw-string-literal,-readability-avoid-const-params-in-decls,-readability-implicit-bool-cast,-readability-implicit-bool-conversion'
Checks: '*,-abseil-string-find-str-contains,-altera-*,-android-cloexec-*,-bugprone-branch-clone,-bugprone-easily-swappable-parameters,-bugprone-macro-parentheses,-cert-dcl21-cpp,-cert-err58-cpp,-clang-analyzer-optin.cplusplus.VirtualCall,-cppcoreguidelines-avoid-c-arrays,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-macro-usage,-cppcoreguidelines-non-private-member-variables-in-classes,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-static-cast-downcast,-cppcoreguidelines-pro-type-vararg,-fuchsia-*,-google-runtime-references,-hicpp-avoid-c-arrays,-hicpp-invalid-access-moved,-hicpp-no-array-decay,-hicpp-no-assembler,-hicpp-vararg,-llvmlibc-*,-llvm-qualified-auto,-misc-macro-parentheses,-misc-non-private-member-variables-in-classes,-misc-no-recursion,-misc-unused-parameters,-modernize-avoid-c-arrays,-modernize-make-unique,-modernize-raw-string-literal,-modernize-use-trailing-return-type,-readability-avoid-const-params-in-decls,-readability-convert-member-functions-to-static,-readability-function-cognitive-complexity,-readability-identifier-length,-readability-implicit-bool-cast,-readability-implicit-bool-conversion,-readability-magic-numbers,-readability-qualified-auto'
#
# For a list of check options, see:
# http://clang.llvm.org/extra/clang-tidy/checks/list.html
# https://clang.llvm.org/extra/clang-tidy/checks/list.html
#
# Disabled checks:
#
# abseil-string-find-str-contains
# We don't want the dependency.
#
# altera-*
# Doesn't apply.
#
# android-cloexec-*
# O_CLOEXEC isn't available on Windows making this non-portable.
#
# bugprone-branch-clone
# Nice idea but collides but with switch statements we'll need to use
# fall-throughs to fix this, which is also bad.
#
# bugprone-easily-swappable-parameters
# Interesting test, but not something we can do much about in many places.
#
# bugprone-macro-parentheses
# False positive in the only place where it reports something and
# disabling locally doesn't work.
#
# cert-dcl21-cpp
# It is unclear whether this is still a good recommendation in modern C++.
#
@ -16,6 +33,22 @@ Checks: '*,-android-cloexec-*,-cert-dcl21-cpp,-cert-err58-cpp,-cppcoreguidelines
# Used in several singelton factory functions. I don't know of a better
# way to do this and it is rather unlikely that this will be a problem.
#
# clang-analyzer-optin.cplusplus.VirtualCall
# Disable a warning we get from the Catch test framework.
#
# cppcoreguidelines-avoid-c-arrays
# Alias for modernize-avoid-c-arrays.
#
# cppcoreguidelines-avoid-magic-numbers
# Generally good advice, but there are too many places where this is
# useful, for instance in tests.
#
# cppcoreguidelines-macro-usage
# There are cases where we actually need macros.
#
# cppcoreguidelines-non-private-member-variables-in-classes
# Alias for misc-non-private-member-variables-in-classes
#
# cppcoreguidelines-owning-memory
# Don't want to add dependency on gsl library.
#
@ -48,6 +81,9 @@ Checks: '*,-android-cloexec-*,-cert-dcl21-cpp,-cert-err58-cpp,-cppcoreguidelines
# This is just a matter of preference, and we can't change the interfaces
# now anyways.
#
# hicpp-avoid-c-arrays
# Alias for modernize-avoid-c-arrays.
#
# hicpp-invalid-access-moved
# Creates false positives.
#
@ -60,14 +96,33 @@ Checks: '*,-android-cloexec-*,-cert-dcl21-cpp,-cert-err58-cpp,-cppcoreguidelines
# hicpp-vararg
# Too strict, sometimes calling vararg functions is necessary.
#
# llvm-qualified-auto
# readability-qualified-auto
# This reports too many cases. Typical case is an iterator that might be
# a pointer on one system but some special type on another.
#
# llvmlibc-*
# Doesn't apply to us.
#
# misc-macro-parentheses
# False positive in the only place where it reports something and
# disabling locally doesn't work.
# Old name for bugprone-macro-parentheses.
#
# misc-non-private-member-variables-in-classes
# Reports this also for structs, which doesn't make any sense. There is
# an option "IgnoreClassesWithAllMemberVariablesBeingPublic" which should
# disable this, but it didn't work for me.
#
# misc-no-recursion
# There is nothing wrong with recursion.
#
# misc-unused-parameters
# Can't be fixed, because then Doxygen will complain. (In file
# include/osmium/area/problem_reporter.hpp).
#
# modernize-avoid-c-arrays
# Makes sense for some array, but especially for char arrays using
# std::array isn't a good solution.
#
# modernize-make-unique
# This is a C++11 library and C++ doesn't have std::make_unique.
#
@ -75,16 +130,31 @@ Checks: '*,-android-cloexec-*,-cert-dcl21-cpp,-cert-err58-cpp,-cppcoreguidelines
# Readability isn't that much better, arguably worse because of the new
# syntax.
#
# modernize-use-trailing-return-type
# I am not quite that modern.
#
# readability-avoid-const-params-in-decls
# This is header only library, so the declaration and implementation are
# often the same and we want to have the const in implementations.
#
# readability-convert-member-functions-to-static
# Reports too many false positives
#
# readability-function-cognitive-complexity
# Sometimes the large functions are needed.
#
# readability-identifier-length
# Too strict.
#
# readability-implicit-bool-cast
# Old name for readability-implicit-bool-conversion.
#
# readability-implicit-bool-conversion
# I don't think this makes the code more readable.
#
# readability-magic-numbers
# Alias for cppcoreguidelines-avoid-magic-numbers.
#
#WarningsAsErrors: '*'
HeaderFilterRegex: '\/include\/osmium\/.*'
...

1
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
custom: "https://osmcode.org/sponsors.html"

48
.github/ISSUE_TEMPLATE/bug-report.md vendored Normal file
View File

@ -0,0 +1,48 @@
---
name: Report problems with the software
about: You found a (possible) bug in libosmium
title: ''
labels: ''
assignees: ''
---
## What version of libosmium are you using?
<!-- Please use the [latest
release](https://github.com/osmcode/libosmium/releases) or master if at all
possible. -->
## What operating system and compiler are you using?
<!-- Also what Linux distribution if applicable, OS version? -->
## Tell us something about your system
<!-- How much RAM do you have, how many CPUs, bare metal or cloud setup? -->
## What did you do exactly?
<!-- Please provide the command(s) you used including all options etc. Include
links to input files. -->
## What did you expect to happen?
<!-- Describe in detail what you expected the above would do. -->
## What did happen instead?
<!-- Please describe what happened and why you think this is wrong. Please
include (or link to, if it is too verbose) the log output. -->
## What did you do to try analyzing the problem?
<!-- Describe what steps you already did to try analyzing the problem before
reporting. -->

4
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@ -0,0 +1,4 @@
contact_links:
- name: help.osm.org
url: https://help.openstreetmap.org/
about: Ask questions and get support from the community.

View File

@ -0,0 +1,10 @@
name: Windows Build
runs:
using: composite
steps:
- name: Build
run: cmake --build . --config Release --verbose
shell: bash
working-directory: build

10
.github/actions/build/action.yml vendored Normal file
View File

@ -0,0 +1,10 @@
name: Build
runs:
using: composite
steps:
- name: Build
run: make VERBOSE=1
shell: bash
working-directory: build

View File

@ -0,0 +1,19 @@
name: Windows CMake
runs:
using: composite
steps:
- name: Create build directory
run: mkdir build
shell: bash
- name: Configure
run: |
cmake -LA .. \
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake \
-DBUILD_HEADERS=OFF \
-DBUILD_BENCHMARKS=ON \
-DOsmium_DEBUG=TRUE \
-DPROTOZERO_INCLUDE_DIR=${GITHUB_WORKSPACE}/../protozero/include
shell: bash
working-directory: build

19
.github/actions/cmake/action.yml vendored Normal file
View File

@ -0,0 +1,19 @@
name: CMake
runs:
using: composite
steps:
- name: Create build directory
run: mkdir build
shell: bash
- name: Configure
run: |
cmake -LA .. \
-DBUILD_DATA_TESTS=ON \
-DUSE_CPP_VERSION=${CPP_VERSION} \
-DWITH_PROJ=${WITH_PROJ} \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DPROTOZERO_INCLUDE_DIR=${GITHUB_WORKSPACE}/../protozero/include
shell: bash
working-directory: build

View File

@ -0,0 +1,10 @@
name: Windows Test
runs:
using: composite
steps:
- name: Test
run: ctest --output-on-failure -C Release
shell: bash
working-directory: build

10
.github/actions/ctest/action.yml vendored Normal file
View File

@ -0,0 +1,10 @@
name: ctest
runs:
using: composite
steps:
- name: Test
run: ctest --output-on-failure
shell: bash
working-directory: build

View File

@ -0,0 +1,13 @@
name: Install homebrew packages on macOS
runs:
using: composite
steps:
- name: Install packages
run: |
brew install \
boost \
gdal \
google-sparsehash
shell: bash

View File

@ -0,0 +1,9 @@
name: Install Protozero from git
runs:
using: composite
steps:
- name: Install from git
run: git clone --quiet --depth 1 https://github.com/mapbox/protozero.git ../protozero
shell: bash

View File

@ -0,0 +1,20 @@
name: Install apt packages on Ubuntu/Debian
runs:
using: composite
steps:
- name: Install packages
run: |
sudo apt-get update -qq
sudo apt-get install -yq \
doxygen \
libboost-dev \
libgdal-dev \
libgeos++-dev \
liblz4-dev \
libproj-dev \
libsparsehash-dev \
ruby-json \
spatialite-bin
shell: bash

View File

@ -0,0 +1,17 @@
name: Install vcpkg packages on Windows
runs:
using: composite
steps:
- name: Install packages
run: |
vcpkg install \
boost-crc:x64-windows \
boost-variant:x64-windows \
bzip2:x64-windows \
expat:x64-windows \
lz4:x64-windows \
sparsehash:x64-windows \
zlib:x64-windows
shell: bash

294
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,294 @@
name: CI
on: [ push, pull_request ]
jobs:
linux:
runs-on: ubuntu-latest
timeout-minutes: 40
strategy:
fail-fast: false
matrix:
name: [Ubuntu-18, Ubuntu-20, Ubuntu-22, Debian-10, Debian-11, Debian-12, Debian-Testing, Debian-Experimental, Fedora-35, Fedora-36, Fedora-37, Fedora-38]
build_type: [Dev]
cpp_compiler: [g++]
cpp_version: [c++11]
include:
- name: Ubuntu-18
# Uses gcc 7.5.0, clang 6.0.0, cmake 3.10.2
image: "ubuntu:18.04"
ubuntu: 18
- name: Ubuntu-20
# Uses gcc 9.3.0, clang 10.0.0, cmake 3.16.3
image: "ubuntu:20.04"
ubuntu: 20
- name: Ubuntu-22
# Uses gcc 12.2.0, clang 15.0.7, cmake 3.24.2
image: "ubuntu:22.04"
ubuntu: 22
CXXFLAGS: -Wno-stringop-overread
- name: Debian-10
# Uses gcc 8.3.0, clang 7.0.1, cmake 3.13.4
image: "debian:buster"
- name: Debian-11
# Uses gcc 10.2.1, clang 11.0.1, cmake 3.18.4
image: "debian:bullseye"
- name: Debian-11
image: "debian:bullseye"
cpp_version: c++17
- name: Debian-11
image: "debian:bullseye"
cpp_version: c++20
- name: Debian-11
image: "debian:bullseye"
c_compiler: clang
cpp_compiler: clang++
- name: Debian-11
image: "debian:bullseye"
c_compiler: clang
cpp_compiler: clang++
cpp_version: c++17
- name: Debian-11
image: "debian:bullseye"
c_compiler: clang
cpp_compiler: clang++
cpp_version: c++20
- name: Debian-11
image: "debian:bullseye"
build_type: RelWithDebInfo
- name: Debian-11
image: "debian:bullseye"
c_compiler: clang
cpp_compiler: clang++
CXXFLAGS: -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer
LDFLAGS: -fsanitize=address,undefined
- name: Debian-12
# Uses gcc 12.2.0, clang 15.0.6, cmake 3.25.1
image: "debian:bookworm"
CXXFLAGS: -Wno-stringop-overread
- name: Debian-12
image: "debian:bookworm"
cpp_version: c++17
CXXFLAGS: -Wno-stringop-overread
- name: Debian-12
image: "debian:bookworm"
cpp_version: c++20
CXXFLAGS: -Wno-stringop-overread
- name: Debian-12
image: "debian:bookworm"
c_compiler: clang
cpp_compiler: clang++
- name: Debian-12
image: "debian:bookworm"
c_compiler: clang
cpp_compiler: clang++
cpp_version: c++17
- name: Debian-12
image: "debian:bookworm"
c_compiler: clang
cpp_compiler: clang++
cpp_version: c++20
- name: Debian-12
image: "debian:bookworm"
build_type: RelWithDebInfo
CXXFLAGS: -Wno-stringop-overread
- name: Debian-12
image: "debian:bookworm"
c_compiler: clang
cpp_compiler: clang++
CXXFLAGS: -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer
LDFLAGS: -fsanitize=address,undefined
- name: Debian-Testing
image: "debian:testing"
CXXFLAGS: -Wno-stringop-overread -Wno-dangling-reference
- name: Debian-Testing
image: "debian:testing"
c_compiler: clang
cpp_compiler: clang++
- name: Debian-Experimental
image: "debian:experimental"
CXXFLAGS: -Wno-stringop-overread -Wno-dangling-reference
- name: Debian-Experimental
image: "debian:experimental"
c_compiler: clang
cpp_compiler: clang++
- name: Fedora-35
# Uses gcc 11.2.1, clang 12.0.1, cmake 3.20.5
image: "fedora:35"
CXXFLAGS: -Wno-stringop-overread
- name: Fedora-36
# Uses gcc 12.2.0, clang 14.0.5, cmake 3.24.2
image: "fedora:36"
CXXFLAGS: -Wno-stringop-overread
- name: Fedora-37
# Uses gcc 12.3.1, clang 15.0.7, cmake 3.26.4
image: "fedora:37"
CXXFLAGS: -Wno-stringop-overread
- name: Fedora-38
# Uses gcc 13.0.1, clang 16.0.5, cmake 3.26.4
image: "fedora:38"
CXXFLAGS: -Wno-stringop-overread -Wno-dangling-reference
container:
image: ${{ matrix.image }}
env:
LANG: en_US.UTF-8
BUILD_TYPE: ${{ matrix.build_type }}
CC: ${{ matrix.c_compiler }}
CXX: ${{ matrix.cpp_compiler }}
CXXFLAGS: ${{ matrix.CXXFLAGS }}
LDFLAGS: ${{ matrix.LDFLAGS }}
CPP_VERSION: ${{ matrix.cpp_version }}
WITH_PROJ: ON
APT_LISTCHANGES_FRONTEND: none
DEBIAN_FRONTEND: noninteractive
steps:
- name: Prepare container (apt)
shell: bash
if: startsWith(matrix.image, 'debian:') || startsWith(matrix.image, 'ubuntu:')
run: |
apt-get update -qq
apt-get install -yq \
clang \
cmake \
doxygen \
g++ \
git \
graphviz \
libboost-dev \
libbz2-dev \
libexpat1-dev \
libgdal-dev \
libgeos++-dev \
liblz4-dev \
libproj-dev \
libsparsehash-dev \
make \
ruby \
ruby-json \
spatialite-bin \
zlib1g-dev
- name: Install compiler
shell: bash
if: matrix.cpp_compiler == 'clang++-14'
run: apt-get install -yq clang-14
- name: Prepare container (dnf)
shell: bash
if: startsWith(matrix.image, 'fedora:')
run: |
dnf install --quiet --assumeyes \
boost-devel \
bzip2-devel \
cmake \
doxygen \
expat-devel \
gcc-c++ \
gdal-devel \
gdalcpp-static \
geos-devel \
git \
graphviz \
lz4-devel \
make \
proj-devel \
ruby \
rubygem-json \
sparsehash-devel \
spatialite-tools \
zlib-devel
# Use v1 of checkout because v3 doesn't work with submodules
- uses: actions/checkout@v1
with:
submodules: true
- uses: ./.github/actions/install-protozero
- uses: ./.github/actions/cmake
- uses: ./.github/actions/build
- uses: ./.github/actions/ctest
ubuntu-latest:
runs-on: ubuntu-22.04
timeout-minutes: 40
env:
CC: clang-15
CXX: clang++-15
BUILD_TYPE: Dev
WITH_PROJ: ON
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Install new clang
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/llvm-snapshot.asc
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main'
sudo apt-get update -qq
sudo apt-get install -yq clang-15
shell: bash
- uses: ./.github/actions/install-ubuntu
- uses: ./.github/actions/install-protozero
- uses: ./.github/actions/cmake
- uses: ./.github/actions/build
- uses: ./.github/actions/ctest
macos:
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
os:
- "macos-11"
- "macos-12"
- "macos-13"
build_type: [Dev]
include:
- os: "macos-12"
build_type: Release
runs-on: ${{ matrix.os }}
env:
CC: clang
CXX: clang++
BUILD_TYPE: ${{ matrix.build_type }}
WITH_PROJ: OFF
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: ./.github/actions/install-macos
- uses: ./.github/actions/install-protozero
- uses: ./.github/actions/cmake
- uses: ./.github/actions/build
- uses: ./.github/actions/ctest
windows-minimal:
timeout-minutes: 40
strategy:
fail-fast: false
matrix:
os:
- windows-2019
- windows-2022
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: ./.github/actions/install-windows
- uses: ./.github/actions/install-protozero
- uses: ./.github/actions/cmake-windows
- uses: ./.github/actions/build-windows
- uses: ./.github/actions/ctest-windows
windows-2019-full:
runs-on: windows-2019
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: ./.github/actions/install-windows
- name: Install extra packages
run: vcpkg install geos:x64-windows gdal:x64-windows proj4:x64-windows
shell: bash
- uses: ./.github/actions/install-protozero
- uses: ./.github/actions/cmake-windows
- uses: ./.github/actions/build-windows
- uses: ./.github/actions/ctest-windows

65
.github/workflows/clang-tidy.yml vendored Normal file
View File

@ -0,0 +1,65 @@
name: clang-tidy
on: workflow_dispatch
jobs:
clang-tidy:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
image: ["debian:bullseye", "debian:testing", "debian:experimental"]
include:
- image: "debian:bullseye"
clang: 11
- image: "debian:testing"
clang: 15
- image: "debian:experimental"
clang: 15
container:
image: ${{ matrix.image }}
env:
BUILD_TYPE: Dev
CC: clang-${{ matrix.clang }}
CXX: clang++-${{ matrix.clang }}
CPP_VERSION: c++11
WITH_PROJ: ON
APT_LISTCHANGES_FRONTEND: none
DEBIAN_FRONTEND: noninteractive
steps:
- name: Prepare container (apt)
run: |
apt-get update -qq
apt-get install -yq \
clang-${{ matrix.clang }} \
clang-tidy-${{ matrix.clang }} \
cmake \
git \
libboost-dev \
libbz2-dev \
libexpat1-dev \
libgdal-dev \
libgeos++-dev \
liblz4-dev \
libproj-dev \
libsparsehash-dev \
make \
zlib1g-dev
shell: bash
# Use v1 of checkout because v3 doesn't work with submodules
- uses: actions/checkout@v1
with:
submodules: true
- uses: ./.github/actions/install-protozero
- uses: ./.github/actions/cmake
- name: clang-tidy
run: make clang-tidy | tee clang-tidy-${{ matrix.clang }}.log
shell: bash
working-directory: build
- name: Upload Log
uses: actions/upload-artifact@v3
if: always()
with:
name: clang-tidy-${{ matrix.clang }}-log
path: build/clang-tidy-${{ matrix.clang }}.log

View File

@ -1,243 +0,0 @@
#-----------------------------------------------------------------------------
#
# Configuration for continuous integration service at travis-ci.org
#
#-----------------------------------------------------------------------------
language: generic
sudo: false
dist: trusty
#-----------------------------------------------------------------------------
cache:
directories:
- $HOME/.ccache
env:
global:
- CCACHE_TEMPDIR=/tmp/.ccache-temp
- CCACHE_COMPRESS=1
- CASHER_TIME_OUT=1000
#-----------------------------------------------------------------------------
# Save common build configurations as shortcuts, so we can reference them later.
addons_shortcuts:
addons_clang35: &clang35
apt:
sources: [ 'ubuntu-toolchain-r-test', 'boost-latest' ]
packages: [ 'libboost1.55-all-dev', 'libgdal-dev', 'libproj-dev', 'libsparsehash-dev', 'spatialite-bin', 'clang-3.5']
addons_clang38: &clang38
apt:
sources: [ 'ubuntu-toolchain-r-test', 'boost-latest' ]
packages: [ 'libboost1.55-all-dev', 'libgdal-dev', 'libproj-dev', 'libsparsehash-dev', 'spatialite-bin', 'clang-3.8']
addons_clang39: &clang39
apt:
sources: [ 'ubuntu-toolchain-r-test', 'boost-latest' ]
packages: [ 'libboost1.55-all-dev', 'libgdal-dev', 'libproj-dev', 'libsparsehash-dev', 'spatialite-bin', 'clang-3.9']
addons_clang40: &clang40
apt:
sources: [ 'ubuntu-toolchain-r-test', 'boost-latest', 'llvm-toolchain-trusty-4.0' ]
packages: [ 'libboost1.55-all-dev', 'libgdal-dev', 'libproj-dev', 'libsparsehash-dev', 'spatialite-bin', 'clang-4.0']
addons_clang50: &clang50
apt:
sources: [ 'ubuntu-toolchain-r-test', 'boost-latest', 'llvm-toolchain-trusty-5.0' ]
packages: [ 'libboost1.55-all-dev', 'libgdal-dev', 'libproj-dev', 'libsparsehash-dev', 'spatialite-bin', 'clang-5.0', 'g++-6', 'gcc-6']
addons_gcc48: &gcc48
apt:
sources: [ 'ubuntu-toolchain-r-test', 'boost-latest' ]
packages: [ 'libboost1.55-all-dev', 'libgdal-dev', 'libproj-dev', 'libsparsehash-dev', 'spatialite-bin', 'g++-4.8', 'gcc-4.8' ]
addons_gcc49: &gcc49
apt:
sources: [ 'ubuntu-toolchain-r-test', 'boost-latest' ]
packages: [ 'libboost1.55-all-dev', 'libgdal-dev', 'libproj-dev', 'libsparsehash-dev', 'spatialite-bin', 'g++-4.9', 'gcc-4.9' ]
addons_gcc5: &gcc5
apt:
sources: [ 'ubuntu-toolchain-r-test', 'boost-latest' ]
packages: [ 'libboost1.55-all-dev', 'libgdal-dev', 'libproj-dev', 'libsparsehash-dev', 'spatialite-bin', 'g++-5', 'gcc-5' ]
addons_gcc6: &gcc6
apt:
sources: [ 'ubuntu-toolchain-r-test', 'boost-latest' ]
packages: [ 'libboost1.55-all-dev', 'libgdal-dev', 'libproj-dev', 'libsparsehash-dev', 'spatialite-bin', 'g++-6', 'gcc-6' ]
#-----------------------------------------------------------------------------
matrix:
include:
# 1/ Linux Clang Builds
- os: linux
compiler: linux-clang35-release
env: CC='clang-3.5' CXX='clang++-3.5' BUILD_TYPE='Release'
addons: *clang35
- os: linux
compiler: linux-clang35-dev
env: CC='clang-3.5' CXX='clang++-3.5' BUILD_TYPE='Dev'
addons: *clang35
- os: linux
compiler: linux-clang38-release
env: CC='clang-3.8' CXX='clang++-3.8' BUILD_TYPE='Release'
addons: *clang38
- os: linux
compiler: linux-clang38-dev
env: CC='clang-3.8' CXX='clang++-3.8' BUILD_TYPE='Dev'
addons: *clang38
- os: linux
compiler: linux-clang39-release
env: CC='clang-3.9' CXX='clang++-3.9' BUILD_TYPE='Release'
addons: *clang39
- os: linux
compiler: linux-clang39-dev
env: CC='clang-3.9' CXX='clang++-3.9' BUILD_TYPE='Dev'
addons: *clang39
- os: linux
compiler: linux-clang40-release
env: CC='clang-4.0' CXX='clang++-4.0' BUILD_TYPE='Release'
addons: *clang40
- os: linux
compiler: linux-clang40-dev
env: CC='clang-4.0' CXX='clang++-4.0' BUILD_TYPE='Dev'
addons: *clang40
- os: linux
compiler: linux-clang50-release
env: CC='clang-5.0' CXX='clang++-5.0' BUILD_TYPE='Release'
addons: *clang50
- os: linux
compiler: linux-clang50-dev
env: CC='clang-5.0' CXX='clang++-5.0' BUILD_TYPE='Dev'
addons: *clang50
# Disabled because it creates false-positives on the old travis systems
# - os: linux
# compiler: linux-clang50-debug
# env: CC='clang-5.0' CXX='clang++-5.0' BUILD_TYPE='Debug'
# CXXFLAGS="-fsanitize=address,undefined,integer -fno-sanitize-recover=all -fno-omit-frame-pointer"
# LDFLAGS="-fsanitize=address,undefined,integer"
# # LSAN doesn't work on container-based system
# sudo: required
# addons: *clang50
# 2/ Linux GCC Builds
- os: linux
compiler: linux-gcc48-release
env: CC='gcc-4.8' CXX='g++-4.8' BUILD_TYPE='Release'
CXXFLAGS='-Wno-return-type'
addons: *gcc48
- os: linux
compiler: linux-gcc48-dev
env: CC='gcc-4.8' CXX='g++-4.8' BUILD_TYPE='Dev'
CXXFLAGS='-Wno-return-type'
addons: *gcc48
- os: linux
compiler: linux-gcc49-release
env: CC='gcc-4.9' CXX='g++-4.9' BUILD_TYPE='Release'
addons: *gcc49
- os: linux
compiler: linux-gcc49-dev
env: CC='gcc-4.9' CXX='g++-4.9' BUILD_TYPE='Dev'
addons: *gcc49
- os: linux
compiler: linux-gcc5-release
env: CC='gcc-5' CXX='g++-5' BUILD_TYPE='Release'
addons: *gcc5
- os: linux
compiler: linux-gcc5-dev
env: CC='gcc-5' CXX='g++-5' BUILD_TYPE='Dev'
addons: *gcc5
- os: linux
compiler: linux-gcc6-release
env: CC='gcc-6' CXX='g++-6' BUILD_TYPE='Release'
addons: *gcc6
- os: linux
compiler: linux-gcc6-dev
env: CC='gcc-6' CXX='g++-6' BUILD_TYPE='Dev'
addons: *gcc6
- os: linux
compiler: linux-gcc6-coverage
env: CC='gcc-6' CXX='g++-6' BUILD_TYPE='Coverage'
addons: *gcc6
# 3/ OSX Clang Builds
- os: osx
osx_image: xcode6.4
compiler: xcode64-clang-release
env: CC='clang' CXX='clang++' BUILD_TYPE='Release'
- os: osx
osx_image: xcode6.4
compiler: xcode64-clang-dev
env: CC='clang' CXX='clang++' BUILD_TYPE='Dev'
- os: osx
osx_image: xcode7
compiler: xcode7-clang-release
env: CC='clang' CXX='clang++' BUILD_TYPE='Release'
- os: osx
osx_image: xcode7
compiler: xcode7-clang-dev
env: CC='clang' CXX='clang++' BUILD_TYPE='Dev'
- os: osx
osx_image: xcode8.3
compiler: xcode8-clang-release
env: CC='clang' CXX='clang++' BUILD_TYPE='Release'
- os: osx
osx_image: xcode8.3
compiler: xcode8-clang-dev
env: CC='clang' CXX='clang++' BUILD_TYPE='Dev'
install:
- git clone --quiet --depth 1 https://github.com/mapbox/protozero.git ../protozero
- |
if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then
brew remove gdal
brew install cmake boost google-sparsehash gdal || true
fi
- cmake --version
before_script:
- cd ${TRAVIS_BUILD_DIR}
- git submodule update --init
- mkdir build && cd build
- cmake -LA .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DBUILD_DATA_TESTS=ON -DBUILD_WITH_CCACHE=1
script:
- make VERBOSE=1 && ctest --output-on-failure
after_success:
- |
if [ "${BUILD_TYPE}" = "Coverage" ]; then
curl -S -f https://codecov.io/bash -o codecov
chmod +x codecov
gcov-${CXX#g++-} -p $(find test/CMakeFiles -name '*.o')
./codecov -Z -c -X gcov -F unit_tests
gcov-${CXX#g++-} -p $(find test/data-tests -name '*.o')
./codecov -Z -c -X gcov -F data_tests
gcov-${CXX#g++-} -p $(find examples -name '*.o')
./codecov -Z -c -X gcov -F examples
fi
#-----------------------------------------------------------------------------

View File

@ -1,53 +0,0 @@
#-----------------------------------------------------------------------------
#
# Configuration for YouCompleteMe Vim plugin
#
# http://valloric.github.io/YouCompleteMe/
#
#-----------------------------------------------------------------------------
from os.path import realpath, dirname
basedir = dirname(realpath(__file__))
# some default flags
# for more information install clang-3.2-doc package and
# check UsersManual.html
flags = [
'-Werror',
'-Wall',
'-Wextra',
'-pedantic',
'-Wno-return-type',
'-Wno-unused-parameter',
'-Wno-unused-variable',
'-std=c++11',
# '-x' and 'c++' also required
# use 'c' for C projects
'-x',
'c++',
# workaround for https://github.com/Valloric/YouCompleteMe/issues/303
# also see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=800618
'-isystem',
'/usr/lib/ycmd/clang_includes/',
# libosmium include dirs
'-I%s/include' % basedir,
'-I%s/test/include' % basedir,
'-I%s/test/data-test/include' % basedir,
# include third party libraries
'-I/usr/include/gdal',
]
# youcompleteme is calling this function to get flags
# You can also set database for flags. Check: JSONCompilationDatabase.html in
# clang-3.2-doc package
def FlagsForFile( filename ):
return {
'flags': flags,
'do_cache': True
}

View File

@ -12,6 +12,468 @@ This project adheres to [Semantic Versioning](https://semver.org/).
### Fixed
## [2.20.0] - 2023-09-20
### Changed
* Optionally allow fractional seconds in timestamps in OSM files.
* Enable `posix_fadvise` usage on FreeBSD.
* Make parsing PBFs a bit less picky.
* Various small code cleanups.
### Fixed
* Don't use class template arguments on `GeometryFactory` constructor
definition.
## [2.19.0] - 2023-01-19
### Changed
* Mark RapidJSON support as deprecated.
* Update included Catch to v2.13.10.
* Remove deprecated BoolVector class.
* Remove deprecated NWRIdSet class.
* Remove deprecated AssemblerConfig constructor.
* Print start of offending string in overlong string exception.
* Implement `set_thread_name()` on FreeBSD.
* Some small code cleanups.
### Fixed
* Fix return type in `MembersDatabaseCommon::count_not_removed()`.
* Make bzip2 unit tests pass on musl-based systems.
* Fix bug in members database test case.
## [2.18.0] - 2022-02-07
### Changed
* Use `system_error` instead of `runtime_error` where it fits better.
* Remove `OSMIUM_NORETURN` macro. This hasn't been used in a while.
### Removed deprecated parts of the code
Several parts of libosmium have been marked deprecated, many of them for a very
long time. These are now removed:
* Sparsehash index class `osmium::index::map::SparseMemTable` as well as the
complete file `osmium/index/map/sparse_mem_table.hpp`.
* Callback functionality of the `osmium::memory::Buffer` class. The
`set_full_callback()` will not be available any more. See the source
for replacement options.
* Various `osmium::builder::build_*` functions in
`osmium/builder/builder_helper.hpp`. Use `osmium::builder::add_*`
functions instead. Removes `builder_helper.hpp`.
* `osmium::builder::Builder::add_item(const osmium::memory::Item* item)`.
Use the function of the same name taking a reference instead.
* `osmium::builder::OSMObject/ChangesetBuilder::add_user()`. Use
`set_user()` instead.
* `osmium::builder::ChangesetBuilder::bounds()` returning a modifiable
reference. Use `set_bounds()` instead.
* Several functions around `osmium::io::OutputIterator`.
* `osmium::Area::inner_ring_cbegin/cend()`, use `inner_rings()` instead.
* `osmium::RelationMember::ref()`, use `set_ref()` instead.
* Implicit conversion from `osmium::Timestamp` to `std::time_t`. Use
`seconds_since_epoch()` instead.
* `osmium::string_to_user_id()`, use `string_to_uid` instead.
* `osmium::static_cast_with_assert()` helper functions as well as the
complete include file `osmium/util/cast.hpp`.
* Some constructors of `osmium::util::MemoryMapping` and
`osmium::util::TypedMemoryMapping`. Use other constructor instead.
## [2.17.3] - 2022-01-19
### Fixed
* Removed possible deadlock when shutting down active Reader.
## [2.17.2] - 2021-12-16
### Changed
* Libosmium now supports being compiled in C++17 and C++20 mode. The minimum
version required is still C++11, but if you use libosmium in an C++17 or
C++20 application this should work properly.
* Switch from catch version 1 to catch2 as test framework.
* When `std::variant` is available (C++17 and above), libosmium will use that
instead of `boost::variant` reducing the dependencies a little bit.
* Removed various workaround that were needed for older MSVC compilers.
* Remove use of `boost::filter_iterator` and `boost::indirect_iterator`. The
removes the dependency on Boost Iterator.
* Examples now mostly use the somewhat cleaner `return` instead of
`std::exit()` to return an exit code from `main`.
* As always: Various small code cleanups.
### Fixed
* When ordering OSM objects (mostly use in the `CheckOrder` handler), the
smallest id possible (`INTMIN`) wasn't sorted correctly.
* Threading problem when reading files.
* Possible dereference of invalid iterator in legacy area assembler. This
only affects the legacy area assembler that takes old-style multipolygons
into account, so modern code that is not working with history data is not
affected.
* Fixed read from an empty queue when reading a file which could block
libosmium forever when an error was encountered while reading a file.
### Deprecated
Several parts of libosmium have been marked deprecated, many of them for a very
long time. These will not be part of the next version of libosmium:
* Sparsehash index class `osmium::index::map::SparseMemTable` as well as the
complete file `osmium/index/map/sparse_mem_table.hpp`.
* Callback functionality of the `osmium::memory::Buffer` class. The
`set_full_callback()` will not be available any more. See the source
for replacement options.
* Various `osmium::builder::build_*` functions in
`osmium/builder/builder_helper.hpp`. Use `osmium::builder::add_*`
functions instead. Removes `builder_helper.hpp`.
* `osmium::builder::Builder::add_item(const osmium::memory::Item* item)`.
Use the function of the same name taking a reference instead.
* `osmium::builder::OSMObject/ChangesetBuilder::add_user()`. Use
`set_user()` instead.
* `osmium::builder::ChangesetBuilder::bounds()` returning a modifiable
reference. Use `set_bounds()` instead.
* Several functions around `osmium::io::OutputIterator`.
* `osmium::Area::inner_ring_cbegin/cend()`, use `inner_rings()` instead.
* `osmium::RelationMember::ref()`, use `set_ref()` instead.
* Implicit conversion from `osmium::Timestamp` to `std::time_t`. Use
`seconds_since_epoch()` instead.
* `osmium::string_to_user_id()`, use `string_to_uid` instead.
* `osmium::static_cast_with_assert()` helper functions as well as the
complete include file `osmium/util/cast.hpp`.
* Some constructors of `osmium::util::MemoryMapping` and
`osmium::util::TypedMemoryMapping`. Use other constructor instead.
## [2.17.1] - 2021-10-05
### Added
* Add `osmium_tags_filter` example showing use of tags filter.
* Add `Writer::set_header()` function to set header after constructing.
### Changed
* Various improvements in PBF file reading make it slightly faster and less
CPU intensive.
* Since 2.17.0 Osmium will, when reading files, tell the kernel using
`fadvise` that it can remove pages from the buffer cache that are not
needed any more. This is usually beneficial, because the memory can be used
for something else. But if you are reading the same OSM file multiple times
at the same time or in short succession, it might be better to keep those
buffer pages. In that case you can set the environment variable
`OSMIUM_CLEAN_PAGE_CACHE_AFTER_READ` to `no` and Osmium will not call
`fadvise`. Set it to `yes` or anything else (or not set it at all) to get
the default behaviour.
* If the macro `OSMIUM_DEFINE_EXPORT` is defined, all exception classes used
by Osmium will get "tagged as exported" using `__declspec(dllexport)` when
using MSVC or `__attribute__ ((visibility("default")))` on other compilers.
This is needed in PyOsmium.
### Fixed
* Fix integer parser. IDs in OPL files can now be anything between -2^63 and
2^63-1.
## [2.17.0] - 2021-04-26
### Added
* Add "ids" output format. New IDS output format that is similar to
the OPL format, but only the entity type and id is written out.
* Add convenience functions `left()`, `right()`, `top()`, `bottom()` to
access `osmium::Box` boundaries.
* Add polygon output to WKB factory.
* Add functions to access storage from `node_locations_for_ways`
handler.
* Add flag `osmium::io::buffers_type` for telling the `Reader` class whether
you want buffers read to only contain a single type of OSM entity.
* Add convenient named `nodes()`, `ways()`, and `relations()` accessor
functions to `nwr_array` class.
* Add `DeltaDecode::value()` accessor function.
* Add variant of the `Buffer::purge_removed()` function which doesn't take
a callback parameter.
### Changed
* Different varint decoding for faster PBF decoding. This makes PBF
decoding about 15% faster.
* Several code optimmizations in (PBF) writer code that speed up
writing of OSM files considerably while using less CPU and spreading
the load on multiple CPUs.
* Use memset/memcpy instead of `std::fill_n` and `std::copy` in object
builder for some slight speedups.
* Ignore metadata setting on reader for history/change files. History
and change files must be read with metadata, because otherwise the
information is lost whether an object is visible or deleted. So
ignore this setting in that case.
* On Linux: Use fadvise() to tell kernel about our reading patterns:
1. Tell kernel that we are reading OSM files sequentially. This
should improve pre-fetching of data blocks.
2. Tell kernel that we are done with block so they can be released.
This means we don't hog the buffer cache for something that
will, in all likelyhood, not be needed any more.
* Use assert() instead of exception in "can not happen" situation in
the relations manager code.
* Various code cleanups.
### Fixed
* Test failure with `add_tag_list` on some systems.
* Test framework fix for aarch64 architecture.
* Remove undefined behaviour in bzip2 compression code.
* Rename some local variables to not shadow member functions.
* Wrap `osmium::util::MemoryMapping::unmap()` in try/catch on Windows
also because we call this from a noexcept function.
* Removed superfluous `std::forward`s and fixed code that called
`std::forward` multiple times on the same object.
* Fix in OPL parser which could lead to invalid data being generated.
* Fixed three bugs in O5M parser which could lead to an infinit loop
or segmentation faults.
## [2.16.0] - 2021-01-08
### Added
* The PBF reader and writer now understand PBF blobs compressed with the LZ4
compression algorithm in addition to the usual ZLIB compression (or no
compression at all). LZ4 is much faster to compress and uncompress. Use
by setting the `pbf_compression` output file format option to `lz4`. You
have to define `OSMIUM_WITH_LZ4` to enable this before including any
libosmium includes.
* The function `osmium::io::supported_pbf_compression_types` can now be used
to get a list of all PBF compression types supported.
* The output file option `pbf_compression_level` can now be set to an integer.
The range depends on the compression type used, 0-9 for zlib compression
and 1-65537 for lz4 compression.
* Adds `ptr_begin()`/`ptr_end()` functions to `ObjectPointerCollection` for
accessing the pointers instead of the underlying objects.
### Changed
* The `osmium::io::Writer::close()` function now returns the number of bytes
written to an OSM file if it is available (and 0 otherwise).
* Use stable sort when sorting `ObjectPointerCollection`.
### Fixed
* Various small fixes and cleanups.
## [2.15.6] - 2020-06-27
### Added
* Add `IdSetSmall::merge_sorted` function.
### Changed
* Little optimization for IdSetSmall: Don't add the same id twice in a row.
### Fixed
* Do not build areas with "recursion depth > 20". This happens when there
are complex multipolygon with many rings touching in single points. This
is a quick fix that hopefully keeps us going until we find a better
solution.
## [2.15.5] - 2020-04-21
### Added
* Additional constructor for `builder::attr::member_type(_string)` taking
char type making it even easier to generate test data.
* Allow single C string or `std::string` as argument for `builder::attr::_tag`.
Must contain key and value separated by the equal sign.
* New `builder::attr::_t()` function to set tags from comma-separated string.
* New `nwr_array` iterator.
* Support for the PROJ library has now been declared deprecated. The old
PROJ API (up to version PROJ 6) is currently still available, but will
be removed in a future version. Support for the new PROJ API will not be
in libosmium. See https://github.com/osmcode/osmium-proj for some code
that might help you if you need this.
### Changed
* Check how much space is available in file system before resizing memory
mapped file (not on Windows). This means we can, at least in some cases,
show an error message instead of crashing the program.
### Fixed
* Parsing coordinates in PBF files did not work correctly if an lat/lon
offset was specified (which almost never happens).
* Make OPL parser more strict: Attributes can only be specified once.
* Do not close stdout after writing OSM file to it.
## [2.15.4] - 2019-11-28
### Added
* Add osmium::Options::empty() for consistency with STL containers.
### Fixed
* Massive reduction of memory consumption in area assembly code. For some
very complex polygons memory usage can drop from multiple gigabytes to just
megabytes.
## [2.15.3] - 2019-09-16
### Added
* New header option "sorting" when reading and writing PBFs. If the header
option "sorting" is set to `Type_then_ID`, the optional header property
`Sort.Type_then_ID` is set on writing to PBF files. When reading PBF files
with this header property, the "sorting" header option is set accordingly.
### Fixed
* Do not propagate C++ exception through C code. We are using the Expat
XML parser, a C library. It calls callbacks in our code. When those
callbacks throw, the exception was propagated through the C code. This
did work in the tests, but that behaviour isn't guaranteed (C++
standard says it is implementation defined). This fixes it by catching
the exception and rethrowing it later.
## [2.15.2] - 2019-08-16
### Added
* Instead of handler classes, the `apply` function can now also take
lambdas (or objects from classes implementing `operator()`).
* Add swap, copy constructor and assignment operator to IdSetDense.
### Changed
* Enable use of the old proj API in proj version 6. This is a stopgap
solution until we find a better one.
* Better error messages when there is an error parsing a timestamp.
* Cleaned up a lot of code based on clang-tidy warnings.
* Ignore <bbox> or <bounds> subelement of <way> or <relation>. <bounds>
elements are created by Overpass API as subelements of ways or relations
when the "out bb" format is used. <bbox> subelements turn up in files
downloaded from http://download.openstreetmap.fr/replication . Libosmium
used to throw an error like "Unknown element in <way>: bbox". With this
commit, these subelements are ignored, ie. there is no error any more,
but the data is not read.
* Add swap, copy constructor and assignment operator to IdSetDense.
* Update included catch.hpp to 1.12.2.
* Retire use of `OSMIUM_NORETURN` macro. Use `[[noreturn]]` instead.
### Fixed
* Do not build areas with more than 100 locations where rings touch.
Places where rings touch are unusual for normal multipolygons and the
algorithm in libosmium that assembles multipolygons does not handle
them well. If there are too many touching points it becomes very slow.
This is not a problem for almost all multipolygons. As I am writing
this there are only three relations in the OSM database with more than
100 touching points, all of them rather weird boundaries in the US.
With this commit libosmium will simply ignore those areas to keep the
processing speed within reasonable bounds.
## [2.15.1] - 2019-02-26
### Added
* More tests.
* CMake config: also find clang-tidy-7.
### Changed
* Example and benchmark programs now don't crash with exceptions any more
but report them properly.
### Fixed
* Compile with NDEBUG in RelWithDebInfo mode.
* Correctly throw exception in `multimap::dump_as_list()`.
* Integer truncation on 32 bit systems in `MemoryUsage`.
* Exception specification on some functions.
* Forwarding references that might have hidden copy/move constructors.
## [2.15.0] - 2018-12-07
### Added
* Function `dump_as_array()` to dump sparse array indexes.
* Set the `xml_josm_upload` header option when reading XML files.
* New function `OSMObject::remove_tags()` marks tags on OSM objects as
removed.
* More tests.
### Changed
* When reading OSM files Libosmium now has less memory overhead, especially
when reading PBF files. This works by using more, but smaller buffers.
* The `TagsFilter` class is now based on the `TagsFilterBase` template
class which allows setting the result type. This allows the filter to
return more data depending on the rule that matched.
* Use enums for many constants instead of (static) const(expr) variables.
* Make `chunk_bits` in `IdSetDense` configurable.
* Hardcode `%lld` format instead of using `<cinttypes>` PRI macro.
* Update included gdalcpp to version 1.2.0.
### Fixed
* The gzip/bzip2 compression code was overhauled and is better tested now.
This fixes some bugs on Windows.
## [2.14.2] - 2018-07-23
### Fixed
* PBF reader and writer depended on byte order of system architecture.
* Removed an unreliable test that didn't work on some architectures.
## [2.14.1] - 2018-07-23
### Changed
* Libosmium now needs the newest Protozero version 1.6.3.
* Removes dependency on the utfcpp library for conversions between Unicode
code points and UTF-8. We have our own functions for this now. This also
gives us more control on where errors are thrown in this code.
* Add support for using the CRC32 implementation from the zlib library in
addition to the one from Boost. It is significantly faster and means we
have one less dependency, because zlib is needed anyway in almost all
programs using Osmium due to its use in the PBF format. Set macro
`OSMIUM_TEST_CRC_USE_BOOST` before compiling the tests, if you want to
run the tests with the boost library code, otherwise it will use the
zlib code. Note that to use this you have to change your software slightly,
see the documentation of the `CRC_zlib` class for details.
* Add a `clear_user()` function to OSMObject and Changeset which allows
removing the user name of an entity without re-creating it in a new buffer.
* In Osmium the 0 value of the Timestamp is used to denote the "invalid"
Timestamp, and its output using the `to_iso()` function is the empty
string. But this is the wrong output for OSM XML files, where a
timestamp that's not set should still be output as
1970-01-01T00:00:00Z. This version introduces a new `to_is_all()`
function which will do this and uses that function in the XML writer.
* Use `protozero::byteswap_inplace` instead of `htonl`/`ntohl`. Makes the
code simpler and also works on Windows.
* Marked `MultipolygonCollector` class as deprecated. Use the
`MultipolygonManager` class introduced in 2.13.0 instead.
* Lots of code cleanups especially around `assert`s. Libosmium checks out
clean with `clang-tidy` now. Some documentation updates.
### Fixed
* Fix compilation error when `fileno()` is a macro (as in OpenBSD 6.3).
* Make `Box` output consistent with the output of a single `Location`
and avoids problems with some locales.
## [2.14.0] - 2018-03-31
@ -823,7 +1285,24 @@ This project adheres to [Semantic Versioning](https://semver.org/).
Doxygen (up to version 1.8.8). This version contains a workaround to fix
this.
[unreleased]: https://github.com/osmcode/libosmium/compare/v2.14.0...HEAD
[unreleased]: https://github.com/osmcode/libosmium/compare/v2.20.0...HEAD
[2.20.0]: https://github.com/osmcode/libosmium/compare/v2.19.0...v2.20.0
[2.19.0]: https://github.com/osmcode/libosmium/compare/v2.18.9...v2.19.0
[2.18.0]: https://github.com/osmcode/libosmium/compare/v2.17.3...v2.18.0
[2.17.3]: https://github.com/osmcode/libosmium/compare/v2.17.2...v2.17.3
[2.17.2]: https://github.com/osmcode/libosmium/compare/v2.17.1...v2.17.2
[2.17.1]: https://github.com/osmcode/libosmium/compare/v2.17.0...v2.17.1
[2.17.0]: https://github.com/osmcode/libosmium/compare/v2.16.0...v2.17.0
[2.16.0]: https://github.com/osmcode/libosmium/compare/v2.15.6...v2.16.0
[2.15.6]: https://github.com/osmcode/libosmium/compare/v2.15.5...v2.15.6
[2.15.5]: https://github.com/osmcode/libosmium/compare/v2.15.4...v2.15.5
[2.15.4]: https://github.com/osmcode/libosmium/compare/v2.15.3...v2.15.4
[2.15.3]: https://github.com/osmcode/libosmium/compare/v2.15.2...v2.15.3
[2.15.2]: https://github.com/osmcode/libosmium/compare/v2.15.1...v2.15.2
[2.15.1]: https://github.com/osmcode/libosmium/compare/v2.15.0...v2.15.1
[2.15.0]: https://github.com/osmcode/libosmium/compare/v2.14.2...v2.15.0
[2.14.2]: https://github.com/osmcode/libosmium/compare/v2.14.1...v2.14.2
[2.14.1]: https://github.com/osmcode/libosmium/compare/v2.14.0...v2.14.1
[2.14.0]: https://github.com/osmcode/libosmium/compare/v2.13.1...v2.14.0
[2.13.1]: https://github.com/osmcode/libosmium/compare/v2.13.0...v2.13.1
[2.13.0]: https://github.com/osmcode/libosmium/compare/v2.12.2...v2.13.0

View File

@ -6,25 +6,40 @@
#
#-----------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
#-----------------------------------------------------------------------------
#
# Configurations
#
#-----------------------------------------------------------------------------
set(CMAKE_CXX_FLAGS_COVERAGE
"-g -O0 -fno-inline-functions -fno-inline --coverage ${extra_coverage_flags_}"
CACHE STRING "Flags used by the compiler during coverage builds.")
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
"--coverage"
CACHE STRING "Flags used by the linker during coverage builds.")
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo;MinSizeRel;Dev;Coverage"
CACHE STRING
"List of available configuration types"
FORCE)
#-----------------------------------------------------------------------------
#
# Project version
#
#-----------------------------------------------------------------------------
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo;MinSizeRel;Dev;Coverage"
CACHE STRING
"List of available configuration types"
FORCE)
project(libosmium)
set(LIBOSMIUM_VERSION_MAJOR 2)
set(LIBOSMIUM_VERSION_MINOR 14)
set(LIBOSMIUM_VERSION_MINOR 20)
set(LIBOSMIUM_VERSION_PATCH 0)
set(LIBOSMIUM_VERSION
@ -62,10 +77,11 @@ option(BUILD_BENCHMARKS "compile benchmark programs" ${dev_build})
option(BUILD_DATA_TESTS "compile data tests, please run them with ctest" ${data_test_build})
option(INSTALL_GDALCPP "also install gdalcpp headers" OFF)
option(INSTALL_UTFCPP "also install utfcpp headers" OFF)
option(WITH_PROFILING "add flags needed for profiling" OFF)
option(WITH_PROJ "build/test with proj" ON)
#-----------------------------------------------------------------------------
#
@ -101,14 +117,6 @@ endif()
# set(extra_coverage_flags_ "-fkeep-inline-functions")
#endif()
set(CMAKE_CXX_FLAGS_COVERAGE
"-g -O0 -fno-inline-functions -fno-inline --coverage ${extra_coverage_flags_}"
CACHE STRING "Flags used by the compiler during coverage builds.")
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
"--coverage"
CACHE STRING "Flags used by the linker during coverage builds.")
if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
if(BUILD_EXAMPLES OR BUILD_HEADERS OR BUILD_BENCHMARKS)
message(WARNING "Coverage builds don't work for anything but the tests")
@ -161,7 +169,11 @@ set(OSMIUM_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
include_directories(${OSMIUM_INCLUDE_DIR})
find_package(Osmium COMPONENTS io gdal geos proj sparsehash)
if(WITH_PROJ)
find_package(Osmium COMPONENTS lz4 io gdal geos proj)
else()
find_package(Osmium COMPONENTS lz4 io gdal geos)
endif()
# The find_package put the directory where it found the libosmium includes
# into OSMIUM_INCLUDE_DIRS. We remove it again, because we want to make
@ -200,11 +212,13 @@ endif()
#
#-----------------------------------------------------------------------------
if(MSVC)
set(USUAL_COMPILE_OPTIONS "/Ox")
set(DEV_COMPILE_OPTIONS "/Ox")
set(RWD_COMPILE_OPTIONS "/Ox /DNDEBUG")
# do not show warnings caused by missing .pdb files for libraries
set(USUAL_LINK_OPTIONS "/debug /ignore:4099")
else()
set(USUAL_COMPILE_OPTIONS "-O3 -g")
set(DEV_COMPILE_OPTIONS "-O3 -g")
set(RWD_COMPILE_OPTIONS "-O3 -g -DNDEBUG")
set(USUAL_LINK_OPTIONS "")
endif()
@ -212,7 +226,7 @@ if(WIN32)
add_definitions(-DWIN32 -D_WIN32 -DMSWIN32 -DBGDWIN32)
endif()
set(CMAKE_CXX_FLAGS_DEV "${USUAL_COMPILE_OPTIONS}"
set(CMAKE_CXX_FLAGS_DEV "${DEV_COMPILE_OPTIONS}"
CACHE STRING "Flags used by the compiler during developer builds."
FORCE)
@ -224,7 +238,7 @@ mark_as_advanced(
CMAKE_EXE_LINKER_FLAGS_DEV
)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${USUAL_COMPILE_OPTIONS}"
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${RWD_COMPILE_OPTIONS}"
CACHE STRING "Flags used by the compiler during RELWITHDEBINFO builds."
FORCE)
@ -318,9 +332,6 @@ if(CPPCHECK)
--force
-Uassert -DPROTOZERO_STRICT_API -DPROTOZERO_USE_BUILTIN_BSWAP -UPROTOZERO_USE_VIEW)
# cpp doesn't find system includes for some reason, suppress that report
set(CPPCHECK_OPTIONS ${CPPCHECK_OPTIONS} --suppress=missingIncludeSystem)
file(GLOB_RECURSE ALL_INCLUDES include/osmium/*.hpp)
file(GLOB ALL_EXAMPLES examples/*.cpp)
file(GLOB ALL_BENCHMARKS benchmarks/*.cpp)
@ -390,14 +401,14 @@ if(BUILD_HEADERS)
file(MAKE_DIRECTORY header_check)
foreach(hpp ${ALL_HPPS})
if(GDAL_FOUND OR NOT ((hpp STREQUAL "osmium/area/problem_reporter_ogr.hpp") OR (hpp STREQUAL "osmium/geom/ogr.hpp")))
if((GDAL_FOUND AND PROJ_FOUND) OR NOT ((hpp STREQUAL "osmium/area/problem_reporter_ogr.hpp") OR (hpp STREQUAL "osmium/geom/ogr.hpp") OR (hpp STREQUAL "osmium/geom/projection.hpp")))
string(REPLACE ".hpp" "" tmp ${hpp})
string(REPLACE "/" "__" libname ${tmp})
# Create a dummy .cpp file that includes the header file we want to
# check.
set(DUMMYCPP ${CMAKE_BINARY_DIR}/header_check/${libname}.cpp)
file(WRITE ${DUMMYCPP} "#include <${hpp}> // IWYU pragma: keep\n")
file(WRITE ${DUMMYCPP} "#define OSMIUM_UTIL_COMPATIBILITY_HPP\n#define OSMIUM_DEPRECATED\n#define OSMIUM_EXPORT\n#include <${hpp}> // IWYU pragma: keep\n")
# There is no way in CMake to just compile but not link a C++ file,
# so we pretend to build a library here.
@ -416,7 +427,7 @@ endif()
#
#-----------------------------------------------------------------------------
message(STATUS "Looking for clang-tidy")
find_program(CLANG_TIDY NAMES clang-tidy clang-tidy-6.0 clang-tidy-5.0)
find_program(CLANG_TIDY NAMES clang-tidy clang-tidy-16 clang-tidy-15 clang-tidy-14 clang-tidy-13 clang-tidy-12 clang-tidy-11)
if(CLANG_TIDY)
message(STATUS "Looking for clang-tidy - found ${CLANG_TIDY}")
@ -459,6 +470,7 @@ if(CLANG_TIDY)
add_custom_target(clang-tidy
${CLANG_TIDY}
-p ${CMAKE_BINARY_DIR}
"-extra-arg=-Wno-#pragma-messages"
${CT_CHECK_FILES}
)
else()
@ -480,11 +492,6 @@ if(INSTALL_GDALCPP)
install(FILES include/gdalcpp.hpp DESTINATION include)
endif()
if(INSTALL_UTFCPP)
install(FILES include/utf8.h DESTINATION include)
install(DIRECTORY include/utf8 DESTINATION include)
endif()
#-----------------------------------------------------------------------------
#

View File

@ -1,27 +0,0 @@
==== For utf8.h
Copyright 2006 Nemanja Trifunovic
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

View File

@ -89,11 +89,11 @@ between compilers due to different C++11 support.
## Operating systems
Usually all code must work on Linux, OSX, and Windows. Execptions are allowed
Usually all code must work on Linux, macOS, and Windows. Execptions are allowed
for some minor functionality, but please discuss this first.
When writing code and tests, care must be taken that everything works with the
CR line ending convention used on Linux and OSX and the CRLF line ending used
CR line ending convention used on Linux and macOS and the CRLF line ending used
on Windows. Note that `git` can be run with different settings regarding line
ending rewritings on different machines making things more difficult. Some
files have been "forced" to LF line endings using `.gitattributes` files.
@ -136,15 +136,7 @@ directory, some data tests in `test/osm-testdata` and tests of the examples in
`test/examples`. They are built by the default cmake config. Run `ctest` to
run them. We can always use more tests.
Tests are run automatically using the Travis (Linux/Mac) and Appveyor (Windows)
services. We automatically create coverage reports on Codevoc.io. Note that
the coverage percentages reported are not always accurate, because code that
is not used in tests at all will not necessarily end up in the binary and
the code coverage tool will not know it is there.
[![Travis Build Status](https://secure.travis-ci.org/osmcode/libosmium.svg)](https://travis-ci.org/osmcode/libosmium)
[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/github/osmcode/libosmium?svg=true)](https://ci.appveyor.com/project/Mapbox/libosmium)
[![Coverage Status](https://codecov.io/gh/osmcode/libosmium/branch/master/graph/badge.svg)](https://codecov.io/gh/osmcode/libosmium)
Tests are run automatically using Github Actions.
## Documenting the code

View File

@ -1,38 +1,34 @@
# Libosmium
http://osmcode.org/libosmium
https://osmcode.org/libosmium
A fast and flexible C++ library for working with OpenStreetMap data.
Libosmium works on Linux, Mac OSX and Windows.
Libosmium works on Linux, macOS and Windows.
[![Travis Build Status](https://secure.travis-ci.org/osmcode/libosmium.svg)](https://travis-ci.org/osmcode/libosmium)
[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/github/osmcode/libosmium?svg=true)](https://ci.appveyor.com/project/Mapbox/libosmium)
[![Coverage Status](https://codecov.io/gh/osmcode/libosmium/branch/master/graph/badge.svg)](https://codecov.io/gh/osmcode/libosmium)
[![Github Build Status](https://github.com/osmcode/libosmium/workflows/CI/badge.svg?branch=master)](https://github.com/osmcode/libosmium/actions)
[![Packaging status](https://repology.org/badge/tiny-repos/libosmium.svg)](https://repology.org/metapackage/libosmium)
Please see the [Libosmium manual](http://osmcode.org/libosmium/manual.html)
Please see the [Libosmium manual](https://osmcode.org/libosmium/manual.html)
for more details than this README can provide.
## Prerequisites
Because Libosmium uses many C++11 features you need a modern compiler and
standard C++ library. Osmium needs at least GCC 4.8 or clang (LLVM) 3.4.
(Some parts may work with older versions.)
You need a C++11 compiler and standard C++ library. Osmium needs at least GCC
4.8 or clang (LLVM) 3.4. (Some parts may work with older versions.)
Different parts of Libosmium (and the applications built on top of it) need
different libraries. You DO NOT NEED to install all of them, just install those
you need for your programs.
For details see the [list of
dependencies](http://osmcode.org/libosmium/manual.html#dependencies) in the
dependencies](https://osmcode.org/libosmium/manual.html#dependencies) in the
manual.
The following external (header-only) libraries are included in the libosmium
repository:
* [gdalcpp](https://github.com/joto/gdalcpp)
* [utfcpp](http://utfcpp.sourceforge.net/)
Note that [protozero](https://github.com/mapbox/protozero) was included in
earlier versions of libosmium, but isn't any more.
@ -69,8 +65,8 @@ cmake:
This will build the examples and tests. Call `ctest` to run the tests.
For more detals see the
[Building Libosmium](http://osmcode.org/libosmium/manual.html#building-libosmium)
For more details see the
[Building Libosmium](https://osmcode.org/libosmium/manual.html#building-libosmium)
chapter in the manual.
@ -85,20 +81,13 @@ git submodule update --init
This will enable additional tests.
See the
[Libosmium Manual](http://osmcode.org/libosmium/manual.html#running-tests)
[Libosmium Manual](https://osmcode.org/libosmium/manual.html#running-tests)
for instructions.
## Switching from the old Osmium
If you have been using the old version of Osmium at
https://github.com/joto/osmium you might want to read about the [changes
needed](http://osmcode.org/libosmium/manual.html#changes-from-old-versions-of-osmium).
## License
Libosmium is available under the Boost Software License. See LICENSE.txt.
Libosmium is available under the Boost Software License. See LICENSE.
## Authors

View File

@ -1,59 +0,0 @@
#-----------------------------------------------------------------------------
#
# Configuration for continuous integration service at appveyor.com
#
#-----------------------------------------------------------------------------
environment:
matrix:
- config: MSYS2
autocrlf: true
- config: Debug
autocrlf: true
- config: Release
autocrlf: true
- config: Debug
autocrlf: false
- config: Release
autocrlf: false
clone_depth: 1
# Operating system (build VM template)
os: Visual Studio 2015
platform: x64
# scripts that are called at very beginning, before repo cloning
init:
- git config --global core.autocrlf %autocrlf%
- git config --get core.autocrlf
clone_folder: c:\projects\libosmium
# The option --ask=20 is a workaround for a problem with the MSYS2 update
# process. Without it the following error is printed and the appveyor script
# halts: "msys2-runtime and catgets are in conflict. Remove catgets?"
# See also: https://github.com/Alexpux/MSYS2-packages/issues/1141
install:
- git submodule update --init
- cd c:\projects
- git clone --depth 1 https://github.com/mapbox/protozero
- if [%config%]==[MSYS2] (
C:\msys64\usr\bin\pacman --noconfirm --sync --refresh --refresh --sysupgrade --sysupgrade --ask=20
&& C:\msys64\usr\bin\pacman -Rc --noconfirm mingw-w64-x86_64-gcc-libs
)
build_script:
- cd c:\projects\libosmium
- if [%config%]==[MSYS2] (
build-msys2.bat
) else (
build-appveyor.bat
)
# remove garbage VS messages
# https://help.appveyor.com/discussions/problems/4569-the-target-_convertpdbfiles-listed-in-a-beforetargets-attribute-at-c-does-not-exist-in-the-project-and-will-be-ignored
before_build:
- del "C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets"

View File

@ -36,19 +36,26 @@ struct CountHandler : public osmium::handler::Handler {
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " OSMFILE\n";
std::exit(1);
return 1;
}
const std::string input_filename{argv[1]};
try {
const std::string input_filename{argv[1]};
osmium::io::Reader reader{input_filename};
osmium::io::Reader reader{input_filename};
CountHandler handler;
osmium::apply(reader, handler);
reader.close();
CountHandler handler;
osmium::apply(reader, handler);
reader.close();
std::cout << "Nodes: " << handler.nodes << '\n';
std::cout << "Ways: " << handler.ways << '\n';
std::cout << "Relations: " << handler.relations << '\n';
std::cout << "Nodes: " << handler.nodes << '\n';
std::cout << "Ways: " << handler.ways << '\n';
std::cout << "Relations: " << handler.relations << '\n';
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
return 1;
}
return 0;
}

View File

@ -39,17 +39,24 @@ struct CountHandler : public osmium::handler::Handler {
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " OSMFILE\n";
std::exit(1);
return 1;
}
const std::string input_filename{argv[1]};
try {
const std::string input_filename{argv[1]};
osmium::io::Reader reader{input_filename};
osmium::io::Reader reader{input_filename};
CountHandler handler;
osmium::apply(reader, handler);
reader.close();
CountHandler handler;
osmium::apply(reader, handler);
reader.close();
std::cout << "r_all=" << handler.all << " r_counter=" << handler.counter << '\n';
std::cout << "r_all=" << handler.all << " r_counter=" << handler.counter << '\n';
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
return 1;
}
return 0;
}

View File

@ -21,20 +21,27 @@ using location_handler_type = osmium::handler::NodeLocationsForWays<index_type>;
int main(int argc, char* argv[]) {
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " OSMFILE FORMAT\n";
std::exit(1);
return 1;
}
const std::string input_filename{argv[1]};
const std::string location_store{argv[2]};
try {
const std::string input_filename{argv[1]};
const std::string location_store{argv[2]};
osmium::io::Reader reader{input_filename};
osmium::io::Reader reader{input_filename};
const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance();
std::unique_ptr<index_type> index = map_factory.create_map(location_store);
location_handler_type location_handler{*index};
location_handler.ignore_errors();
const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance();
std::unique_ptr<index_type> index = map_factory.create_map(location_store);
location_handler_type location_handler{*index};
location_handler.ignore_errors();
osmium::apply(reader, location_handler);
reader.close();
osmium::apply(reader, location_handler);
reader.close();
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
return 1;
}
return 0;
}

View File

@ -28,15 +28,22 @@ struct GeomHandler : public osmium::handler::Handler {
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " OSMFILE\n";
std::exit(1);
return 1;
}
const std::string input_filename{argv[1]};
try {
const std::string input_filename{argv[1]};
osmium::io::Reader reader{input_filename};
osmium::io::Reader reader{input_filename};
GeomHandler handler;
osmium::apply(reader, handler);
reader.close();
GeomHandler handler;
osmium::apply(reader, handler);
reader.close();
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
return 1;
}
return 0;
}

View File

@ -41,104 +41,111 @@ using dynamic_location_handler_type = osmium::handler::NodeLocationsForWays<dyna
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " OSMFILE\n";
std::exit(1);
return 1;
}
const std::string input_filename{argv[1]};
try {
const std::string input_filename{argv[1]};
osmium::memory::Buffer buffer{osmium::io::read_file(input_filename)};
const osmium::memory::Buffer buffer{osmium::io::read_file(input_filename)};
const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance();
const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance();
const auto buffer_size = buffer.committed() / (1024 * 1024); // buffer size in MBytes
const int runs = std::max(10, static_cast<int>(5000ull / buffer_size));
const auto buffer_size = buffer.committed() / (1024UL * 1024UL); // buffer size in MBytes
const int runs = std::max(10, static_cast<int>(5000ULL / buffer_size));
std::cout << "input: filename=" << input_filename << " buffer_size=" << buffer_size << "MBytes\n";
std::cout << "runs: " << runs << "\n";
std::cout << "input: filename=" << input_filename << " buffer_size=" << buffer_size << "MBytes\n";
std::cout << "runs: " << runs << "\n";
double static_min = std::numeric_limits<double>::max();
double static_sum = 0;
double static_max = 0;
double static_min = std::numeric_limits<double>::max();
double static_sum = 0;
double static_max = 0;
double dynamic_min = std::numeric_limits<double>::max();
double dynamic_sum = 0;
double dynamic_max = 0;
double dynamic_min = std::numeric_limits<double>::max();
double dynamic_sum = 0;
double dynamic_max = 0;
for (int i = 0; i < runs; ++i) {
for (int i = 0; i < runs; ++i) {
{
// static index
osmium::memory::Buffer tmp_buffer{buffer.committed()};
for (const auto& item : buffer) {
tmp_buffer.add_item(item);
tmp_buffer.commit();
{
// static index
osmium::memory::Buffer tmp_buffer{buffer.committed()};
for (const auto& item : buffer) {
tmp_buffer.add_item(item);
tmp_buffer.commit();
}
static_index_type static_index;
static_location_handler_type static_location_handler{static_index};
const auto start = std::chrono::steady_clock::now();
osmium::apply(tmp_buffer, static_location_handler);
const auto end = std::chrono::steady_clock::now();
const double duration = std::chrono::duration<double, std::milli>(end - start).count();
if (duration < static_min) {
static_min = duration;
}
if (duration > static_max) {
static_max = duration;
}
static_sum += duration;
}
static_index_type static_index;
static_location_handler_type static_location_handler{static_index};
{
// dynamic index
osmium::memory::Buffer tmp_buffer{buffer.committed()};
for (const auto& item : buffer) {
tmp_buffer.add_item(item);
tmp_buffer.commit();
}
const auto start = std::chrono::steady_clock::now();
osmium::apply(tmp_buffer, static_location_handler);
const auto end = std::chrono::steady_clock::now();
std::unique_ptr<dynamic_index_type> index = map_factory.create_map(location_store);
dynamic_location_handler_type dynamic_location_handler{*index};
dynamic_location_handler.ignore_errors();
const double duration = std::chrono::duration<double, std::milli>(end - start).count();
const auto start = std::chrono::steady_clock::now();
osmium::apply(tmp_buffer, dynamic_location_handler);
const auto end = std::chrono::steady_clock::now();
if (duration < static_min) {
static_min = duration;
const double duration = std::chrono::duration<double, std::milli>(end - start).count();
if (duration < dynamic_min) {
dynamic_min = duration;
}
if (duration > dynamic_max) {
dynamic_max = duration;
}
dynamic_sum += duration;
}
if (duration > static_max) {
static_max = duration;
}
static_sum += duration;
}
{
// dynamic index
osmium::memory::Buffer tmp_buffer{buffer.committed()};
for (const auto& item : buffer) {
tmp_buffer.add_item(item);
tmp_buffer.commit();
}
const double static_avg = static_sum / runs;
const double dynamic_avg = dynamic_sum / runs;
std::unique_ptr<dynamic_index_type> index = map_factory.create_map(location_store);
dynamic_location_handler_type dynamic_location_handler{*index};
dynamic_location_handler.ignore_errors();
std::cout << "static min=" << static_min << "ms avg=" << static_avg << "ms max=" << static_max << "ms\n";
std::cout << "dynamic min=" << dynamic_min << "ms avg=" << dynamic_avg << "ms max=" << dynamic_max << "ms\n";
const auto start = std::chrono::steady_clock::now();
osmium::apply(tmp_buffer, dynamic_location_handler);
const auto end = std::chrono::steady_clock::now();
const double rfactor = 100.0;
const double diff_min = std::round((dynamic_min - static_min) * rfactor) / rfactor;
const double diff_avg = std::round((dynamic_avg - static_avg) * rfactor) / rfactor;
const double diff_max = std::round((dynamic_max - static_max) * rfactor) / rfactor;
const double duration = std::chrono::duration<double, std::milli>(end - start).count();
const double prfactor = 10.0;
const double percent_min = std::round((100.0 * diff_min / static_min) * prfactor) / prfactor;
const double percent_avg = std::round((100.0 * diff_avg / static_avg) * prfactor) / prfactor;
const double percent_max = std::round((100.0 * diff_max / static_max) * prfactor) / prfactor;
if (duration < dynamic_min) {
dynamic_min = duration;
}
if (duration > dynamic_max) {
dynamic_max = duration;
}
dynamic_sum += duration;
}
std::cout << "difference:";
std::cout << " min=" << diff_min << "ms (" << percent_min << "%)";
std::cout << " avg=" << diff_avg << "ms (" << percent_avg << "%)";
std::cout << " max=" << diff_max << "ms (" << percent_max << "%)\n";
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
return 1;
}
const double static_avg = static_sum / runs;
const double dynamic_avg = dynamic_sum / runs;
std::cout << "static min=" << static_min << "ms avg=" << static_avg << "ms max=" << static_max << "ms\n";
std::cout << "dynamic min=" << dynamic_min << "ms avg=" << dynamic_avg << "ms max=" << dynamic_max << "ms\n";
const double rfactor = 100.0;
const double diff_min = std::round((dynamic_min - static_min) * rfactor) / rfactor;
const double diff_avg = std::round((dynamic_avg - static_avg) * rfactor) / rfactor;
const double diff_max = std::round((dynamic_max - static_max) * rfactor) / rfactor;
const double prfactor = 10.0;
const double percent_min = std::round((100.0 * diff_min / static_min) * prfactor) / prfactor;
const double percent_avg = std::round((100.0 * diff_avg / static_avg) * prfactor) / prfactor;
const double percent_max = std::round((100.0 * diff_max / static_max) * prfactor) / prfactor;
std::cout << "difference:";
std::cout << " min=" << diff_min << "ms (" << percent_min << "%)";
std::cout << " avg=" << diff_avg << "ms (" << percent_avg << "%)";
std::cout << " max=" << diff_max << "ms (" << percent_max << "%)\n";
return 0;
}

View File

@ -14,22 +14,29 @@
int main(int argc, char* argv[]) {
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " INPUT-FILE OUTPUT-FILE\n";
std::exit(1);
return 1;
}
std::string input_filename{argv[1]};
std::string output_filename{argv[2]};
try {
const std::string input_filename{argv[1]};
const std::string output_filename{argv[2]};
osmium::io::Reader reader{input_filename};
osmium::io::File output_file{output_filename, "pbf"};
osmium::io::Header header;
osmium::io::Writer writer{output_file, header, osmium::io::overwrite::allow};
osmium::io::Reader reader{input_filename};
const osmium::io::File output_file{output_filename, "pbf"};
const osmium::io::Header header;
osmium::io::Writer writer{output_file, header, osmium::io::overwrite::allow};
while (osmium::memory::Buffer buffer = reader.read()) {
writer(std::move(buffer));
while (osmium::memory::Buffer buffer = reader.read()) { // NOLINT(bugprone-use-after-move) Bug in clang-tidy https://bugs.llvm.org/show_bug.cgi?id=36516
writer(std::move(buffer));
}
writer.close();
reader.close();
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
return 1;
}
writer.close();
reader.close();
return 0;
}

View File

@ -24,6 +24,11 @@ IF %ERRORLEVEL% NEQ 0 GOTO ERROR
SET PATH=C:/projects/bzip2.v140.1.0.6.9/build/native/bin/x64/%config%;%PATH%
nuget install lz4 -Version 1.3.1.2
IF %ERRORLEVEL% NEQ 0 GOTO ERROR
SET PATH=C:/projects/lz4.1.3.1.2/build/native/bin/x64/%config%;%PATH%
CD libosmium
ECHO config^: %config%
@ -46,13 +51,15 @@ SET CMAKE_CMD=cmake .. -LA -G "Visual Studio 14 Win64" ^
-DOsmium_DEBUG=TRUE ^
-DCMAKE_BUILD_TYPE=%config% ^
-DBUILD_HEADERS=OFF ^
-DBOOST_ROOT=C:/Libraries/boost_1_63_0 ^
-DBOOST_ROOT=C:/Libraries/boost_1_67_0 ^
-DZLIB_INCLUDE_DIR=C:/projects/zlib-vc140-static-64.1.2.11/lib/native/include ^
-DZLIB_LIBRARY=C:/projects/zlib-vc140-static-64.1.2.11/lib/native/libs/x64/static/%config%/zlibstatic.lib ^
-DEXPAT_INCLUDE_DIR=C:/projects/expat.v140.2.2.5/build/native/include ^
-DEXPAT_LIBRARY=C:/projects/expat.v140.2.2.5/build/native/lib/x64/%config%/libexpat%libpostfix%.lib ^
-DBZIP2_INCLUDE_DIR=C:/projects/bzip2.v140.1.0.6.9/build/native/include ^
-DBZIP2_LIBRARIES=C:/projects/bzip2.v140.1.0.6.9/build/native/lib/x64/%config%/libbz2%libpostfix%.lib
-DBZIP2_LIBRARIES=C:/projects/bzip2.v140.1.0.6.9/build/native/lib/x64/%config%/libbz2%libpostfix%.lib ^
-DLZ4_INCLUDE_DIR=C:/projects/lz4.1.3.1.2/build/native/include ^
-DLZ4_LIBRARY=C:/projects/lz4.1.3.1.2/build/native/lib/x64/%config%/liblz4%libpostfix%.lib
ECHO calling^: %CMAKE_CMD%
%CMAKE_CMD%
@ -68,7 +75,7 @@ msbuild libosmium.sln ^
/p:PlatformToolset=v140 %avlogger%
IF %ERRORLEVEL% NEQ 0 GOTO ERROR
ctest --output-on-failure -C %config% -E testdata-overview
ctest --output-on-failure -C %config%
IF %ERRORLEVEL% NEQ 0 GOTO ERROR
GOTO DONE

View File

@ -9,12 +9,18 @@ SET "PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH%"
echo %PATH%
echo "Installing MSYS2 packages..."
bash -lc "pacman -S --needed --noconfirm mingw-w64-x86_64-gcc mingw-w64-x86_64-geos mingw-w64-x86_64-cmake mingw-w64-x86_64-boost mingw-w64-x86_64-cppcheck mingw-w64-x86_64-doxygen mingw-w64-x86_64-gdb mingw-w64-x86_64-sparsehash mingw-w64-x86_64-gdal mingw-w64-x86_64-ruby mingw-w64-x86_64-libspatialite mingw-w64-x86_64-spatialite-tools mingw-w64-x86_64-clang-tools-extra"
bash -lc "pacman -S --needed --noconfirm mingw-w64-x86_64-postgresql mingw-w64-x86_64-netcdf mingw-w64-x86_64-crypto++"
bash -lc "pacman -Sy --needed --noconfirm mingw-w64-x86_64-gcc mingw-w64-x86_64-geos mingw-w64-x86_64-cmake mingw-w64-x86_64-boost mingw-w64-x86_64-cppcheck mingw-w64-x86_64-doxygen mingw-w64-x86_64-gdb mingw-w64-x86_64-gdal mingw-w64-x86_64-ruby mingw-w64-x86_64-libspatialite mingw-w64-x86_64-spatialite-tools mingw-w64-x86_64-clang-tools-extra"
bash -lc "pacman -Sy --needed --noconfirm mingw-w64-x86_64-postgresql mingw-w64-x86_64-netcdf mingw-w64-x86_64-crypto++"
call C:\msys64\mingw64\bin\gem.cmd install json
echo "Setting PROJ_LIB variable for correct PROJ.4 working"
REM Workaround for problem with spatialite (see https://github.com/osmcode/libosmium/issues/262)
copy /y C:\msys64\mingw64\bin\libreadline8.dll C:\msys64\mingw64\bin\libreadline7.dll
echo "Setting PROJ_LIB/DATA variable for correct PROJ.4 working"
set PROJ_LIB=c:\msys64\mingw64\share\proj
set PROJ_DATA=c:\msys64\mingw64\share\proj
set CXXFLAGS=-Wno-stringop-overflow
echo "Generating makefiles"
mkdir build

View File

@ -149,7 +149,7 @@ if(DEFINED GEM_INCLUDE_DIRS)
LIST(REMOVE_DUPLICATES GEM_INCLUDE_DIRS)
endif()
find_package_handle_standard_args(GEM
find_package_handle_standard_args(Gem
REQUIRED_VARS ${components_found_vars}
FAIL_MESSAGE "Could not find all required gems")

38
cmake/FindLZ4.cmake Normal file
View File

@ -0,0 +1,38 @@
find_path(LZ4_INCLUDE_DIR
NAMES lz4.h
DOC "lz4 include directory")
mark_as_advanced(LZ4_INCLUDE_DIR)
find_library(LZ4_LIBRARY
NAMES lz4 liblz4
DOC "lz4 library")
mark_as_advanced(LZ4_LIBRARY)
if (LZ4_INCLUDE_DIR)
file(STRINGS "${LZ4_INCLUDE_DIR}/lz4.h" _lz4_version_lines
REGEX "#define[ \t]+LZ4_VERSION_(MAJOR|MINOR|RELEASE)")
string(REGEX REPLACE ".*LZ4_VERSION_MAJOR *\([0-9]*\).*" "\\1" _lz4_version_major "${_lz4_version_lines}")
string(REGEX REPLACE ".*LZ4_VERSION_MINOR *\([0-9]*\).*" "\\1" _lz4_version_minor "${_lz4_version_lines}")
string(REGEX REPLACE ".*LZ4_VERSION_RELEASE *\([0-9]*\).*" "\\1" _lz4_version_release "${_lz4_version_lines}")
set(LZ4_VERSION "${_lz4_version_major}.${_lz4_version_minor}.${_lz4_version_release}")
unset(_lz4_version_major)
unset(_lz4_version_minor)
unset(_lz4_version_release)
unset(_lz4_version_lines)
endif ()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LZ4
REQUIRED_VARS LZ4_LIBRARY LZ4_INCLUDE_DIR
VERSION_VAR LZ4_VERSION)
if (LZ4_FOUND)
set(LZ4_INCLUDE_DIRS "${LZ4_INCLUDE_DIR}")
set(LZ4_LIBRARIES "${LZ4_LIBRARY}")
if (NOT TARGET LZ4::LZ4)
add_library(LZ4::LZ4 UNKNOWN IMPORTED)
set_target_properties(LZ4::LZ4 PROPERTIES
IMPORTED_LOCATION "${LZ4_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${LZ4_INCLUDE_DIR}")
endif ()
endif ()

View File

@ -33,7 +33,8 @@
# geos - include if you want to use any of the GEOS functions
# gdal - include if you want to use any of the OGR functions
# proj - include if you want to use any of the Proj.4 functions
# sparsehash - include if you use the sparsehash index
# sparsehash - include if you use the sparsehash index (deprecated!)
# lz4 - include support for LZ4 compression of PBF files
#
# You can check for success with something like this:
#
@ -71,6 +72,9 @@ find_path(OSMIUM_INCLUDE_DIR osmium/version.hpp
# Check libosmium version number
if(Osmium_FIND_VERSION)
if(NOT EXISTS "${OSMIUM_INCLUDE_DIR}/osmium/version.hpp")
message(FATAL_ERROR "Missing ${OSMIUM_INCLUDE_DIR}/osmium/version.hpp. Either your libosmium version is too old, or libosmium wasn't found in the place you said.")
endif()
file(STRINGS "${OSMIUM_INCLUDE_DIR}/osmium/version.hpp" _libosmium_version_define REGEX "#define LIBOSMIUM_VERSION_STRING")
if("${_libosmium_version_define}" MATCHES "#define LIBOSMIUM_VERSION_STRING \"([0-9.]+)\"")
set(_libosmium_version "${CMAKE_MATCH_1}")
@ -111,16 +115,23 @@ endif()
if(Osmium_USE_PBF)
find_package(ZLIB)
find_package(Threads)
find_package(Protozero 1.5.1)
find_package(Protozero 1.6.3)
if(Osmium_USE_LZ4)
find_package(LZ4 REQUIRED)
add_definitions(-DOSMIUM_WITH_LZ4)
endif()
list(APPEND OSMIUM_EXTRA_FIND_VARS ZLIB_FOUND Threads_FOUND PROTOZERO_INCLUDE_DIR)
if(ZLIB_FOUND AND Threads_FOUND AND PROTOZERO_FOUND)
list(APPEND OSMIUM_PBF_LIBRARIES
${ZLIB_LIBRARIES}
${LZ4_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
list(APPEND OSMIUM_INCLUDE_DIRS
${ZLIB_INCLUDE_DIR}
${LZ4_INCLUDE_DIRS}
${PROTOZERO_INCLUDE_DIR}
)
else()
@ -213,6 +224,7 @@ endif()
#----------------------------------------------------------------------
# Component 'sparsehash'
if(Osmium_USE_SPARSEHASH)
message(WARNING "Osmium: Use of Google SparseHash is deprecated. Please switch to a different index type.")
find_path(SPARSEHASH_INCLUDE_DIR google/sparsetable)
list(APPEND OSMIUM_EXTRA_FIND_VARS SPARSEHASH_INCLUDE_DIR)
@ -324,7 +336,7 @@ if(MSVC)
add_definitions(-DNOMINMAX -DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_WARNINGS)
endif()
if(APPLE)
if(APPLE AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# following only available from cmake 2.8.12:
# add_compile_options(-stdlib=libc++)
# so using this instead:

View File

@ -1,15 +0,0 @@
call "%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat" x86_amd64
set CMAKE_PREFIX_PATH=C:\PROJ
set VERSION=Debug
set TESTS=ON
set ALLHPPS=ON
set PREFIX=d:\libs18d
set BOOST_ROOT=d:\boost
cmake .. -G "Visual Studio 12 Win64" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=%PREFIX% -DBOOST_ROOT=%BOOST_ROOT% -DBoost_USE_STATIC_LIBS=ON -DBUILD_TESTING=%TESTS% -DBUILD_TRY_HPPS=%ALLHPPS$ -T CTP_Nov2013
msbuild /clp:Verbosity=minimal /nologo libosmium.sln /flp1:logfile=build_errors.txt;errorsonly /flp2:logfile=build_warnings.txt;warningsonly
set PATH=%PATH%;%PREFIX%/bin
del test\osm-testdata\*.db
del test\osm-testdata\*.json
if "%TESTS%"=="ON" ctest -VV >build_tests.log

View File

@ -4,7 +4,7 @@ data.
This is the API documentation that was automatically created from the
source code. For more information about the Osmium Library see
http://osmcode.org/libosmium .
https://osmcode.org/libosmium .
Osmium is free software and available under the Boost Software License.
The source code is available at https://github.com/osmcode/libosmium .

View File

@ -25,6 +25,7 @@ set(EXAMPLES
read
read_with_progress
road_length
tags_filter
tiles
CACHE STRING "Example programs"
)

View File

@ -29,6 +29,7 @@ them.
* `osmium_area_test`
* `osmium_create_pois`
* `osmium_tags_filter`
## Even more advanced examples

View File

@ -25,7 +25,6 @@
*/
#include <cstdio> // for std::printf
#include <cstdlib> // for std::exit
#include <iostream> // for std::cerr
#include <string> // for std::string
@ -58,12 +57,12 @@ using location_handler_type = osmium::handler::NodeLocationsForWays<index_type>;
class AmenityHandler : public osmium::handler::Handler {
// Print info about one amenity to stdout.
void print_amenity(const char* type, const char* name, const osmium::geom::Coordinates& c) {
static void print_amenity(const char* type, const char* name, const osmium::geom::Coordinates& c) {
std::printf("%8.4f,%8.4f %-15s %s\n", c.x, c.y, type, name ? name : "");
}
// Calculate the center point of a NodeRefList.
osmium::geom::Coordinates calc_center(const osmium::NodeRefList& nr_list) {
static osmium::geom::Coordinates calc_center(const osmium::NodeRefList& nr_list) {
// Coordinates simply store an X and Y coordinate pair as doubles.
// (Unlike osmium::Location which stores them more efficiently as
// 32 bit integers.) Use Coordinates when you want to do calculations
@ -75,15 +74,17 @@ class AmenityHandler : public osmium::handler::Handler {
c.y += nr.lat();
}
c.x /= nr_list.size();
c.y /= nr_list.size();
c.x /= static_cast<double>(nr_list.size());
c.y /= static_cast<double>(nr_list.size());
return c;
}
public:
void node(const osmium::Node& node) {
// The callback functions can be either static or not depending on whether
// you need to access any member variables of the handler.
static void node(const osmium::Node& node) {
// Getting a tag value can be expensive, because a list of tags has
// to be gone through and each tag has to be checked. So we store the
// result and reuse it.
@ -93,7 +94,9 @@ public:
}
}
void area(const osmium::Area& area) {
// The callback functions can be either static or not depending on whether
// you need to access any member variables of the handler.
static void area(const osmium::Area& area) {
const char* amenity = area.tags()["amenity"];
if (amenity) {
// Use the center of the first outer ring. Because we set
@ -110,62 +113,68 @@ public:
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " OSMFILE\n";
std::exit(1);
return 1;
}
// The input file
const osmium::io::File input_file{argv[1]};
try {
// The input file
const osmium::io::File input_file{argv[1]};
// Configuration for the multipolygon assembler. We disable the option to
// create empty areas when invalid multipolygons are encountered. This
// means areas created have a valid geometry and invalid multipolygons
// are simply ignored.
osmium::area::Assembler::config_type assembler_config;
assembler_config.create_empty_areas = false;
// Configuration for the multipolygon assembler. We disable the option to
// create empty areas when invalid multipolygons are encountered. This
// means areas created have a valid geometry and invalid multipolygons
// are simply ignored.
osmium::area::Assembler::config_type assembler_config;
assembler_config.create_empty_areas = false;
// Initialize the MultipolygonManager. Its job is to collect all
// relations and member ways needed for each area. It then calls an
// instance of the osmium::area::Assembler class (with the given config)
// to actually assemble one area.
osmium::area::MultipolygonManager<osmium::area::Assembler> mp_manager{assembler_config};
// Initialize the MultipolygonManager. Its job is to collect all
// relations and member ways needed for each area. It then calls an
// instance of the osmium::area::Assembler class (with the given config)
// to actually assemble one area.
osmium::area::MultipolygonManager<osmium::area::Assembler> mp_manager{assembler_config};
// We read the input file twice. In the first pass, only relations are
// read and fed into the multipolygon manager.
std::cerr << "Pass 1...\n";
osmium::relations::read_relations(input_file, mp_manager);
std::cerr << "Pass 1 done\n";
// We read the input file twice. In the first pass, only relations are
// read and fed into the multipolygon manager.
std::cerr << "Pass 1...\n";
osmium::relations::read_relations(input_file, mp_manager);
std::cerr << "Pass 1 done\n";
// The index storing all node locations.
index_type index;
// The index storing all node locations.
index_type index;
// The handler that stores all node locations in the index and adds them
// to the ways.
location_handler_type location_handler{index};
// The handler that stores all node locations in the index and adds them
// to the ways.
location_handler_type location_handler{index};
// If a location is not available in the index, we ignore it. It might
// not be needed (if it is not part of a multipolygon relation), so why
// create an error?
location_handler.ignore_errors();
// If a location is not available in the index, we ignore it. It might
// not be needed (if it is not part of a multipolygon relation), so why
// create an error?
location_handler.ignore_errors();
// Create our handler.
AmenityHandler data_handler;
// Create our handler.
AmenityHandler data_handler;
// On the second pass we read all objects and run them first through the
// node location handler and then the multipolygon manager. The manager
// will put the areas it has created into the "buffer" which are then
// fed through our handler.
//
// The read_meta::no option disables reading of meta data (such as version
// numbers, timestamps, etc.) which are not needed in this case. Disabling
// this can speed up your program.
std::cerr << "Pass 2...\n";
osmium::io::Reader reader{input_file, osmium::io::read_meta::no};
// On the second pass we read all objects and run them first through the
// node location handler and then the multipolygon manager. The manager
// will put the areas it has created into the "buffer" which are then
// fed through our handler.
//
// The read_meta::no option disables reading of meta data (such as version
// numbers, timestamps, etc.) which are not needed in this case. Disabling
// this can speed up your program.
std::cerr << "Pass 2...\n";
osmium::io::Reader reader{input_file, osmium::io::read_meta::no};
osmium::apply(reader, location_handler, data_handler, mp_manager.handler([&data_handler](const osmium::memory::Buffer& area_buffer) {
osmium::apply(area_buffer, data_handler);
}));
osmium::apply(reader, location_handler, data_handler, mp_manager.handler([&data_handler](const osmium::memory::Buffer& area_buffer) {
osmium::apply(area_buffer, data_handler);
}));
reader.close();
std::cerr << "Pass 2 done\n";
reader.close();
std::cerr << "Pass 2 done\n";
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
return 1;
}
}

View File

@ -25,7 +25,6 @@
*/
#include <cstdlib> // for std::exit
#include <cstring> // for std::strcmp
#include <iostream> // for std::cout, std::cerr
@ -93,106 +92,113 @@ void print_help() {
void print_usage(const char* prgname) {
std::cerr << "Usage: " << prgname << " [OPTIONS] OSMFILE\n";
std::exit(1);
}
int main(int argc, char* argv[]) {
if (argc > 1 && (!std::strcmp(argv[1], "-h") ||
!std::strcmp(argv[1], "--help"))) {
print_help();
std::exit(0);
return 0;
}
if (argc != 3) {
print_usage(argv[0]);
return 1;
}
// Initialize an empty DynamicHandler. Later it will be associated
// with one of the handlers. You can think of the DynamicHandler as
// a kind of "variant handler" or a "pointer handler" pointing to the
// real handler.
osmium::handler::DynamicHandler handler;
try {
// Initialize an empty DynamicHandler. Later it will be associated
// with one of the handlers. You can think of the DynamicHandler as
// a kind of "variant handler" or a "pointer handler" pointing to the
// real handler.
osmium::handler::DynamicHandler handler;
if (!std::strcmp(argv[1], "-w") || !std::strcmp(argv[1], "--dump-wkt")) {
handler.set<WKTDump>();
} else if (!std::strcmp(argv[1], "-o") || !std::strcmp(argv[1], "--dump-objects")) {
handler.set<osmium::handler::Dump>(std::cout);
} else {
print_usage(argv[0]);
}
osmium::io::File input_file{argv[2]};
// Configuration for the multipolygon assembler. Here the default settings
// are used, but you could change multiple settings.
osmium::area::Assembler::config_type assembler_config;
// Set up a filter matching only forests. This will be used to only build
// areas with matching tags.
osmium::TagsFilter filter{false};
filter.add_rule(true, "landuse", "forest");
filter.add_rule(true, "natural", "wood");
// Initialize the MultipolygonManager. Its job is to collect all
// relations and member ways needed for each area. It then calls an
// instance of the osmium::area::Assembler class (with the given config)
// to actually assemble one area. The filter parameter is optional, if
// it is not set, all areas will be built.
osmium::area::MultipolygonManager<osmium::area::Assembler> mp_manager{assembler_config, filter};
// We read the input file twice. In the first pass, only relations are
// read and fed into the multipolygon manager.
std::cerr << "Pass 1...\n";
osmium::relations::read_relations(input_file, mp_manager);
std::cerr << "Pass 1 done\n";
// Output the amount of main memory used so far. All multipolygon relations
// are in memory now.
std::cerr << "Memory:\n";
osmium::relations::print_used_memory(std::cerr, mp_manager.used_memory());
// The index storing all node locations.
index_type index;
// The handler that stores all node locations in the index and adds them
// to the ways.
location_handler_type location_handler{index};
// If a location is not available in the index, we ignore it. It might
// not be needed (if it is not part of a multipolygon relation), so why
// create an error?
location_handler.ignore_errors();
// On the second pass we read all objects and run them first through the
// node location handler and then the multipolygon collector. The collector
// will put the areas it has created into the "buffer" which are then
// fed through our "handler".
std::cerr << "Pass 2...\n";
osmium::io::Reader reader{input_file};
osmium::apply(reader, location_handler, mp_manager.handler([&handler](osmium::memory::Buffer&& buffer) {
osmium::apply(buffer, handler);
}));
reader.close();
std::cerr << "Pass 2 done\n";
// Output the amount of main memory used so far. All complete multipolygon
// relations have been cleaned up.
std::cerr << "Memory:\n";
osmium::relations::print_used_memory(std::cerr, mp_manager.used_memory());
// If there were multipolgyon relations in the input, but some of their
// members are not in the input file (which often happens for extracts)
// this will write the IDs of the incomplete relations to stderr.
std::vector<osmium::object_id_type> incomplete_relations_ids;
mp_manager.for_each_incomplete_relation([&](const osmium::relations::RelationHandle& handle){
incomplete_relations_ids.push_back(handle->id());
});
if (!incomplete_relations_ids.empty()) {
std::cerr << "Warning! Some member ways missing for these multipolygon relations:";
for (const auto id : incomplete_relations_ids) {
std::cerr << " " << id;
if (!std::strcmp(argv[1], "-w") || !std::strcmp(argv[1], "--dump-wkt")) {
handler.set<WKTDump>();
} else if (!std::strcmp(argv[1], "-o") || !std::strcmp(argv[1], "--dump-objects")) {
handler.set<osmium::handler::Dump>(std::cout);
} else {
print_usage(argv[0]);
return 1;
}
std::cerr << "\n";
const osmium::io::File input_file{argv[2]};
// Configuration for the multipolygon assembler. Here the default settings
// are used, but you could change multiple settings.
const osmium::area::Assembler::config_type assembler_config;
// Set up a filter matching only forests. This will be used to only build
// areas with matching tags.
osmium::TagsFilter filter{false};
filter.add_rule(true, "landuse", "forest");
filter.add_rule(true, "natural", "wood");
// Initialize the MultipolygonManager. Its job is to collect all
// relations and member ways needed for each area. It then calls an
// instance of the osmium::area::Assembler class (with the given config)
// to actually assemble one area. The filter parameter is optional, if
// it is not set, all areas will be built.
osmium::area::MultipolygonManager<osmium::area::Assembler> mp_manager{assembler_config, filter};
// We read the input file twice. In the first pass, only relations are
// read and fed into the multipolygon manager.
std::cerr << "Pass 1...\n";
osmium::relations::read_relations(input_file, mp_manager);
std::cerr << "Pass 1 done\n";
// Output the amount of main memory used so far. All multipolygon relations
// are in memory now.
std::cerr << "Memory:\n";
osmium::relations::print_used_memory(std::cerr, mp_manager.used_memory());
// The index storing all node locations.
index_type index;
// The handler that stores all node locations in the index and adds them
// to the ways.
location_handler_type location_handler{index};
// If a location is not available in the index, we ignore it. It might
// not be needed (if it is not part of a multipolygon relation), so why
// create an error?
location_handler.ignore_errors();
// On the second pass we read all objects and run them first through the
// node location handler and then the multipolygon collector. The collector
// will put the areas it has created into the "buffer" which are then
// fed through our "handler".
std::cerr << "Pass 2...\n";
osmium::io::Reader reader{input_file};
osmium::apply(reader, location_handler, mp_manager.handler([&handler](osmium::memory::Buffer&& buffer) {
osmium::apply(buffer, handler);
}));
reader.close();
std::cerr << "Pass 2 done\n";
// Output the amount of main memory used so far. All complete multipolygon
// relations have been cleaned up.
std::cerr << "Memory:\n";
osmium::relations::print_used_memory(std::cerr, mp_manager.used_memory());
// If there were multipolgyon relations in the input, but some of their
// members are not in the input file (which often happens for extracts)
// this will write the IDs of the incomplete relations to stderr.
std::vector<osmium::object_id_type> incomplete_relations_ids;
mp_manager.for_each_incomplete_relation([&](const osmium::relations::RelationHandle& handle){
incomplete_relations_ids.push_back(handle->id());
});
if (!incomplete_relations_ids.empty()) {
std::cerr << "Warning! Some member ways missing for these multipolygon relations:";
for (const auto id : incomplete_relations_ids) {
std::cerr << " " << id;
}
std::cerr << "\n";
}
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
return 1;
}
}

View File

@ -22,7 +22,6 @@
*/
#include <cstdlib> // for std::exit
#include <cstring> // for std::strcmp
#include <exception> // for std::exception
#include <iostream> // for std::cout, std::cerr
@ -66,7 +65,7 @@ class RewriteHandler : public osmium::handler::Handler {
// Copy all tags with two changes:
// * Do not copy "created_by" tags
// * Change "landuse=forest" into "natural=wood"
void copy_tags(osmium::builder::Builder& parent, const osmium::TagList& tags) {
static void copy_tags(osmium::builder::Builder& parent, const osmium::TagList& tags) {
// The TagListBuilder is used to create a list of tags. The parameter
// to create it is a reference to the builder of the object that
@ -150,12 +149,12 @@ public:
int main(int argc, char* argv[]) {
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " INFILE OUTFILE\n";
std::exit(1);
return 1;
}
// Get input and output file names from command line.
std::string input_file_name{argv[1]};
std::string output_file_name{argv[2]};
const std::string input_file_name{argv[1]};
const std::string output_file_name{argv[2]};
try {
// Initialize Reader
@ -196,8 +195,8 @@ int main(int argc, char* argv[]) {
reader.close();
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << "\n";
std::exit(1);
std::cerr << e.what() << '\n';
return 1;
}
}

View File

@ -17,7 +17,6 @@
*/
#include <cstdlib> // for std::exit
#include <cstring> // for std::strcmp
#include <exception> // for std::exception
#include <iostream> // for std::cout, std::cerr
@ -53,18 +52,18 @@ void print_help() {
void print_usage(const char* prgname) {
std::cerr << "Usage: " << prgname << " [OPTIONS] [INFILE [OUTFILE]]\n";
std::exit(0);
}
int main(int argc, char* argv[]) {
if (argc == 1) {
print_usage(argv[0]);
return 0;
}
if (argc > 1 && (!std::strcmp(argv[1], "-h") ||
!std::strcmp(argv[1], "--help"))) {
print_help();
std::exit(0);
return 0;
}
// Input and output format are empty by default. Later this will mean that
@ -83,6 +82,7 @@ int main(int argc, char* argv[]) {
input_format = argv[i];
} else {
print_usage(argv[0]);
return 1;
}
} else if (!std::strncmp(argv[i], "--from-format=", 14)) {
input_format = argv[i] + 14;
@ -92,6 +92,7 @@ int main(int argc, char* argv[]) {
output_format = argv[i];
} else {
print_usage(argv[0]);
return 1;
}
} else if (!std::strncmp(argv[i], "--to-format=", 12)) {
output_format = argv[i] + 12;
@ -101,6 +102,7 @@ int main(int argc, char* argv[]) {
output_file_name = argv[i];
} else {
print_usage(argv[0]);
return 1;
}
}
@ -135,7 +137,7 @@ int main(int argc, char* argv[]) {
// a time. This is much easier and faster than copying each object
// in the file. Buffers are moved around, so there is no cost for
// copying in memory.
while (osmium::memory::Buffer buffer = reader.read()) {
while (osmium::memory::Buffer buffer = reader.read()) { // NOLINT(bugprone-use-after-move) Bug in clang-tidy https://bugs.llvm.org/show_bug.cgi?id=36516
writer(std::move(buffer));
}
@ -147,8 +149,8 @@ int main(int argc, char* argv[]) {
reader.close();
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << "\n";
std::exit(1);
std::cerr << e.what() << '\n';
return 1;
}
}

View File

@ -18,7 +18,6 @@
*/
#include <cstdint> // for std::uint64_t
#include <cstdlib> // for std::exit
#include <iostream> // for std::cout, std::cerr
// Allow any format of input files (XML, PBF, ...)
@ -63,33 +62,39 @@ struct CountHandler : public osmium::handler::Handler {
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " OSMFILE\n";
std::exit(1);
return 1;
}
// The Reader is initialized here with an osmium::io::File, but could
// also be directly initialized with a file name.
osmium::io::File input_file{argv[1]};
osmium::io::Reader reader{input_file};
try {
// The Reader is initialized here with an osmium::io::File, but could
// also be directly initialized with a file name.
const osmium::io::File input_file{argv[1]};
osmium::io::Reader reader{input_file};
// Create an instance of our own CountHandler and push the data from the
// input file through it.
CountHandler handler;
osmium::apply(reader, handler);
// Create an instance of our own CountHandler and push the data from the
// input file through it.
CountHandler handler;
osmium::apply(reader, handler);
// You do not have to close the Reader explicitly, but because the
// destructor can't throw, you will not see any errors otherwise.
reader.close();
// You do not have to close the Reader explicitly, but because the
// destructor can't throw, you will not see any errors otherwise.
reader.close();
std::cout << "Nodes: " << handler.nodes << "\n";
std::cout << "Ways: " << handler.ways << "\n";
std::cout << "Relations: " << handler.relations << "\n";
std::cout << "Nodes: " << handler.nodes << "\n";
std::cout << "Ways: " << handler.ways << "\n";
std::cout << "Relations: " << handler.relations << "\n";
// Because of the huge amount of OSM data, some Osmium-based programs
// (though not this one) can use huge amounts of data. So checking actual
// memore usage is often useful and can be done easily with this class.
// (Currently only works on Linux, not OSX and Windows.)
osmium::MemoryUsage memory;
// Because of the huge amount of OSM data, some Osmium-based programs
// (though not this one) can use huge amounts of data. So checking actual
// memore usage is often useful and can be done easily with this class.
// (Currently only works on Linux, not macOS and Windows.)
const osmium::MemoryUsage memory;
std::cout << "\nMemory used: " << memory.peak() << " MBytes\n";
std::cout << "\nMemory used: " << memory.peak() << " MBytes\n";
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
return 1;
}
}

View File

@ -19,7 +19,6 @@
*/
#include <cstdlib> // for std::exit
#include <cstring> // for std::strcmp
#include <ctime> // for std::time
#include <exception> // for std::exception
@ -37,15 +36,15 @@
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " OUTFILE\n";
std::exit(1);
return 1;
}
// Get output file name from command line.
std::string output_file_name{argv[1]};
const std::string output_file_name{argv[1]};
// If output file name is "-", this means STDOUT. Set the OPL file type
// in this case. Otherwise take the file type from the file name suffix.
osmium::io::File output_file{output_file_name, output_file_name == "-" ? ".opl" : ""};
const osmium::io::File output_file{output_file_name, output_file_name == "-" ? ".opl" : ""};
try {
// Create a buffer where all objects will live. Use a sensible initial
@ -93,8 +92,8 @@ int main(int argc, char* argv[]) {
writer.close();
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << "\n";
std::exit(1);
std::cerr << e.what() << '\n';
return 1;
}
}

View File

@ -17,7 +17,6 @@
*/
#include <cstdlib> // for std::exit
#include <iostream> // for std::cout, std::cerr
#include <string> // for std::string
@ -34,51 +33,57 @@ int main(int argc, char* argv[]) {
if (argc < 2 || argc > 3) {
std::cerr << "Usage: " << argv[0] << " OSMFILE [TYPES]\n";
std::cerr << "TYPES can be any combination of 'n', 'w', 'r', and 'c' to indicate what types of OSM entities you want (default: all).\n";
std::exit(1);
return 1;
}
// Default is all entity types: nodes, ways, relations, and changesets
osmium::osm_entity_bits::type read_types = osmium::osm_entity_bits::all;
try {
// Default is all entity types: nodes, ways, relations, and changesets
osmium::osm_entity_bits::type read_types = osmium::osm_entity_bits::all;
// Get entity types from command line if there is a 2nd argument.
if (argc == 3) {
read_types = osmium::osm_entity_bits::nothing;
std::string types = argv[2];
if (types.find('n') != std::string::npos) {
read_types |= osmium::osm_entity_bits::node;
// Get entity types from command line if there is a 2nd argument.
if (argc == 3) {
read_types = osmium::osm_entity_bits::nothing;
const std::string types = argv[2];
if (types.find('n') != std::string::npos) {
read_types |= osmium::osm_entity_bits::node;
}
if (types.find('w') != std::string::npos) {
read_types |= osmium::osm_entity_bits::way;
}
if (types.find('r') != std::string::npos) {
read_types |= osmium::osm_entity_bits::relation;
}
if (types.find('c') != std::string::npos) {
read_types |= osmium::osm_entity_bits::changeset;
}
}
if (types.find('w') != std::string::npos) {
read_types |= osmium::osm_entity_bits::way;
}
if (types.find('r') != std::string::npos) {
read_types |= osmium::osm_entity_bits::relation;
}
if (types.find('c') != std::string::npos) {
read_types |= osmium::osm_entity_bits::changeset;
// Initialize Reader with file name and the types of entities we want to
// read.
osmium::io::Reader reader{argv[1], read_types};
// The file header can contain metadata such as the program that generated
// the file and the bounding box of the data.
osmium::io::Header header = reader.header();
std::cout << "HEADER:\n generator=" << header.get("generator") << "\n";
for (const auto& bbox : header.boxes()) {
std::cout << " bbox=" << bbox << "\n";
}
// Initialize Dump handler.
osmium::handler::Dump dump{std::cout};
// Read from input and send everything to Dump handler.
osmium::apply(reader, dump);
// You do not have to close the Reader explicitly, but because the
// destructor can't throw, you will not see any errors otherwise.
reader.close();
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
return 1;
}
// Initialize Reader with file name and the types of entities we want to
// read.
osmium::io::Reader reader{argv[1], read_types};
// The file header can contain metadata such as the program that generated
// the file and the bounding box of the data.
osmium::io::Header header = reader.header();
std::cout << "HEADER:\n generator=" << header.get("generator") << "\n";
for (const auto& bbox : header.boxes()) {
std::cout << " bbox=" << bbox << "\n";
}
// Initialize Dump handler.
osmium::handler::Dump dump{std::cout};
// Read from input and send everything to Dump handler.
osmium::apply(reader, dump);
// You do not have to close the Reader explicitly, but because the
// destructor can't throw, you will not see any errors otherwise.
reader.close();
}

View File

@ -29,7 +29,6 @@
*/
#include <cerrno> // for errno
#include <cstdlib> // for std::exit
#include <cstring> // for std::strerror
#include <iostream> // for std::cout, std::cerr
#include <string> // for std::string
@ -73,8 +72,7 @@ public:
explicit IndexFile(const std::string& filename) :
m_fd(::open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666)) { // NOLINT(hicpp-signed-bitwise)
if (m_fd < 0) {
std::cerr << "Can't open index file '" << filename << "': " << std::strerror(errno) << "\n";
std::exit(2);
throw std::system_error{errno, std::system_category(), "Can't open index file '" + filename};
}
#ifdef _WIN32
_setmode(m_fd, _O_BINARY);
@ -102,95 +100,101 @@ public:
int main(int argc, char* argv[]) {
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " OSMFILE DIR\n";
std::exit(2);
return 2;
}
const std::string input_file_name{argv[1]};
const std::string output_dir{argv[2]};
try {
const std::string input_file_name{argv[1]};
const std::string output_dir{argv[2]};
// Create output directory. Ignore the error if it already exists.
// Create output directory. Ignore the error if it already exists.
#ifndef _WIN32
const int result = ::mkdir(output_dir.c_str(), 0777);
const int result = ::mkdir(output_dir.c_str(), 0777);
#else
const int result = mkdir(output_dir.c_str());
const int result = mkdir(output_dir.c_str());
#endif
if (result == -1 && errno != EEXIST) {
std::cerr << "Problem creating directory '" << output_dir << "': " << std::strerror(errno) << "\n";
std::exit(2);
}
if (result == -1 && errno != EEXIST) {
std::cerr << "Problem creating directory '" << output_dir << "': " << std::strerror(errno) << "\n";
return 2;
}
// Create the output file which will contain our serialized OSM data
const std::string data_file{output_dir + "/data.osm.ser"};
const int data_fd = ::open(data_file.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666); // NOLINT(hicpp-signed-bitwise)
if (data_fd < 0) {
std::cerr << "Can't open data file '" << data_file << "': " << std::strerror(errno) << "\n";
std::exit(2);
}
// Create the output file which will contain our serialized OSM data
const std::string data_file{output_dir + "/data.osm.ser"};
const int data_fd = ::open(data_file.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666); // NOLINT(hicpp-signed-bitwise)
if (data_fd < 0) {
std::cerr << "Can't open data file '" << data_file << "': " << std::strerror(errno) << "\n";
return 2;
}
#ifdef _WIN32
_setmode(data_fd, _O_BINARY);
_setmode(data_fd, _O_BINARY);
#endif
// These indexes store the offset in the data file where each node, way,
// or relation is stored.
offset_index_type node_index;
offset_index_type way_index;
offset_index_type relation_index;
// These indexes store the offset in the data file where each node, way,
// or relation is stored.
offset_index_type node_index;
offset_index_type way_index;
offset_index_type relation_index;
// This handler will dump the internal data to disk using the given file
// descriptor while updating the indexes.
osmium::handler::DiskStore disk_store_handler{data_fd, node_index, way_index, relation_index};
// This handler will dump the internal data to disk using the given file
// descriptor while updating the indexes.
osmium::handler::DiskStore disk_store_handler{data_fd, node_index, way_index, relation_index};
// These indexes store the mapping from node id to the ids of the ways
// containing this node, and from node/way/relation ids to the ids of the
// relations containing those objects.
map_type map_node2way;
map_type map_node2relation;
map_type map_way2relation;
map_type map_relation2relation;
// These indexes store the mapping from node id to the ids of the ways
// containing this node, and from node/way/relation ids to the ids of the
// relations containing those objects.
map_type map_node2way;
map_type map_node2relation;
map_type map_way2relation;
map_type map_relation2relation;
// This handler will update the map indexes.
osmium::handler::ObjectRelations object_relations_handler{map_node2way, map_node2relation, map_way2relation, map_relation2relation};
// This handler will update the map indexes.
osmium::handler::ObjectRelations object_relations_handler{map_node2way, map_node2relation, map_way2relation, map_relation2relation};
// Read OSM data buffer by buffer.
osmium::io::Reader reader{input_file_name};
// Read OSM data buffer by buffer.
osmium::io::Reader reader{input_file_name};
while (osmium::memory::Buffer buffer = reader.read()) {
// Write buffer to disk and update indexes.
disk_store_handler(buffer);
while (osmium::memory::Buffer buffer = reader.read()) {
// Write buffer to disk and update indexes.
disk_store_handler(buffer);
// Update object relation index maps.
osmium::apply(buffer, object_relations_handler);
// Update object relation index maps.
osmium::apply(buffer, object_relations_handler);
}
reader.close();
// Write out node, way, and relation offset indexes to disk.
const IndexFile nodes_idx{output_dir + "/nodes.idx"};
node_index.dump_as_list(nodes_idx.fd());
const IndexFile ways_idx{output_dir + "/ways.idx"};
way_index.dump_as_list(ways_idx.fd());
const IndexFile relations_idx{output_dir + "/relations.idx"};
relation_index.dump_as_list(relations_idx.fd());
// Sort the maps (so later binary search will work on them) and write
// them to disk.
map_node2way.sort();
const IndexFile node2way_idx{output_dir + "/node2way.map"};
map_node2way.dump_as_list(node2way_idx.fd());
map_node2relation.sort();
const IndexFile node2relation_idx{output_dir + "/node2rel.map"};
map_node2relation.dump_as_list(node2relation_idx.fd());
map_way2relation.sort();
const IndexFile way2relation_idx{output_dir + "/way2rel.map"};
map_way2relation.dump_as_list(way2relation_idx.fd());
map_relation2relation.sort();
const IndexFile relation2relation_idx{output_dir + "/rel2rel.map"};
map_relation2relation.dump_as_list(relation2relation_idx.fd());
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
return 1;
}
reader.close();
// Write out node, way, and relation offset indexes to disk.
IndexFile nodes_idx{output_dir + "/nodes.idx"};
node_index.dump_as_list(nodes_idx.fd());
IndexFile ways_idx{output_dir + "/ways.idx"};
way_index.dump_as_list(ways_idx.fd());
IndexFile relations_idx{output_dir + "/relations.idx"};
relation_index.dump_as_list(relations_idx.fd());
// Sort the maps (so later binary search will work on them) and write
// them to disk.
map_node2way.sort();
IndexFile node2way_idx{output_dir + "/node2way.map"};
map_node2way.dump_as_list(node2way_idx.fd());
map_node2relation.sort();
IndexFile node2relation_idx{output_dir + "/node2rel.map"};
map_node2relation.dump_as_list(node2relation_idx.fd());
map_way2relation.sort();
IndexFile way2relation_idx{output_dir + "/way2rel.map"};
map_way2relation.dump_as_list(way2relation_idx.fd());
map_relation2relation.sort();
IndexFile relation2relation_idx{output_dir + "/rel2rel.map"};
map_relation2relation.dump_as_list(relation2relation_idx.fd());
}

View File

@ -22,7 +22,6 @@
*/
#include <algorithm> // for std::copy_if
#include <cstdlib> // for std::exit
#include <iostream> // for std::cout, std::cerr
// We want to read OSM files in XML format
@ -43,50 +42,56 @@
int main(int argc, char* argv[]) {
if (argc != 3) {
std::cout << "Usage: " << argv[0] << " INFILE OUTFILE\n";
std::exit(1);
return 1;
}
// The input file, deduce file format from file suffix.
osmium::io::File input_file{argv[1]};
try {
// The input file, deduce file format from file suffix.
const osmium::io::File input_file{argv[1]};
// The output file, force XML OSM file format.
osmium::io::File output_file{argv[2], "osm"};
// The output file, force XML OSM file format.
const osmium::io::File output_file{argv[2], "osm"};
// Initialize Reader for the input file.
// Read only changesets (will ignore nodes, ways, and
// relations if there are any).
osmium::io::Reader reader{input_file, osmium::osm_entity_bits::changeset};
// Initialize Reader for the input file.
// Read only changesets (will ignore nodes, ways, and
// relations if there are any).
osmium::io::Reader reader{input_file, osmium::osm_entity_bits::changeset};
// Get the header from the input file.
osmium::io::Header header = reader.header();
// Get the header from the input file.
osmium::io::Header header = reader.header();
// Set the "generator" on the header to ourselves.
header.set("generator", "osmium_filter_discussions");
// Set the "generator" on the header to ourselves.
header.set("generator", "osmium_filter_discussions");
// Initialize writer for the output file. Use the header from the input
// file for the output file. This will copy over some header information.
// The last parameter will tell the writer that it is allowed to overwrite
// an existing file. Without it, it will refuse to do so.
osmium::io::Writer writer{output_file, header, osmium::io::overwrite::allow};
// Initialize writer for the output file. Use the header from the input
// file for the output file. This will copy over some header information.
// The last parameter will tell the writer that it is allowed to overwrite
// an existing file. Without it, it will refuse to do so.
osmium::io::Writer writer{output_file, header, osmium::io::overwrite::allow};
// Create range of input iterators that will iterator over all changesets
// delivered from input file through the "reader".
auto input_range = osmium::io::make_input_iterator_range<osmium::Changeset>(reader);
// Create range of input iterators that will iterator over all changesets
// delivered from input file through the "reader".
auto input_range = osmium::io::make_input_iterator_range<osmium::Changeset>(reader);
// Create an output iterator writing through the "writer" object to the
// output file.
auto output_iterator = osmium::io::make_output_iterator(writer);
// Create an output iterator writing through the "writer" object to the
// output file.
auto output_iterator = osmium::io::make_output_iterator(writer);
// Copy all changesets from input to output that have at least one comment.
std::copy_if(input_range.begin(), input_range.end(), output_iterator, [](const osmium::Changeset& changeset) {
return changeset.num_comments() > 0;
});
// Copy all changesets from input to output that have at least one comment.
std::copy_if(input_range.begin(), input_range.end(), output_iterator, [](const osmium::Changeset& changeset) {
return changeset.num_comments() > 0;
});
// Explicitly close the writer and reader. Will throw an exception if
// there is a problem. If you wait for the destructor to close the writer
// and reader, you will not notice the problem, because destructors must
// not throw.
writer.close();
reader.close();
// Explicitly close the writer and reader. Will throw an exception if
// there is a problem. If you wait for the destructor to close the writer
// and reader, you will not notice the problem, because destructors must
// not throw.
writer.close();
reader.close();
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
return 1;
}
}

View File

@ -67,10 +67,10 @@ public:
IndexAccess(const IndexAccess&) = delete;
IndexAccess& operator=(const IndexAccess&) = delete;
IndexAccess(IndexAccess&&) = delete;
IndexAccess& operator=(IndexAccess&&) = delete;
IndexAccess(IndexAccess&&) noexcept = delete;
IndexAccess& operator=(IndexAccess&&) noexcept = delete;
virtual ~IndexAccess() = default;
virtual ~IndexAccess() noexcept = default;
virtual void dump() const = 0;
@ -97,8 +97,16 @@ public:
IndexAccess<TValue>(fd) {
}
IndexAccessDense(const IndexAccessDense&) = default;
IndexAccessDense& operator=(const IndexAccessDense&) = default;
IndexAccessDense(IndexAccessDense&&) noexcept = default;
IndexAccessDense& operator=(IndexAccessDense&&) noexcept = default;
~IndexAccessDense() noexcept override = default;
void dump() const override {
index_type index{this->fd()};
const index_type index{this->fd()};
for (std::size_t i = 0; i < index.size(); ++i) {
if (index.get(i) != TValue{}) {
@ -108,7 +116,7 @@ public:
}
bool search(const osmium::unsigned_object_id_type& key) const override {
index_type index{this->fd()};
const index_type index{this->fd()};
try {
TValue value = index.get(key);
@ -136,8 +144,16 @@ public:
IndexAccess<TValue>(fd) {
}
IndexAccessSparse(const IndexAccessSparse&) = default;
IndexAccessSparse& operator=(const IndexAccessSparse&) = default;
IndexAccessSparse(IndexAccessSparse&&) noexcept = default;
IndexAccessSparse& operator=(IndexAccessSparse&&) noexcept = default;
~IndexAccessSparse() noexcept override = default;
void dump() const override {
index_type index{this->fd()};
const index_type index{this->fd()};
for (const auto& element : index) {
std::cout << element.first << " " << element.second << "\n";
@ -148,7 +164,7 @@ public:
using element_type = typename index_type::element_type;
index_type index{this->fd()};
element_type elem{key, TValue{}};
const element_type elem{key, TValue{}};
const auto positions = std::equal_range(index.begin(),
index.end(),
elem,
@ -182,7 +198,7 @@ class Options {
bool m_array_format = false;
bool m_list_format = false;
void print_help() {
static void print_help() {
std::cout << "Usage: osmium_index_lookup [OPTIONS]\n\n"
<< "-h, --help Print this help message\n"
<< "-a, --array=FILE Read given index file in array format\n"
@ -193,7 +209,7 @@ class Options {
;
}
void print_usage(const char* prgname) {
static void print_usage(const char* prgname) {
std::cout << "Usage: " << prgname << " [OPTIONS]\n\n";
std::exit(0);
}
@ -331,14 +347,14 @@ int run(const IndexAccess<TValue>& index, const Options& options) {
int main(int argc, char* argv[]) {
// Parse command line options.
Options options{argc, argv};
const Options options{argc, argv};
// Open the index file.
const int fd = ::open(options.filename(), O_RDWR);
if (fd < 0) {
std::cerr << "Can not open file '" << options.filename()
<< "': " << std::strerror(errno) << '\n';
std::exit(2);
return 2;
}
#ifdef _WIN32
@ -363,8 +379,9 @@ int main(int argc, char* argv[]) {
const auto index = create<std::size_t>(options.dense_format(), fd);
return run(*index, options);
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << '\n';
std::exit(1);
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
return 1;
}
}

View File

@ -25,7 +25,6 @@
*/
#include <cerrno> // for errno
#include <cstdlib> // for std::exit
#include <cstring> // for strerror
#include <fcntl.h> // for open
#include <iostream> // for std::cout, std::cerr
@ -62,33 +61,39 @@ using location_handler_type = osmium::handler::NodeLocationsForWays<index_type>;
int main(int argc, char* argv[]) {
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " OSM_FILE CACHE_FILE\n";
std::exit(1);
return 1;
}
const std::string input_filename{argv[1]};
const std::string cache_filename{argv[2]};
try {
const std::string input_filename{argv[1]};
const std::string cache_filename{argv[2]};
// Construct Reader reading only nodes
osmium::io::Reader reader{input_filename, osmium::osm_entity_bits::node};
// Construct Reader reading only nodes
osmium::io::Reader reader{input_filename, osmium::osm_entity_bits::node};
// Initialize location index on disk creating a new file.
const int fd = ::open(cache_filename.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0666); // NOLINT(hicpp-signed-bitwise)
if (fd == -1) {
std::cerr << "Can not open location cache file '" << cache_filename << "': " << std::strerror(errno) << "\n";
std::exit(1);
}
// Initialize location index on disk creating a new file.
const int fd = ::open(cache_filename.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0666); // NOLINT(hicpp-signed-bitwise)
if (fd == -1) {
std::cerr << "Can not open location cache file '" << cache_filename << "': " << std::strerror(errno) << "\n";
return 1;
}
#ifdef _WIN32
_setmode(fd, _O_BINARY);
_setmode(fd, _O_BINARY);
#endif
index_type index{fd};
index_type index{fd};
// The handler that stores all node locations in the index.
location_handler_type location_handler{index};
// The handler that stores all node locations in the index.
location_handler_type location_handler{index};
// Feed all nodes through the location handler.
osmium::apply(reader, location_handler);
// Feed all nodes through the location handler.
osmium::apply(reader, location_handler);
// Explicitly close input so we get notified of any errors.
reader.close();
// Explicitly close input so we get notified of any errors.
reader.close();
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
return 1;
}
}

View File

@ -25,7 +25,6 @@
*/
#include <cerrno> // for errno
#include <cstdlib> // for std::exit
#include <cstring> // for strerror
#include <fcntl.h> // for open
#include <iostream> // for std::cout, std::cerr
@ -63,7 +62,9 @@ using location_handler_type = osmium::handler::NodeLocationsForWays<index_type>;
// ID and all nodes IDs and locations in those ways.
struct MyHandler : public osmium::handler::Handler {
void way(const osmium::Way& way) {
// The callback functions can be either static or not depending on whether
// you need to access any member variables of the handler.
static void way(const osmium::Way& way) {
std::cout << "way " << way.id() << "\n";
for (const auto& nr : way.nodes()) {
std::cout << " node " << nr.ref() << " " << nr.location() << "\n";
@ -75,34 +76,40 @@ struct MyHandler : public osmium::handler::Handler {
int main(int argc, char* argv[]) {
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " OSM_FILE CACHE_FILE\n";
std::exit(1);
}
const std::string input_filename{argv[1]};
const std::string cache_filename{argv[2]};
// Construct Reader reading only ways
osmium::io::Reader reader{input_filename, osmium::osm_entity_bits::way};
// Initialize location index on disk using an existing file
const int fd = ::open(cache_filename.c_str(), O_RDWR);
if (fd == -1) {
std::cerr << "Can not open location cache file '" << cache_filename << "': " << std::strerror(errno) << "\n";
return 1;
}
try {
const std::string input_filename{argv[1]};
const std::string cache_filename{argv[2]};
// Construct Reader reading only ways
osmium::io::Reader reader{input_filename, osmium::osm_entity_bits::way};
// Initialize location index on disk using an existing file
const int fd = ::open(cache_filename.c_str(), O_RDWR);
if (fd == -1) {
std::cerr << "Can not open location cache file '" << cache_filename << "': " << std::strerror(errno) << "\n";
return 1;
}
#ifdef _WIN32
_setmode(fd, _O_BINARY);
_setmode(fd, _O_BINARY);
#endif
index_type index{fd};
index_type index{fd};
// The handler that adds node locations from the index to the ways.
location_handler_type location_handler{index};
// The handler that adds node locations from the index to the ways.
location_handler_type location_handler{index};
// Feed all ways through the location handler and then our own handler.
MyHandler handler;
osmium::apply(reader, location_handler, handler);
// Feed all ways through the location handler and then our own handler.
MyHandler handler;
osmium::apply(reader, location_handler, handler);
// Explicitly close input so we get notified of any errors.
reader.close();
// Explicitly close input so we get notified of any errors.
reader.close();
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
return 1;
}
}

View File

@ -18,7 +18,6 @@
*/
#include <cstdlib> // for std::exit
#include <cstring> // for std::strncmp
#include <iostream> // for std::cout, std::cerr
@ -33,7 +32,7 @@
class NamesHandler : public osmium::handler::Handler {
void output_pubs(const osmium::OSMObject& object) {
static void output_pubs(const osmium::OSMObject& object) {
const osmium::TagList& tags = object.tags();
if (tags.has_tag("amenity", "pub")) {
@ -57,13 +56,17 @@ class NamesHandler : public osmium::handler::Handler {
public:
// The callback functions can be either static or not depending on whether
// you need to access any member variables of the handler.
// Nodes can be tagged amenity=pub.
void node(const osmium::Node& node) {
static void node(const osmium::Node& node) {
output_pubs(node);
}
// The callback functions can be either static or not depending on whether
// you need to access any member variables of the handler.
// Ways can be tagged amenity=pub, too (typically buildings).
void way(const osmium::Way& way) {
static void way(const osmium::Way& way) {
output_pubs(way);
}
@ -72,18 +75,24 @@ public:
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " OSMFILE\n";
std::exit(1);
return 1;
}
// Construct the handler defined above
NamesHandler names_handler;
try {
// Construct the handler defined above
NamesHandler names_handler;
// Initialize the reader with the filename from the command line and
// tell it to only read nodes and ways. We are ignoring multipolygon
// relations in this simple example.
osmium::io::Reader reader{argv[1], osmium::osm_entity_bits::node | osmium::osm_entity_bits::way};
// Initialize the reader with the filename from the command line and
// tell it to only read nodes and ways. We are ignoring multipolygon
// relations in this simple example.
osmium::io::Reader reader{argv[1], osmium::osm_entity_bits::node | osmium::osm_entity_bits::way};
// Apply input data to our own handler
osmium::apply(reader, names_handler);
// Apply input data to our own handler
osmium::apply(reader, names_handler);
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
return 1;
}
}

View File

@ -13,7 +13,6 @@
*/
#include <cstdlib> // for std::exit
#include <iostream> // for std::cerr
// Allow any format of input files (XML, PBF, ...)
@ -22,21 +21,27 @@
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " OSMFILE\n";
std::exit(1);
return 1;
}
// The Reader is initialized here with an osmium::io::File, but could
// also be directly initialized with a file name.
osmium::io::File input_file{argv[1]};
osmium::io::Reader reader{input_file};
try {
// The Reader is initialized here with an osmium::io::File, but could
// also be directly initialized with a file name.
const osmium::io::File input_file{argv[1]};
osmium::io::Reader reader{input_file};
// OSM data comes in buffers, read until there are no more.
while (osmium::memory::Buffer buffer = reader.read()) {
// do nothing
// OSM data comes in buffers, read until there are no more.
while (const osmium::memory::Buffer buffer = reader.read()) {
// do nothing
}
// You do not have to close the Reader explicitly, but because the
// destructor can't throw, you will not see any errors otherwise.
reader.close();
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
return 1;
}
// You do not have to close the Reader explicitly, but because the
// destructor can't throw, you will not see any errors otherwise.
reader.close();
}

View File

@ -16,7 +16,6 @@
*/
#include <cstdlib> // for std::exit
#include <iostream> // for std::cerr
// Allow any format of input files (XML, PBF, ...)
@ -29,28 +28,34 @@
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " OSMFILE\n";
std::exit(1);
return 1;
}
// The Reader is initialized here with an osmium::io::File, but could
// also be directly initialized with a file name.
osmium::io::File input_file{argv[1]};
osmium::io::Reader reader{input_file};
try {
// The Reader is initialized here with an osmium::io::File, but could
// also be directly initialized with a file name.
const osmium::io::File input_file{argv[1]};
osmium::io::Reader reader{input_file};
// Initialize progress bar, enable it only if STDERR is a TTY.
osmium::ProgressBar progress{reader.file_size(), osmium::isatty(2)};
// Initialize progress bar, enable it only if STDERR is a TTY.
osmium::ProgressBar progress{reader.file_size(), osmium::isatty(2)};
// OSM data comes in buffers, read until there are no more.
while (osmium::memory::Buffer buffer = reader.read()) {
// Update progress bar for each buffer.
progress.update(reader.offset());
// OSM data comes in buffers, read until there are no more.
while (const osmium::memory::Buffer buffer = reader.read()) {
// Update progress bar for each buffer.
progress.update(reader.offset());
}
// Progress bar is done.
progress.done();
// You do not have to close the Reader explicitly, but because the
// destructor can't throw, you will not see any errors otherwise.
reader.close();
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
return 1;
}
// Progress bar is done.
progress.done();
// You do not have to close the Reader explicitly, but because the
// destructor can't throw, you will not see any errors otherwise.
reader.close();
}

View File

@ -20,7 +20,6 @@
*/
#include <cstdlib> // for std::exit
#include <iostream> // for std::cout, std::cerr
// Allow any format of input files (XML, PBF, ...)
@ -65,28 +64,34 @@ struct RoadLengthHandler : public osmium::handler::Handler {
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " OSMFILE\n";
std::exit(1);
return 1;
}
// Initialize the reader with the filename from the command line and
// tell it to only read nodes and ways.
osmium::io::Reader reader{argv[1], osmium::osm_entity_bits::node | osmium::osm_entity_bits::way};
try {
// Initialize the reader with the filename from the command line and
// tell it to only read nodes and ways.
osmium::io::Reader reader{argv[1], osmium::osm_entity_bits::node | osmium::osm_entity_bits::way};
// The index to hold node locations.
index_type index;
// The index to hold node locations.
index_type index;
// The location handler will add the node locations to the index and then
// to the ways
location_handler_type location_handler{index};
// The location handler will add the node locations to the index and then
// to the ways
location_handler_type location_handler{index};
// Our handler defined above
RoadLengthHandler road_length_handler;
// Our handler defined above
RoadLengthHandler road_length_handler;
// Apply input data to first the location handler and then our own handler
osmium::apply(reader, location_handler, road_length_handler);
// Apply input data to first the location handler and then our own handler
osmium::apply(reader, location_handler, road_length_handler);
// Output the length. The haversine function calculates it in meters,
// so we first devide by 1000 to get kilometers.
std::cout << "Length: " << road_length_handler.length / 1000 << " km\n";
// Output the length. The haversine function calculates it in meters,
// so we first devide by 1000 to get kilometers.
std::cout << "Length: " << road_length_handler.length / 1000 << " km\n";
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
return 1;
}
}

View File

@ -0,0 +1,171 @@
/*
EXAMPLE osmium_filter
Filter OSM files
DEMONSTRATES USE OF:
* file input and output
* file types
* Osmium buffers
* Tags filter
SIMPLER EXAMPLES you might want to understand first:
* osmium_convert
LICENSE
The code in this example file is released into the Public Domain.
*/
#include <cstring> // for std::strcmp
#include <exception> // for std::exception
#include <iostream> // for std::cout, std::cerr
#include <string> // for std::string
// Allow any format of input files (XML, PBF, ...)
#include <osmium/io/any_input.hpp>
// Allow any format of output files (XML, PBF, ...)
#include <osmium/io/any_output.hpp>
#include <osmium/tags/taglist.hpp>
#include <osmium/tags/tags_filter.hpp>
void print_help() {
std::cout << "osmium_filter [OPTIONS] [INFILE [OUTFILE]]\n\n" \
<< "If INFILE or OUTFILE is not given stdin/stdout is assumed.\n" \
<< "File format is autodetected from file name suffix.\n" \
<< "Use -f and -t options to force file format.\n" \
<< "\nFile types:\n" \
<< " osm normal OSM file\n" \
<< " osc OSM change file\n" \
<< " osh OSM file with history information\n" \
<< "\nFile format:\n" \
<< " (default) XML encoding\n" \
<< " pbf binary PBF encoding\n" \
<< " opl OPL encoding\n" \
<< "\nFile compression\n" \
<< " gz compressed with gzip\n" \
<< " bz2 compressed with bzip2\n" \
<< "\nOptions:\n" \
<< " -h, --help This help message\n" \
<< " -f, --from-format=FORMAT Input format\n" \
<< " -t, --to-format=FORMAT Output format\n";
}
void print_usage(const char* prgname) {
std::cerr << "Usage: " << prgname << " [OPTIONS] [INFILE [OUTFILE]]\n";
}
int main(int argc, char* argv[]) {
if (argc == 1) {
print_usage(argv[0]);
return 0;
}
if (argc > 1 && (!std::strcmp(argv[1], "-h") ||
!std::strcmp(argv[1], "--help"))) {
print_help();
return 0;
}
// Input and output format are empty by default. Later this will mean that
// the format should be taken from the input and output file suffix,
// respectively.
std::string input_format;
std::string output_format;
std::string input_file_name;
std::string output_file_name;
for (int i = 1; i < argc; ++i) {
if (!std::strcmp(argv[i], "-f") || !std::strcmp(argv[i], "--from-format")) {
++i;
if (i < argc) {
input_format = argv[i];
} else {
print_usage(argv[0]);
return 1;
}
} else if (!std::strncmp(argv[i], "--from-format=", 14)) {
input_format = argv[i] + 14;
} else if (!std::strcmp(argv[i], "-t") || !std::strcmp(argv[i], "--to-format")) {
++i;
if (i < argc) {
output_format = argv[i];
} else {
print_usage(argv[0]);
return 1;
}
} else if (!std::strncmp(argv[i], "--to-format=", 12)) {
output_format = argv[i] + 12;
} else if (input_file_name.empty()) {
input_file_name = argv[i];
} else if (output_file_name.empty()) {
output_file_name = argv[i];
} else {
print_usage(argv[0]);
return 1;
}
}
// This declares the input and output files using either the suffix of
// the file names or the format in the 2nd argument. It does not yet open
// the files.
const osmium::io::File input_file{input_file_name, input_format};
const osmium::io::File output_file{output_file_name, output_format};
// Input and output files can be OSM data files (without history) or
// OSM history files. History files are detected if they use the '.osh'
// file suffix.
if ( input_file.has_multiple_object_versions() &&
!output_file.has_multiple_object_versions()) {
std::cerr << "Warning! You are converting from an OSM file with (potentially) several versions of the same object to one that is not marked as such.\n";
}
try {
// Initialize Reader
osmium::io::Reader reader{input_file};
// Get header from input file and change the "generator" setting to
// ourselves.
osmium::io::Header header = reader.header();
header.set("generator", "osmium_convert");
// Initialize Writer using the header from above and tell it that it
// is allowed to overwrite a possibly existing file.
osmium::io::Writer writer{output_file, header, osmium::io::overwrite::allow};
// Match highway=primary or highway=secondary
osmium::TagsFilter filter1{false};
filter1.add_rule(true, "highway", "primary");
filter1.add_rule(true, "highway", "secondary");
// Match oneway=yes
osmium::TagsFilter filter2{false};
filter2.add_rule(true, "oneway", "yes");
// Get all object matching both filters
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
for (const auto& object : buffer.select<osmium::OSMObject>()) {
if (osmium::tags::match_any_of(object.tags(), filter1) &&
osmium::tags::match_any_of(object.tags(), filter2)) {
writer(object);
}
}
}
// Explicitly close the writer and reader. Will throw an exception if
// there is a problem. If you wait for the destructor to close the writer
// and reader, you will not notice the problem, because destructors must
// not throw.
writer.close();
reader.close();
} catch (const std::exception& e) {
// All exceptions used by the Osmium library derive from std::exception.
std::cerr << e.what() << '\n';
return 1;
}
}

View File

@ -15,7 +15,7 @@
*/
#include <cstdlib> // for std::exit, std::atoi, std::atof
#include <cstdlib> // for std::atoi, std::atof
#include <iostream> // for std::cout, std::cerr
// The Location contains a longitude and latitude and is usually used inside
@ -33,14 +33,14 @@
int main(int argc, char* argv[]) {
if (argc != 4) {
std::cerr << "Usage: " << argv[0] << " ZOOM LON LAT\n";
std::exit(1);
return 1;
}
const int zoom = std::atoi(argv[1]); // NOLINT(cert-err34-c)
if (zoom < 0 || zoom > 30) {
std::cerr << "ERROR: Zoom must be between 0 and 30\n";
std::exit(1);
return 1;
}
osmium::Location location{};
@ -49,14 +49,14 @@ int main(int argc, char* argv[]) {
location.set_lat(argv[3]);
} catch (const osmium::invalid_location&) {
std::cerr << "ERROR: Location is invalid\n";
std::exit(1);
return 1;
}
// A location can store some invalid locations, ie locations outside the
// -180 to 180 and -90 to 90 degree range. This function checks for that.
if (!location.valid()) {
std::cerr << "ERROR: Location is invalid\n";
std::exit(1);
return 1;
}
std::cout << "WGS84: lon=" << location.lon() << " lat=" << location.lat() << "\n";
@ -68,7 +68,7 @@ int main(int argc, char* argv[]) {
// Create a tile at this location. This will also internally use the
// Mercator projection and then calculate the tile coordinates.
const osmium::geom::Tile tile{uint32_t(zoom), location};
const osmium::geom::Tile tile{static_cast<uint32_t>(zoom), location};
std::cout << "Tile: zoom=" << tile.z << " x=" << tile.x << " y=" << tile.y << "\n";
}

View File

@ -5,11 +5,11 @@
C++11 wrapper classes for GDAL/OGR.
Version 1.1.1
Version 1.3.0
https://github.com/joto/gdalcpp
Copyright 2015 Jochen Topf <jochen@topf.org>
Copyright 2015-2021 Jochen Topf <jochen@topf.org>
Boost Software License - Version 1.0 - August 17th, 2003
@ -37,17 +37,25 @@ DEALINGS IN THE SOFTWARE.
*/
#include <algorithm>
#include <memory>
#include <stdexcept>
#include <string>
#include <vector>
#include <gdal_priv.h>
#include <gdal_version.h>
#include <ogr_api.h>
#include <ogrsf_frmts.h>
#include <cstdint>
#include <algorithm>
#include <memory>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
#if defined(_MSC_VER)
# define GDALCPP_EXPORT __declspec(dllexport)
#else
# define GDALCPP_EXPORT __attribute__ ((visibility("default")))
#endif
namespace gdalcpp {
#if GDAL_VERSION_MAJOR >= 2
@ -61,7 +69,7 @@ namespace gdalcpp {
/**
* Exception thrown for all errors in this class.
*/
class gdal_error : public std::runtime_error {
class GDALCPP_EXPORT gdal_error : public std::runtime_error {
std::string m_driver;
std::string m_dataset;
@ -85,23 +93,23 @@ namespace gdalcpp {
m_error(error) {
}
const std::string& driver() const {
const std::string& driver() const noexcept {
return m_driver;
}
const std::string& dataset() const {
const std::string& dataset() const noexcept {
return m_dataset;
}
const std::string& layer() const {
const std::string& layer() const noexcept {
return m_layer;
}
const std::string& field() const {
const std::string& field() const noexcept {
return m_field;
}
OGRErr error() const {
OGRErr error() const noexcept {
return m_error;
}
@ -111,18 +119,26 @@ namespace gdalcpp {
struct init_wrapper {
#if GDAL_VERSION_MAJOR >= 2
init_wrapper() { GDALAllRegister(); }
init_wrapper() noexcept {
GDALAllRegister();
}
#else
init_wrapper() { OGRRegisterAll(); }
~init_wrapper() { OGRCleanupAll(); }
init_wrapper() noexcept {
OGRRegisterAll();
}
~init_wrapper() noexcept {
OGRCleanupAll();
}
#endif
};
}; // struct init_wrapper
struct init_library {
init_library() {
static init_wrapper iw;
}
};
}; // struct init_library
class Driver : private init_library {
@ -138,11 +154,13 @@ namespace gdalcpp {
m_driver(OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(driver_name.c_str())) {
#endif
if (!m_driver) {
throw gdal_error(std::string("unknown driver: '") + driver_name + "'", OGRERR_NONE, driver_name);
throw gdal_error{std::string{"unknown driver: '"} + driver_name + "'",
OGRERR_NONE,
driver_name};
}
}
gdal_driver_type& get() const {
gdal_driver_type& get() const noexcept {
return *m_driver;
}
@ -155,14 +173,14 @@ namespace gdalcpp {
Options(const std::vector<std::string>& options) :
m_options(options),
m_ptrs(new const char*[options.size()+1]) {
m_ptrs(new const char*[options.size() + 1]) {
std::transform(m_options.begin(), m_options.end(), m_ptrs.get(), [&](const std::string& s) {
return s.data();
});
m_ptrs[options.size()] = nullptr;
}
char** get() const {
char** get() const noexcept {
return const_cast<char**>(m_ptrs.get());
}
@ -178,33 +196,37 @@ namespace gdalcpp {
SRS() :
m_spatial_reference() {
auto result = m_spatial_reference.SetWellKnownGeogCS("WGS84");
const auto result = m_spatial_reference.SetWellKnownGeogCS("CRS84");
if (result != OGRERR_NONE) {
throw gdal_error(std::string("can not initialize spatial reference system WGS84"), result);
throw gdal_error{std::string{"can not initialize spatial reference system WGS84"},
result};
}
}
explicit SRS(int epsg) :
m_spatial_reference() {
auto result = m_spatial_reference.importFromEPSG(epsg);
const auto result = m_spatial_reference.importFromEPSG(epsg);
if (result != OGRERR_NONE) {
throw gdal_error(std::string("can not initialize spatial reference system for EPSG:") + std::to_string(epsg), result);
throw gdal_error{std::string{"can not initialize spatial reference system for EPSG:"} + std::to_string(epsg),
result};
}
}
explicit SRS(const char* name) :
m_spatial_reference() {
auto result = m_spatial_reference.importFromProj4(name);
const auto result = m_spatial_reference.importFromProj4(name);
if (result != OGRERR_NONE) {
throw gdal_error(std::string("can not initialize spatial reference system '") + name + "'", result);
throw gdal_error{std::string{"can not initialize spatial reference system '"} + name + "'",
result};
}
}
explicit SRS(const std::string& name) :
m_spatial_reference() {
auto result = m_spatial_reference.importFromProj4(name.c_str());
const auto result = m_spatial_reference.importFromProj4(name.c_str());
if (result != OGRERR_NONE) {
throw gdal_error(std::string("can not initialize spatial reference system '") + name + "'", result);
throw gdal_error{std::string{"can not initialize spatial reference system '"} + name + "'",
result};
}
}
@ -212,11 +234,11 @@ namespace gdalcpp {
m_spatial_reference(spatial_reference) {
}
OGRSpatialReference& get() {
OGRSpatialReference& get() noexcept {
return m_spatial_reference;
}
const OGRSpatialReference& get() const {
const OGRSpatialReference& get() const noexcept {
return m_spatial_reference;
}
@ -257,11 +279,14 @@ namespace gdalcpp {
m_dataset(detail::Driver(driver_name).get().CreateDataSource(dataset_name.c_str(), m_options.get())) {
#endif
if (!m_dataset) {
throw gdal_error(std::string("failed to create dataset '") + dataset_name + "'", OGRERR_NONE, driver_name, dataset_name);
throw gdal_error{std::string{"failed to create dataset '"} + dataset_name + "'",
OGRERR_NONE,
driver_name,
dataset_name};
}
}
~Dataset() {
~Dataset() noexcept {
try {
if (m_edit_count > 0) {
commit_transaction();
@ -270,24 +295,24 @@ namespace gdalcpp {
}
}
const std::string& driver_name() const {
const std::string& driver_name() const noexcept {
return m_driver_name;
}
const std::string& dataset_name() const {
const std::string& dataset_name() const noexcept {
return m_dataset_name;
}
gdal_dataset_type& get() const {
gdal_dataset_type& get() const noexcept {
return *m_dataset;
}
SRS& srs() {
SRS& srs() noexcept {
return m_srs;
}
void exec(const char* sql) {
auto result = m_dataset->ExecuteSQL(sql, nullptr, nullptr);
const auto result = m_dataset->ExecuteSQL(sql, nullptr, nullptr);
if (result) {
m_dataset->ReleaseResultSet(result);
}
@ -334,7 +359,7 @@ namespace gdalcpp {
}
}
Dataset& enable_auto_transactions(uint64_t edits = 100000) {
Dataset& enable_auto_transactions(uint64_t edits = 100000) noexcept {
m_max_edit_count = edits;
return *this;
}
@ -362,20 +387,23 @@ namespace gdalcpp {
m_dataset(dataset),
m_layer(dataset.get().CreateLayer(layer_name.c_str(), &dataset.srs().get(), type, m_options.get())) {
if (!m_layer) {
throw gdal_error(std::string("failed to create layer '") + layer_name + "'", OGRERR_NONE,
dataset.driver_name(), dataset.dataset_name(), layer_name);
throw gdal_error{std::string{"failed to create layer '"} + layer_name + "'",
OGRERR_NONE,
dataset.driver_name(),
dataset.dataset_name(),
layer_name};
}
}
OGRLayer& get() {
OGRLayer& get() noexcept {
return *m_layer;
}
const OGRLayer& get() const {
const OGRLayer& get() const noexcept {
return *m_layer;
}
Dataset& dataset() const {
Dataset& dataset() const noexcept {
return m_dataset;
}
@ -389,8 +417,12 @@ namespace gdalcpp {
field.SetPrecision(precision);
if (m_layer->CreateField(&field) != OGRERR_NONE) {
throw gdal_error(std::string("failed to create field '") + field_name + "' in layer '" + name() + "'", OGRERR_NONE,
m_dataset.driver_name(), m_dataset.dataset_name(), name(), field_name);
throw gdal_error{std::string{"failed to create field '"} + field_name + "' in layer '" + name() + "'",
OGRERR_NONE,
m_dataset.driver_name(),
m_dataset.dataset_name(),
name(),
field_name};
}
return *this;
@ -398,18 +430,25 @@ namespace gdalcpp {
void create_feature(OGRFeature* feature) {
dataset().prepare_edit();
OGRErr result = m_layer->CreateFeature(feature);
const auto result = m_layer->CreateFeature(feature);
if (result != OGRERR_NONE) {
throw gdal_error(std::string("creating feature in layer '") + name() + "' failed", result, dataset().driver_name(), dataset().dataset_name());
throw gdal_error{std::string{"creating feature in layer '"} + name() + "' failed",
result,
dataset().driver_name(),
dataset().dataset_name()};
}
dataset().finalize_edit();
}
Layer& start_transaction() {
#if GDAL_VERSION_MAJOR < 2
OGRErr result = m_layer->StartTransaction();
const auto result = m_layer->StartTransaction();
if (result != OGRERR_NONE) {
throw gdal_error(std::string("starting transaction on layer '") + name() + "' failed", result, m_dataset.driver_name(), m_dataset.dataset_name(), name());
throw gdal_error{std::string{"starting transaction on layer '"} + name() + "' failed",
result,
m_dataset.driver_name(),
m_dataset.dataset_name(),
name()};
}
#endif
return *this;
@ -417,9 +456,13 @@ namespace gdalcpp {
Layer& commit_transaction() {
#if GDAL_VERSION_MAJOR < 2
OGRErr result = m_layer->CommitTransaction();
const auto result = m_layer->CommitTransaction();
if (result != OGRERR_NONE) {
throw gdal_error(std::string("committing transaction on layer '") + name() + "' failed", result, m_dataset.driver_name(), m_dataset.dataset_name(), name());
throw gdal_error{std::string{"committing transaction on layer '"} + name() + "' failed",
result,
m_dataset.driver_name(),
m_dataset.dataset_name(),
name()};
}
#endif
return *this;
@ -446,11 +489,14 @@ namespace gdalcpp {
m_layer(layer),
m_feature(OGRFeature::CreateFeature(m_layer.get().GetLayerDefn())) {
if (!m_feature) {
throw std::bad_alloc();
throw std::bad_alloc{};
}
OGRErr result = m_feature->SetGeometryDirectly(geometry.release());
const auto result = m_feature->SetGeometryDirectly(geometry.release());
if (result != OGRERR_NONE) {
throw gdal_error(std::string("setting feature geometry in layer '") + m_layer.name() + "' failed", result, m_layer.dataset().driver_name(), m_layer.dataset().dataset_name());
throw gdal_error{std::string{"setting feature geometry in layer '"} + m_layer.name() + "' failed",
result,
m_layer.dataset().driver_name(),
m_layer.dataset().dataset_name()};
}
}
@ -458,13 +504,13 @@ namespace gdalcpp {
m_layer.create_feature(m_feature.get());
}
template <class T>
template <typename T>
Feature& set_field(int n, T&& arg) {
m_feature->SetField(n, std::forward<T>(arg));
return *this;
}
template <class T>
template <typename T>
Feature& set_field(const char* name, T&& arg) {
m_feature->SetField(name, std::forward<T>(arg));
return *this;
@ -474,4 +520,6 @@ namespace gdalcpp {
} // namespace gdalcpp
#undef GDALCPP_EXPORT
#endif // GDALCPP_HPP

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -213,7 +213,7 @@ namespace osmium {
// Now create the Area object and add the attributes and tags
// from the relation.
bool okay = create_area(out_buffer, relation, members);
const bool okay = create_area(out_buffer, relation, members);
if (okay) {
out_buffer.commit();
} else {

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -33,8 +33,6 @@ DEALINGS IN THE SOFTWARE.
*/
#include <osmium/util/compatibility.hpp>
namespace osmium {
namespace area {
@ -126,25 +124,6 @@ namespace osmium {
AssemblerConfig() noexcept = default;
/**
* Constructor
* @deprecated Use default constructor and set values afterwards.
*/
explicit AssemblerConfig(ProblemReporter* pr, bool d = false) :
problem_reporter(pr),
debug_level(d) {
}
/**
* Enable or disable debug output to stderr. This is for Osmium
* developers only.
*
* @deprecated Set debug_level directly.
*/
OSMIUM_DEPRECATED void enable_debug_output(bool d = true) {
debug_level = d;
}
}; // struct AssemblerConfig
} // namespace area

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -72,10 +72,6 @@ namespace osmium {
*/
class AssemblerLegacy : public detail::BasicAssemblerWithTags {
void add_tags_to_area(osmium::builder::AreaBuilder& builder, const osmium::Way& way) const {
builder.add_item(way.tags());
}
void add_common_tags(osmium::builder::TagListBuilder& tl_builder, std::set<const osmium::Way*>& ways) const {
std::map<std::string, std::size_t> counter;
for (const osmium::Way* way : ways) {
@ -166,7 +162,7 @@ namespace osmium {
const bool area_okay = create_rings();
if (area_okay || config().create_empty_areas) {
add_tags_to_area(builder, way);
builder.add_item(way.tags());
}
if (area_okay) {
add_rings_to_area(builder);
@ -336,12 +332,15 @@ namespace osmium {
if (!way.nodes().empty() && way.is_closed() && !way.tags().empty()) {
const auto d = std::count_if(way.tags().cbegin(), way.tags().cend(), std::cref(filter()));
if (d > 0) {
osmium::tags::KeyFilter::iterator way_fi_begin(std::cref(filter()), way.tags().cbegin(), way.tags().cend());
osmium::tags::KeyFilter::iterator way_fi_end(std::cref(filter()), way.tags().cend(), way.tags().cend());
osmium::tags::KeyFilter::iterator area_fi_begin(std::cref(filter()), area_tags.cbegin(), area_tags.cend());
osmium::tags::KeyFilter::iterator area_fi_end(std::cref(filter()), area_tags.cend(), area_tags.cend());
if (!std::equal(way_fi_begin, way_fi_end, area_fi_begin) || d != std::distance(area_fi_begin, area_fi_end)) {
const osmium::tags::KeyFilter::iterator way_fi_begin(std::cref(filter()), way.tags().cbegin(), way.tags().cend());
const osmium::tags::KeyFilter::iterator way_fi_end(std::cref(filter()), way.tags().cend(), way.tags().cend());
const osmium::tags::KeyFilter::iterator area_fi_begin(std::cref(filter()), area_tags.cbegin(), area_tags.cend());
const osmium::tags::KeyFilter::iterator area_fi_end(std::cref(filter()), area_tags.cend(), area_tags.cend());
#ifdef __cpp_lib_robust_nonmodifying_seq_ops
if (!std::equal(way_fi_begin, way_fi_end, area_fi_begin, area_fi_end)) {
#else
if (d != std::distance(area_fi_begin, area_fi_end) || !std::equal(way_fi_begin, way_fi_end, area_fi_begin)) {
#endif
ways_that_should_be_areas.push_back(&way);
} else {
++stats().inner_with_same_tags;

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -51,6 +51,7 @@ DEALINGS IN THE SOFTWARE.
#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <exception>
#include <iostream>
#include <iterator>
#include <list>
@ -103,9 +104,19 @@ namespace osmium {
*/
class BasicAssembler {
static constexpr const std::size_t max_split_locations = 100ULL;
// Maximum recursion depth, stops complex multipolygons from
// breaking everything.
enum : unsigned {
max_depth = 20U
};
struct slocation {
static constexpr const uint32_t invalid_item = 1u << 30u;
enum {
invalid_item = 1U << 30U
};
uint32_t item : 31;
uint32_t reverse : 1;
@ -185,7 +196,7 @@ namespace osmium {
++m_stats.wrong_role;
if (debug()) {
std::cerr << " Segment " << *segment << " from way " << segment->way()->id() << " has role '" << segment->role_name()
<< "', but should have role '" << (ring.is_outer() ? "outer" : "inner") << "'\n";
<< "', but should have role '" << (ring.is_outer() ? "outer" : "inner") << "'\n";
}
if (m_config.problem_reporter) {
if (ring.is_outer()) {
@ -269,7 +280,7 @@ namespace osmium {
using rings_stack = std::vector<rings_stack_element>;
void remove_duplicates(rings_stack& outer_rings) {
static void remove_duplicates(rings_stack& outer_rings) {
while (true) {
const auto it = std::adjacent_find(outer_rings.begin(), outer_rings.end());
if (it == outer_rings.end()) {
@ -315,7 +326,7 @@ namespace osmium {
const int64_t ay = a.y();
const int64_t by = b.y();
const int64_t ly = end_location.y();
const auto z = (bx - ax)*(ly - ay) - (by - ay)*(lx - ax);
const auto z = (bx - ax) * (ly - ay) - (by - ay) * (lx - ax);
if (debug()) {
std::cerr << " Segment z=" << z << '\n';
}
@ -342,7 +353,7 @@ namespace osmium {
const int64_t ay = a.y();
const int64_t by = b.y();
const int64_t ly = location.y();
const auto z = (bx - ax)*(ly - ay) - (by - ay)*(lx - ax);
const auto z = (bx - ax) * (ly - ay) - (by - ay) * (lx - ax);
if (z >= 0) {
nesting += segment->is_reverse() ? -1 : 1;
@ -350,7 +361,8 @@ namespace osmium {
std::cerr << " Segment is below (nesting=" << nesting << ")\n";
}
if (segment->ring()->is_outer()) {
const double y = ay + (by - ay) * (lx - ax) / double(bx - ax);
const double y = static_cast<double>(ay) +
static_cast<double>((by - ay) * (lx - ax)) / static_cast<double>(bx - ax);
if (debug()) {
std::cerr << " Segment belongs to outer ring (y=" << y << " ring=" << *segment->ring() << ")\n";
}
@ -373,7 +385,7 @@ namespace osmium {
}
assert(!outer_rings.empty());
std::sort(outer_rings.rbegin(), outer_rings.rend());
std::stable_sort(outer_rings.rbegin(), outer_rings.rend());
if (debug()) {
for (const auto& o : outer_rings) {
std::cerr << " y=" << o.y() << " " << o.ring() << "\n";
@ -396,7 +408,7 @@ namespace osmium {
return std::find(m_split_locations.cbegin(), m_split_locations.cend(), location) != m_split_locations.cend();
}
uint32_t add_new_ring(slocation& node) {
uint32_t add_new_ring(const slocation& node) {
NodeRefSegment* segment = &m_segment_list[node.item];
assert(!segment->is_done());
@ -454,7 +466,7 @@ namespace osmium {
return nodes;
}
uint32_t add_new_ring_complex(slocation& node) {
uint32_t add_new_ring_complex(const slocation& node) {
NodeRefSegment* segment = &m_segment_list[node.item];
assert(!segment->is_done());
@ -500,7 +512,12 @@ namespace osmium {
void create_locations_list() {
m_locations.reserve(m_segment_list.size() * 2);
for (uint32_t n = 0; n < m_segment_list.size(); ++n) {
// static_cast is okay here: The 32bit limit is way past
// anything that makes sense here and even if there are
// 2^32 segments here, it would simply not go through
// all of them not building the multipolygon correctly.
assert(m_segment_list.size() < std::numeric_limits<uint32_t>::max());
for (uint32_t n = 0; n < static_cast<uint32_t>(m_segment_list.size()); ++n) {
m_locations.emplace_back(n, false);
m_locations.emplace_back(n, true);
}
@ -536,7 +553,7 @@ namespace osmium {
return;
}
std::sort(rings.begin(), rings.end(), [](ProtoRing* a, ProtoRing* b) {
std::stable_sort(rings.begin(), rings.end(), [](ProtoRing* a, ProtoRing* b) {
return a->min_segment() < b->min_segment();
});
@ -576,7 +593,7 @@ namespace osmium {
}
++m_stats.open_rings;
} else {
if (loc == previous_location && (m_split_locations.empty() || m_split_locations.back() != previous_location )) {
if (loc == previous_location && (m_split_locations.empty() || m_split_locations.back() != previous_location)) {
m_split_locations.push_back(previous_location);
}
++it;
@ -591,7 +608,7 @@ namespace osmium {
void create_rings_simple_case() {
auto count_remaining = m_segment_list.size();
for (slocation& sl : m_locations) {
for (const slocation& sl : m_locations) {
const NodeRefSegment& segment = m_segment_list[sl.item];
if (!segment.is_done()) {
count_remaining -= add_new_ring(sl);
@ -602,7 +619,7 @@ namespace osmium {
}
}
std::vector<location_to_ring_map> create_location_to_ring_map(open_ring_its_type& open_ring_its) {
std::vector<location_to_ring_map> create_location_to_ring_map(open_ring_its_type& open_ring_its) const {
std::vector<location_to_ring_map> xrings;
xrings.reserve(open_ring_its.size() * 2);
@ -614,7 +631,7 @@ namespace osmium {
xrings.emplace_back((*it)->get_node_ref_stop().location(), it, false);
}
std::sort(xrings.begin(), xrings.end());
std::stable_sort(xrings.begin(), xrings.end());
return xrings;
}
@ -654,7 +671,7 @@ namespace osmium {
std::cerr << " Trying to merge " << open_ring_its.size() << " open rings (try_to_merge)\n";
}
std::vector<location_to_ring_map> xrings = create_location_to_ring_map(open_ring_its);
const auto xrings = create_location_to_ring_map(open_ring_its);
auto it = xrings.cbegin();
while (it != xrings.cend()) {
@ -679,7 +696,7 @@ namespace osmium {
}
bool there_are_open_rings() const noexcept {
return std::any_of(m_rings.cbegin(), m_rings.cend(), [](const ProtoRing& ring){
return std::any_of(m_rings.cbegin(), m_rings.cend(), [](const ProtoRing& ring) {
return !ring.closed();
});
}
@ -703,7 +720,15 @@ namespace osmium {
};
void find_candidates(std::vector<candidate>& candidates, std::unordered_set<osmium::Location>& loc_done, const std::vector<location_to_ring_map>& xrings, candidate& cand) {
struct exceeded_max_depth : public std::exception {};
using location_set = std::vector<osmium::Location>;
void find_candidates(std::vector<candidate>& candidates, location_set& loc_done, const std::vector<location_to_ring_map>& xrings, const candidate& cand, unsigned depth = 0) {
if (depth > max_depth) {
throw exceeded_max_depth{};
}
if (debug()) {
std::cerr << " find_candidates sum=" << cand.sum << " start=" << cand.start_location << " stop=" << cand.stop_location << "\n";
for (const auto& ring : cand.rings) {
@ -741,14 +766,32 @@ namespace osmium {
if (debug()) {
std::cerr << " found candidate\n";
}
candidates.push_back(c);
} else if (loc_done.count(c.stop_location) == 0) {
if (debug()) {
std::cerr << " recurse...\n";
if (candidates.empty()) {
candidates.push_back(c);
} else if (candidates.size() == 1) {
// add new candidate to vector, keep sorted
if (std::abs(c.sum) < std::abs(candidates.front().sum)) {
candidates.insert(candidates.begin(), c);
} else {
candidates.push_back(c);
}
} else {
// add new candidate if it has either smallest or largest area
if (std::abs(c.sum) < std::abs(candidates.front().sum)) {
candidates.front() = c;
} else if (std::abs(c.sum) > std::abs(candidates.back().sum)) {
candidates.back() = c;
}
}
loc_done.insert(c.stop_location);
find_candidates(candidates, loc_done, xrings, c);
loc_done.erase(c.stop_location);
} else if (std::find(loc_done.cbegin(), loc_done.cend(), c.stop_location) == loc_done.cend()) {
if (debug()) {
std::cerr << " recurse... (depth=" << depth << " candidates.size=" << candidates.size() << " loc_done.size=" << loc_done.size() << ")\n";
}
loc_done.push_back(c.stop_location);
find_candidates(candidates, loc_done, xrings, c, depth + 1);
assert(!loc_done.empty() && loc_done.back() == c.stop_location);
loc_done.pop_back();
if (debug()) {
std::cerr << " ...back\n";
}
@ -782,7 +825,7 @@ namespace osmium {
find_inner_outer_complex();
ProtoRing* outer_ring = find_enclosing_ring(ring_min->ring().min_segment());
bool ring_min_is_outer = !outer_ring;
const bool ring_min_is_outer = !outer_ring;
if (debug()) {
std::cerr << " Open ring is " << (ring_min_is_outer ? "outer" : "inner") << " ring\n";
}
@ -790,16 +833,23 @@ namespace osmium {
ring.reset();
}
candidate cand{*ring_min, false};
const candidate cand{*ring_min, false};
// Locations we have visited while finding candidates, used
// to detect loops.
std::unordered_set<osmium::Location> loc_done;
location_set loc_done;
loc_done.insert(cand.stop_location);
loc_done.push_back(cand.stop_location);
std::vector<candidate> candidates;
find_candidates(candidates, loc_done, xrings, cand);
try {
find_candidates(candidates, loc_done, xrings, cand);
} catch (const exceeded_max_depth&) {
if (m_config.debug_level > 0) {
std::cerr << " Exceeded max depth (" << static_cast<unsigned>(max_depth) << ")\n";
}
return false;
}
if (candidates.empty()) {
if (debug()) {
@ -819,35 +869,29 @@ namespace osmium {
if (debug()) {
std::cerr << " Found candidates:\n";
for (const auto& cand : candidates) {
std::cerr << " sum=" << cand.sum << "\n";
for (const auto& ring : cand.rings) {
for (const auto& c : candidates) {
std::cerr << " sum=" << c.sum << "\n";
for (const auto& ring : c.rings) {
std::cerr << " " << ring.first.ring() << (ring.second ? " reverse" : "") << "\n";
}
}
}
// Find the candidate with the smallest/largest area
const auto chosen_cand = ring_min_is_outer ?
std::min_element(candidates.cbegin(), candidates.cend(), [](const candidate& lhs, const candidate& rhs) {
return std::abs(lhs.sum) < std::abs(rhs.sum);
}) :
std::max_element(candidates.cbegin(), candidates.cend(), [](const candidate& lhs, const candidate& rhs) {
return std::abs(lhs.sum) < std::abs(rhs.sum);
});
const auto chosen_cand = ring_min_is_outer ? candidates.front() : candidates.back();
if (debug()) {
std::cerr << " Decided on: sum=" << chosen_cand->sum << "\n";
for (const auto& ring : chosen_cand->rings) {
std::cerr << " Decided on: sum=" << chosen_cand.sum << "\n";
for (const auto& ring : chosen_cand.rings) {
std::cerr << " " << ring.first.ring() << (ring.second ? " reverse" : "") << "\n";
}
}
// Join all (open) rings in the candidate to get one closed ring.
assert(chosen_cand->rings.size() > 1);
const auto& first_ring = chosen_cand->rings.front().first;
assert(chosen_cand.rings.size() > 1);
const auto& first_ring = chosen_cand.rings.front().first;
const ProtoRing& remaining_ring = first_ring.ring();
for (auto it = std::next(chosen_cand->rings.begin()); it != chosen_cand->rings.end(); ++it) {
for (auto it = std::next(chosen_cand.rings.begin()); it != chosen_cand.rings.end(); ++it) {
merge_two_rings(open_ring_its, first_ring, it->first);
}
@ -863,11 +907,11 @@ namespace osmium {
auto count_remaining = m_segment_list.size();
for (const osmium::Location& location : m_split_locations) {
const auto locs = make_range(std::equal_range(m_locations.begin(),
m_locations.end(),
slocation{},
[this, &location](const slocation& lhs, const slocation& rhs) {
return lhs.location(m_segment_list, location) < rhs.location(m_segment_list, location);
}));
m_locations.end(),
slocation{},
[this, &location](const slocation& lhs, const slocation& rhs) {
return lhs.location(m_segment_list, location) < rhs.location(m_segment_list, location);
}));
for (auto& loc : locs) {
if (!m_segment_list[loc.item].is_done()) {
count_remaining -= add_new_ring_complex(loc);
@ -880,7 +924,7 @@ namespace osmium {
// Now find all the rest of the rings (ie not starting at split locations)
if (count_remaining > 0) {
for (slocation& sl : m_locations) {
for (const slocation& sl : m_locations) {
const NodeRefSegment& segment = m_segment_list[sl.item];
if (!segment.is_done()) {
count_remaining -= add_new_ring_complex(sl);
@ -1066,28 +1110,38 @@ namespace osmium {
// whether there were any split locations or not. If there
// are no splits, we use the faster "simple algorithm", if
// there are, we use the slower "complex algorithm".
osmium::Timer timer_simple_case;
osmium::Timer timer_complex_case;
osmium::Timer timer;
if (m_split_locations.empty()) {
if (debug()) {
std::cerr << " No split locations -> using simple algorithm\n";
}
++m_stats.area_simple_case;
timer_simple_case.start();
timer.start();
create_rings_simple_case();
timer_simple_case.stop();
timer.stop();
} else if (m_split_locations.size() > max_split_locations) {
if (m_config.debug_level > 0) {
std::cerr << " Ignoring polygon with "
<< m_split_locations.size()
<< " split locations (>"
<< max_split_locations
<< ")\n";
}
return false;
} else {
if (debug()) {
std::cerr << " Found split locations -> using complex algorithm\n";
if (m_config.debug_level > 0) {
std::cerr << " Found "
<< m_split_locations.size()
<< " split locations -> using complex algorithm\n";
}
++m_stats.area_touching_rings_case;
timer_complex_case.start();
timer.start();
if (!create_rings_complex_case()) {
return false;
}
timer_complex_case.stop();
timer.stop();
}
// If the assembler was so configured, now check whether the
@ -1098,7 +1152,7 @@ namespace osmium {
timer_roles.stop();
}
m_stats.outer_rings = std::count_if(m_rings.cbegin(), m_rings.cend(), [](const ProtoRing& ring){
m_stats.outer_rings = std::count_if(m_rings.cbegin(), m_rings.cend(), [](const ProtoRing& ring) {
return ring.is_outer();
});
m_stats.inner_rings = m_rings.size() - m_stats.outer_rings;
@ -1112,11 +1166,9 @@ namespace osmium {
' ' << timer_split.elapsed_microseconds();
if (m_split_locations.empty()) {
std::cout << ' ' << timer_simple_case.elapsed_microseconds() <<
" 0";
std::cout << ' ' << timer.elapsed_microseconds() << " 0";
} else {
std::cout << " 0" <<
' ' << timer_complex_case.elapsed_microseconds();
std::cout << " 0" << ' ' << timer.elapsed_microseconds();
}
std::cout <<

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -56,13 +56,13 @@ namespace osmium {
return false;
}
return stats().duplicate_nodes ||
stats().duplicate_segments ||
stats().intersections ||
stats().open_rings ||
stats().short_ways ||
stats().touching_rings ||
stats().ways_in_multiple_rings ||
stats().wrong_role;
stats().duplicate_segments ||
stats().intersections ||
stats().open_rings ||
stats().short_ways ||
stats().touching_rings ||
stats().ways_in_multiple_rings ||
stats().wrong_role;
}
static void copy_tags_without_type(osmium::builder::AreaBuilder& builder, const osmium::TagList& tags) {

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -38,6 +38,7 @@ DEALINGS IN THE SOFTWARE.
#include <osmium/osm/node_ref.hpp>
#include <algorithm>
#include <array>
#include <cassert>
#include <cstdint>
#include <iosfwd>
@ -101,14 +102,10 @@ namespace osmium {
NodeRefSegment() noexcept = default;
NodeRefSegment(const osmium::NodeRef& nr1, const osmium::NodeRef& nr2, role_type role, const osmium::Way* way) noexcept :
m_first(nr1),
m_second(nr2),
m_first(nr1.location() < nr2.location() ? nr1 : nr2),
m_second(nr1.location() < nr2.location() ? nr2 : nr1),
m_way(way),
m_role(role) {
if (nr2.location() < nr1.location()) {
using std::swap;
swap(m_first, m_second);
}
}
/**
@ -195,8 +192,8 @@ namespace osmium {
}
const char* role_name() const noexcept {
static const char* names[] = { "unknown", "outer", "inner", "empty" };
return names[int(m_role)];
static const std::array<const char*, 4> names = {{"unknown", "outer", "inner", "empty"}};
return names[static_cast<int>(m_role)];
}
const osmium::Way* way() const noexcept {
@ -205,7 +202,7 @@ namespace osmium {
/**
* The "determinant" of this segment. Used for calculating
* the winding order or a ring.
* the winding order of a ring.
*/
int64_t det() const noexcept {
const vec a{start()};
@ -222,7 +219,7 @@ namespace osmium {
}
inline bool operator!=(const NodeRefSegment& lhs, const NodeRefSegment& rhs) noexcept {
return ! (lhs == rhs);
return !(lhs == rhs);
}
/**
@ -330,9 +327,9 @@ namespace osmium {
if ((d > 0 && na >= 0 && na <= d && nb >= 0 && nb <= d) ||
(d < 0 && na <= 0 && na >= d && nb <= 0 && nb >= d)) {
const double ua = double(na) / d;
const double ua = static_cast<double>(na) / static_cast<double>(d);
const vec i = p0 + ua * (p1 - p0);
return osmium::Location{int32_t(i.x), int32_t(i.y)};
return osmium::Location{static_cast<int32_t>(i.x), static_cast<int32_t>(i.y)};
}
return osmium::Location{};
@ -348,13 +345,14 @@ namespace osmium {
osmium::Location location;
};
seg_loc sl[4];
sl[0] = {0, s1.first().location() };
sl[1] = {0, s1.second().location()};
sl[2] = {1, s2.first().location() };
sl[3] = {1, s2.second().location()};
std::array<seg_loc, 4> sl = {{
{0, s1.first().location()},
{0, s1.second().location()},
{1, s2.first().location()},
{1, s2.second().location()},
}};
std::sort(sl, sl+4, [](const seg_loc& lhs, const seg_loc& rhs) {
std::sort(sl.begin(), sl.end(), [](const seg_loc& lhs, const seg_loc& rhs) {
return lhs.location < rhs.location;
});

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -86,16 +86,16 @@ namespace osmium {
int64_t m_num;
#endif
int64_t m_sum;
int64_t m_sum = 0;
public:
explicit ProtoRing(NodeRefSegment* segment) noexcept :
m_min_segment(segment),
m_min_segment(segment)
#ifdef OSMIUM_DEBUG_RING_NO
m_num(next_num()),
, m_num(next_num())
#endif
m_sum(0) {
{
add_segment_back(segment);
}
@ -196,12 +196,14 @@ namespace osmium {
}
void join_forward(ProtoRing& other) {
m_segments.reserve(m_segments.size() + other.m_segments.size());
for (NodeRefSegment* segment : other.m_segments) {
add_segment_back(segment);
}
}
void join_backward(ProtoRing& other) {
m_segments.reserve(m_segments.size() + other.m_segments.size());
for (auto it = other.m_segments.rbegin(); it != other.m_segments.rend(); ++it) {
(*it)->reverse();
add_segment_back(*it);

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -147,14 +147,14 @@ namespace osmium {
m_debug(debug) {
}
~SegmentList() noexcept = default;
SegmentList(const SegmentList&) = delete;
SegmentList(SegmentList&&) = delete;
SegmentList& operator=(const SegmentList&) = delete;
SegmentList& operator=(SegmentList&&) = delete;
~SegmentList() noexcept = default;
/// The number of segments in the list.
std::size_t size() const noexcept {
return m_segments.size();
@ -181,7 +181,7 @@ namespace osmium {
return m_segments[n];
}
NodeRefSegment& operator[](std::size_t n) noexcept {
NodeRefSegment& operator[](const std::size_t n) noexcept {
assert(n < m_segments.size());
return m_segments[n];
}
@ -206,7 +206,7 @@ namespace osmium {
* Enable or disable debug output to stderr. This is used
* for debugging libosmium itself.
*/
void enable_debug_output(bool debug = true) noexcept {
void enable_debug_output(const bool debug = true) noexcept {
m_debug = debug;
}
@ -296,14 +296,14 @@ namespace osmium {
}
}
if (it+2 != m_segments.end() && *it == *(it+2)) {
if (it + 2 != m_segments.end() && *it == *(it + 2)) {
++overlapping_segments;
if (problem_reporter) {
problem_reporter->report_overlapping_segment(it->first(), it->second());
}
}
m_segments.erase(it, it+2);
m_segments.erase(it, it + 2);
}
}
@ -323,7 +323,7 @@ namespace osmium {
for (auto it1 = m_segments.cbegin(); it1 != m_segments.cend() - 1; ++it1) {
const NodeRefSegment& s1 = *it1;
for (auto it2 = it1+1; it2 != m_segments.end(); ++it2) {
for (auto it2 = it1 + 1; it2 != m_segments.end(); ++it2) {
const NodeRefSegment& s2 = *it2;
assert(s1 != s2); // erase_duplicate_segments() should have made sure of that
@ -333,7 +333,7 @@ namespace osmium {
}
if (y_range_overlap(s1, s2)) {
osmium::Location intersection{calculate_intersection(s1, s2)};
const osmium::Location intersection{calculate_intersection(s1, s2)};
if (intersection) {
++found_intersections;
if (m_debug) {

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -89,12 +89,12 @@ namespace osmium {
// scale vector
constexpr inline vec operator*(double s, const vec& v) noexcept {
return vec{int64_t(s * v.x), int64_t(s * v.y)};
return vec{static_cast<int64_t>(s * static_cast<double>(v.x)), static_cast<int64_t>(s * static_cast<double>(v.y))};
}
// scale vector
constexpr inline vec operator*(const vec& v, double s) noexcept {
return vec{int64_t(s * v.x), int64_t(s * v.y)};
return vec{static_cast<int64_t>(s * static_cast<double>(v.x)), static_cast<int64_t>(s * static_cast<double>(v.y))};
}
// equality

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -68,8 +68,6 @@ namespace osmium {
detail::BasicAssembler(config) {
}
~GeomAssembler() noexcept = default;
/**
* Assemble an area from the given way.
*

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -70,6 +70,8 @@ namespace osmium {
*
* @tparam TAssembler Multipolygon Assembler class.
* @pre The Ids of all objects must be unique in the input data.
*
* @deprecated Use MultipolygonManager instead.
*/
template <typename TAssembler>
class MultipolygonCollector : public osmium::relations::Collector<MultipolygonCollector<TAssembler>, false, true, false> {
@ -83,8 +85,13 @@ namespace osmium {
area_stats m_stats;
static constexpr size_t initial_output_buffer_size = 1024 * 1024;
static constexpr size_t max_buffer_size_for_flush = 100 * 1024;
enum {
initial_output_buffer_size = 1024UL * 1024UL
};
enum {
max_buffer_size_for_flush = 100UL * 1024UL
};
void flush_output_buffer() {
if (this->callback()) {
@ -165,7 +172,7 @@ namespace osmium {
}
}
void complete_relation(osmium::relations::RelationMeta& relation_meta) {
void complete_relation(const osmium::relations::RelationMeta& relation_meta) {
const osmium::Relation& relation = this->get_relation(relation_meta);
const osmium::memory::Buffer& buffer = this->members_buffer();

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -63,8 +63,8 @@ namespace osmium {
/**
* This class collects all data needed for creating areas from
* relations tagged with type=multipolygon or type=boundary.
* Most of its functionality is derived from the parent class
* osmium::relations::Collector.
* Most of its functionality is derived from the parent template class
* osmium::relations::RelationsManager.
*
* The actual assembling of the areas is done by the assembler
* class given as template argument.

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -80,7 +80,7 @@ namespace osmium {
ProblemReporter(ProblemReporter&&) noexcept = default;
ProblemReporter& operator=(ProblemReporter&&) noexcept = default;
virtual ~ProblemReporter() = default;
virtual ~ProblemReporter() noexcept = default;
/**
* Set the object the next problem reports will be on.
@ -93,6 +93,10 @@ namespace osmium {
m_object_id = object_id;
}
osmium::object_id_type object_id() const noexcept {
return m_object_id;
}
void set_nodes(size_t nodes) noexcept {
m_nodes = nodes;
}

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -75,15 +75,15 @@ namespace osmium {
void set_object(gdalcpp::Feature& feature) {
const char t[2] = {osmium::item_type_to_char(m_object_type), '\0'};
feature.set_field("obj_type", t);
feature.set_field("obj_id", int32_t(m_object_id));
feature.set_field("nodes", int32_t(m_nodes));
feature.set_field("obj_id", static_cast<int32_t>(m_object_id));
feature.set_field("nodes", static_cast<int32_t>(m_nodes));
}
void write_point(const char* problem_type, osmium::object_id_type id1, osmium::object_id_type id2, osmium::Location location) {
gdalcpp::Feature feature{m_layer_perror, m_ogr_factory.create_point(location)};
set_object(feature);
feature.set_field("id1", double(id1));
feature.set_field("id2", double(id2));
feature.set_field("id1", static_cast<double>(id1));
feature.set_field("id2", static_cast<double>(id2));
feature.set_field("problem", problem_type);
feature.add_to_layer();
}
@ -117,8 +117,7 @@ namespace osmium {
.add_field("nodes", OFTInteger, 8)
.add_field("id1", OFTReal, 12, 1)
.add_field("id2", OFTReal, 12, 1)
.add_field("problem", OFTString, 30)
;
.add_field("problem", OFTString, 30);
m_layer_lerror
.add_field("obj_type", OFTString, 1)
@ -126,15 +125,13 @@ namespace osmium {
.add_field("nodes", OFTInteger, 8)
.add_field("id1", OFTReal, 12, 1)
.add_field("id2", OFTReal, 12, 1)
.add_field("problem", OFTString, 30)
;
.add_field("problem", OFTString, 30);
m_layer_ways
.add_field("obj_type", OFTString, 1)
.add_field("obj_id", OFTInteger, 10)
.add_field("way_id", OFTInteger, 10)
.add_field("nodes", OFTInteger, 8)
;
.add_field("nodes", OFTInteger, 8);
}
void report_duplicate_node(osmium::object_id_type node_id1, osmium::object_id_type node_id2, osmium::Location location) override {
@ -179,7 +176,7 @@ namespace osmium {
try {
gdalcpp::Feature feature{m_layer_lerror, m_ogr_factory.create_linestring(way)};
set_object(feature);
feature.set_field("id1", int32_t(way.id()));
feature.set_field("id1", static_cast<int32_t>(way.id()));
feature.set_field("id2", 0);
feature.set_field("problem", "way_in_multiple_rings");
feature.add_to_layer();
@ -195,7 +192,7 @@ namespace osmium {
try {
gdalcpp::Feature feature{m_layer_lerror, m_ogr_factory.create_linestring(way)};
set_object(feature);
feature.set_field("id1", int32_t(way.id()));
feature.set_field("id1", static_cast<int32_t>(way.id()));
feature.set_field("id2", 0);
feature.set_field("problem", "inner_with_same_tags");
feature.add_to_layer();
@ -211,7 +208,7 @@ namespace osmium {
try {
gdalcpp::Feature feature{m_layer_lerror, m_ogr_factory.create_linestring(way)};
set_object(feature);
feature.set_field("id1", int32_t(way.id()));
feature.set_field("id1", static_cast<int32_t>(way.id()));
feature.set_field("id2", 0);
feature.set_field("problem", "duplicate_way");
feature.add_to_layer();
@ -232,7 +229,7 @@ namespace osmium {
try {
gdalcpp::Feature feature{m_layer_ways, m_ogr_factory.create_linestring(way)};
set_object(feature);
feature.set_field("way_id", int32_t(way.id()));
feature.set_field("way_id", static_cast<int32_t>(way.id()));
feature.add_to_layer();
} catch (const osmium::geometry_error&) {
// XXX

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -45,6 +45,7 @@ DEALINGS IN THE SOFTWARE.
#include <osmium/osm/relation.hpp>
#include <osmium/osm/timestamp.hpp>
#include <osmium/osm/types.hpp>
#include <osmium/util/string.hpp>
#include <cstddef>
#include <cstdint>
@ -226,8 +227,8 @@ namespace osmium {
OSMIUM_ATTRIBUTE(node_handler, _location, osmium::Location)
constexpr explicit _location(const osmium::Location& value) noexcept :
type_wrapper(value) {}
explicit _location(double lat, double lon) :
type_wrapper(osmium::Location{lat, lon}) {}
explicit _location(double lon, double lat) :
type_wrapper(osmium::Location{lon, lat}) {}
};
OSMIUM_ATTRIBUTE(entity_handler, _user, const char*)
@ -254,6 +255,10 @@ namespace osmium {
m_role(role) {
}
member_type(char type, osmium::object_id_type ref, const char* role = "") noexcept :
member_type(osmium::char_to_item_type(type), ref, role) {
}
constexpr osmium::item_type type() const noexcept {
return m_type;
}
@ -282,6 +287,10 @@ namespace osmium {
m_role(std::move(role)) {
}
member_type_string(char type, osmium::object_id_type ref, std::string&& role) noexcept :
member_type_string(osmium::char_to_item_type(type), ref, std::move(role)) {
}
osmium::item_type type() const noexcept {
return m_type;
}
@ -360,6 +369,15 @@ namespace osmium {
type_wrapper(std::make_pair(key, val)) {}
explicit _tag(const std::string& key, const std::string& val) :
type_wrapper(std::make_pair(key.c_str(), val.c_str())) {}
explicit _tag(const char* const key_value) :
type_wrapper(pair_of_cstrings{key_value, nullptr}) {}
explicit _tag(const std::string& key_value) :
type_wrapper(pair_of_cstrings{key_value.c_str(), nullptr}) {}
};
OSMIUM_ATTRIBUTE(tags_handler, _t, const char*)
explicit _t(const char *tags) :
type_wrapper(tags) {}
};
template <typename TTagIterator>
@ -659,7 +677,19 @@ namespace osmium {
}
static void set_value(TagListBuilder& builder, const attr::_tag& tag) {
builder.add_tag(tag.value);
if (tag.value.second != nullptr) {
builder.add_tag(tag.value);
return;
}
const char* key = tag.value.first;
const char* const equal_sign = std::strchr(key, '=');
if (!equal_sign) {
builder.add_tag(key, "");
return;
}
const char* value = equal_sign + 1;
builder.add_tag(key, equal_sign - key,
value, std::strlen(value));
}
template <typename TIterator>
@ -669,6 +699,21 @@ namespace osmium {
}
}
static void set_value(TagListBuilder& builder, const attr::_t& tags) {
const auto taglist = osmium::split_string(tags.value, ',', true);
for (const auto& tag : taglist) {
const std::size_t pos = tag.find_first_of('=');
if (pos == std::string::npos) {
builder.add_tag(tag, "");
} else {
const char* value = tag.c_str() + pos + 1;
builder.add_tag(tag.c_str(), pos,
value, tag.size() - pos - 1);
}
}
}
}; // struct tags_handler
struct nodes_handler {
@ -764,7 +809,7 @@ namespace osmium {
template <typename TBuilder, typename THandler, typename... TArgs>
inline typename std::enable_if<is_handled_by<THandler, TArgs...>::value>::type
add_list(osmium::builder::Builder& parent, const TArgs&... args) {
TBuilder builder(parent.buffer(), &parent);
TBuilder builder{parent.buffer(), &parent};
(void)std::initializer_list<int>{
(THandler::set_value(builder, args), 0)...
};
@ -792,7 +837,7 @@ namespace osmium {
static_assert(detail::are_all_handled_by<detail::any_node_handlers, TArgs...>::value, "Attribute not allowed in add_node()");
{
NodeBuilder builder(buffer);
NodeBuilder builder{buffer};
detail::add_basic<detail::node_handler>(builder, args...);
detail::add_user(builder, args...);
@ -815,7 +860,7 @@ namespace osmium {
static_assert(detail::are_all_handled_by<detail::any_way_handlers, TArgs...>::value, "Attribute not allowed in add_way()");
{
WayBuilder builder(buffer);
WayBuilder builder{buffer};
detail::add_basic<detail::object_handler>(builder, args...);
detail::add_user(builder, args...);
@ -839,7 +884,7 @@ namespace osmium {
static_assert(detail::are_all_handled_by<detail::any_relation_handlers, TArgs...>::value, "Attribute not allowed in add_relation()");
{
RelationBuilder builder(buffer);
RelationBuilder builder{buffer};
detail::add_basic<detail::object_handler>(builder, args...);
detail::add_user(builder, args...);
@ -863,7 +908,7 @@ namespace osmium {
static_assert(detail::are_all_handled_by<detail::any_changeset_handlers, TArgs...>::value, "Attribute not allowed in add_changeset()");
{
ChangesetBuilder builder(buffer);
ChangesetBuilder builder{buffer};
detail::add_basic<detail::changeset_handler>(builder, args...);
detail::add_user(builder, args...);
@ -887,7 +932,7 @@ namespace osmium {
static_assert(detail::are_all_handled_by<detail::any_area_handlers, TArgs...>::value, "Attribute not allowed in add_area()");
{
AreaBuilder builder(buffer);
AreaBuilder builder{buffer};
detail::add_basic<detail::object_handler>(builder, args...);
detail::add_user(builder, args...);
@ -914,7 +959,7 @@ namespace osmium {
static_assert(detail::are_all_handled_by<detail::nodes_handler, TArgs...>::value, "Attribute not allowed in add_way_node_list()");
{
WayNodeListBuilder builder(buffer);
WayNodeListBuilder builder{buffer};
(void)std::initializer_list<int>{
(detail::nodes_handler::set_value(builder, args), 0)...
};
@ -936,7 +981,7 @@ namespace osmium {
static_assert(detail::are_all_handled_by<detail::tags_handler, TArgs...>::value, "Attribute not allowed in add_tag_list()");
{
TagListBuilder builder(buffer);
TagListBuilder builder{buffer};
(void)std::initializer_list<int>{
(detail::tags_handler::set_value(builder, args), 0)...
};

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -35,7 +35,6 @@ DEALINGS IN THE SOFTWARE.
#include <osmium/memory/buffer.hpp>
#include <osmium/memory/item.hpp>
#include <osmium/util/compatibility.hpp>
#include <algorithm>
#include <cassert>
@ -65,7 +64,7 @@ namespace osmium {
explicit Builder(osmium::memory::Buffer& buffer, Builder* parent, osmium::memory::item_size_type size) :
m_buffer(buffer),
m_parent(parent),
m_item_offset(buffer.written()) {
m_item_offset(buffer.written() - buffer.committed()) {
reserve_space(size);
assert(buffer.is_aligned());
if (m_parent) {
@ -80,15 +79,19 @@ namespace osmium {
}
#ifdef NDEBUG
~Builder() = default;
~Builder() noexcept = default;
#else
~Builder() noexcept {
m_buffer.decrement_builder_count();
}
#endif
osmium::memory::Item& item() const {
return *reinterpret_cast<osmium::memory::Item*>(m_buffer.data() + m_item_offset);
unsigned char* item_pos() const noexcept {
return m_buffer.data() + m_buffer.committed() + m_item_offset;
}
osmium::memory::Item& item() const noexcept {
return *reinterpret_cast<osmium::memory::Item*>(item_pos());
}
unsigned char* reserve_space(std::size_t size) {
@ -183,18 +186,6 @@ namespace osmium {
return append(str, static_cast<osmium::memory::item_size_type>(std::strlen(str) + 1));
}
/**
* Append '\0' to the buffer.
*
* @deprecated Use append_with_zero() instead.
*
* @returns The number of bytes appended (always 1).
*/
OSMIUM_DEPRECATED osmium::memory::item_size_type append_zero() {
*reserve_space(1) = '\0';
return 1;
}
public:
Builder(const Builder&) = delete;
@ -217,15 +208,6 @@ namespace osmium {
add_size(item.padded_size());
}
/**
* @deprecated Use the version of add_item() taking a
* reference instead.
*/
OSMIUM_DEPRECATED void add_item(const osmium::memory::Item* item) {
assert(item);
add_item(*item);
}
}; // class Builder
} // namespace builder

View File

@ -1,120 +0,0 @@
#ifndef OSMIUM_BUILDER_BUILDER_HELPER_HPP
#define OSMIUM_BUILDER_BUILDER_HELPER_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <osmium/builder/osm_object_builder.hpp>
#include <osmium/memory/buffer.hpp>
#include <osmium/util/compatibility.hpp>
#include <cstddef>
#include <functional>
#include <initializer_list>
#include <map>
#include <utility>
namespace osmium {
class NodeRef;
class TagList;
class WayNodeList;
namespace builder {
/**
* @deprecated
* Use osmium::builder::add_way_node_list() instead.
*/
OSMIUM_DEPRECATED inline const osmium::WayNodeList& build_way_node_list(osmium::memory::Buffer& buffer, const std::initializer_list<osmium::NodeRef>& nodes) {
const size_t pos = buffer.committed();
{
osmium::builder::WayNodeListBuilder wnl_builder(buffer);
for (const auto& node_ref : nodes) {
wnl_builder.add_node_ref(node_ref);
}
}
buffer.commit();
return buffer.get<const osmium::WayNodeList>(pos);
}
/**
* @deprecated
* Use osmium::builder::add_tag_list() instead.
*/
OSMIUM_DEPRECATED inline const osmium::TagList& build_tag_list(osmium::memory::Buffer& buffer, const std::initializer_list<std::pair<const char*, const char*>>& tags) {
const size_t pos = buffer.committed();
{
osmium::builder::TagListBuilder tl_builder(buffer);
for (const auto& p : tags) {
tl_builder.add_tag(p.first, p.second);
}
}
buffer.commit();
return buffer.get<const osmium::TagList>(pos);
}
/**
* @deprecated
* Use osmium::builder::add_tag_list() instead.
*/
OSMIUM_DEPRECATED inline const osmium::TagList& build_tag_list_from_map(osmium::memory::Buffer& buffer, const std::map<const char*, const char*>& tags) {
const size_t pos = buffer.committed();
{
osmium::builder::TagListBuilder tl_builder(buffer);
for (const auto& p : tags) {
tl_builder.add_tag(p.first, p.second);
}
}
buffer.commit();
return buffer.get<const osmium::TagList>(pos);
}
/**
* @deprecated
* Use osmium::builder::add_tag_list() instead.
*/
OSMIUM_DEPRECATED inline const osmium::TagList& build_tag_list_from_func(osmium::memory::Buffer& buffer, const std::function<void(osmium::builder::TagListBuilder&)>& func) {
const size_t pos = buffer.committed();
{
osmium::builder::TagListBuilder tl_builder(buffer);
func(tl_builder);
}
buffer.commit();
return buffer.get<const osmium::TagList>(pos);
}
} // namespace builder
} // namespace osmium
#endif // OSMIUM_BUILDER_BUILDER_HELPER_HPP

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -48,7 +48,6 @@ DEALINGS IN THE SOFTWARE.
#include <osmium/osm/timestamp.hpp>
#include <osmium/osm/types.hpp>
#include <osmium/osm/way.hpp>
#include <osmium/util/compatibility.hpp>
#include <algorithm>
#include <cassert>
@ -126,8 +125,8 @@ namespace osmium {
if (value_length > osmium::max_osm_string_length) {
throw std::length_error{"OSM tag value is too long"};
}
add_size(append_with_zero(key, osmium::memory::item_size_type(key_length)));
add_size(append_with_zero(value, osmium::memory::item_size_type(value_length)));
add_size(append_with_zero(key, static_cast<osmium::memory::item_size_type>(key_length)));
add_size(append_with_zero(value, static_cast<osmium::memory::item_size_type>(value_length)));
}
/**
@ -143,8 +142,8 @@ namespace osmium {
if (value.size() > osmium::max_osm_string_length) {
throw std::length_error{"OSM tag value is too long"};
}
add_size(append(key.data(), osmium::memory::item_size_type(key.size()) + 1));
add_size(append(value.data(), osmium::memory::item_size_type(value.size()) + 1));
add_size(append(key.data(), static_cast<osmium::memory::item_size_type>(key.size()) + 1));
add_size(append(value.data(), static_cast<osmium::memory::item_size_type>(value.size()) + 1));
}
/**
@ -241,8 +240,8 @@ namespace osmium {
if (length > osmium::max_osm_string_length) {
throw std::length_error{"OSM relation member role is too long"};
}
member.set_role_size(osmium::string_size_type(length) + 1);
add_size(append_with_zero(role, osmium::memory::item_size_type(length)));
member.set_role_size(static_cast<osmium::string_size_type>(length) + 1);
add_size(append_with_zero(role, static_cast<osmium::memory::item_size_type>(length)));
add_padding(true);
}
@ -331,16 +330,16 @@ namespace osmium {
if (length > osmium::max_osm_string_length) {
throw std::length_error{"OSM user name is too long"};
}
comment.set_user_size(osmium::string_size_type(length) + 1);
add_size(append_with_zero(user, osmium::memory::item_size_type(length)));
comment.set_user_size(static_cast<osmium::string_size_type>(length) + 1);
add_size(append_with_zero(user, static_cast<osmium::memory::item_size_type>(length)));
}
void add_text(osmium::ChangesetComment& comment, const char* text, const std::size_t length) {
if (length > std::numeric_limits<osmium::changeset_comment_size_type>::max() - 1) {
throw std::length_error{"OSM changeset comment is too long"};
}
comment.set_text_size(osmium::changeset_comment_size_type(length) + 1);
add_size(append_with_zero(text, osmium::memory::item_size_type(length)));
comment.set_text_size(static_cast<osmium::changeset_comment_size_type>(length) + 1);
add_size(append_with_zero(text, static_cast<osmium::memory::item_size_type>(length)));
add_padding(true);
}
@ -405,18 +404,22 @@ namespace osmium {
constexpr static const std::size_t min_size_for_user = osmium::memory::padded_length(sizeof(string_size_type) + 1);
void set_user_size(string_size_type size) noexcept {
std::memcpy(item_pos() + sizeof(T), &size, sizeof(string_size_type));
}
public:
explicit OSMObjectBuilder(osmium::memory::Buffer& buffer, Builder* parent = nullptr) :
Builder(buffer, parent, sizeof(T) + min_size_for_user) {
new (&item()) T{};
add_size(min_size_for_user);
std::fill_n(object().data() + sizeof(T), min_size_for_user, 0);
object().set_user_size(1);
std::memset(object().data() + sizeof(T), 0, min_size_for_user);
set_user_size(1);
}
/**
* Get a reference to the object buing built.
* Get a reference to the object being built.
*
* Note that this reference will be invalidated by every action
* on the builder that might make the buffer grow. This includes
@ -427,7 +430,7 @@ namespace osmium {
}
/**
* Get a const reference to the object buing built.
* Get a const reference to the object being built.
*
* Note that this reference will be invalidated by every action
* on the builder that might make the buffer grow. This includes
@ -447,14 +450,14 @@ namespace osmium {
const auto size_of_object = sizeof(T) + sizeof(string_size_type);
assert(cobject().user_size() == 1 && (size() <= size_of_object + osmium::memory::padded_length(1))
&& "set_user() must be called at most once and before any sub-builders");
const auto available_space = min_size_for_user - sizeof(string_size_type) - 1;
constexpr const auto available_space = min_size_for_user - sizeof(string_size_type) - 1;
if (length > available_space) {
const auto space_needed = osmium::memory::padded_length(length - available_space);
std::fill_n(reserve_space(space_needed), space_needed, 0);
std::memset(reserve_space(space_needed), 0, space_needed);
add_size(static_cast<uint32_t>(space_needed));
}
std::copy_n(user, length, object().data() + size_of_object);
object().set_user_size(length + 1);
std::memcpy(object().data() + size_of_object, user, length);
set_user_size(length + 1);
return static_cast<TDerived&>(*this);
}
@ -484,12 +487,6 @@ namespace osmium {
return set_user(user.data(), static_cast<string_size_type>(user.size()));
}
/// @deprecated Use set_user(...) instead.
template <typename... TArgs>
OSMIUM_DEPRECATED void add_user(TArgs&&... args) {
set_user(std::forward<TArgs>(args)...);
}
OSMIUM_FORWARD(set_id)
OSMIUM_FORWARD(set_visible)
OSMIUM_FORWARD(set_deleted)
@ -608,7 +605,7 @@ namespace osmium {
Builder(buffer, parent, sizeof(Changeset) + min_size_for_user) {
new (&item()) Changeset{};
add_size(min_size_for_user);
std::fill_n(object().data() + sizeof(Changeset), min_size_for_user, 0);
std::memset(object().data() + sizeof(Changeset), 0, min_size_for_user);
object().set_user_size(1);
}
@ -644,11 +641,6 @@ namespace osmium {
OSMIUM_FORWARD(set_attribute)
OSMIUM_FORWARD(set_removed)
// @deprecated Use set_bounds() instead.
OSMIUM_DEPRECATED osmium::Box& bounds() noexcept {
return object().bounds();
}
ChangesetBuilder& set_bounds(const osmium::Box& box) noexcept {
object().bounds() = box;
return *this;
@ -663,13 +655,13 @@ namespace osmium {
ChangesetBuilder& set_user(const char* user, const string_size_type length) {
assert(cobject().user_size() == 1 && (size() <= sizeof(Changeset) + osmium::memory::padded_length(1))
&& "set_user() must be called at most once and before any sub-builders");
const auto available_space = min_size_for_user - 1;
constexpr const auto available_space = min_size_for_user - 1;
if (length > available_space) {
const auto space_needed = osmium::memory::padded_length(length - available_space);
std::fill_n(reserve_space(space_needed), space_needed, 0);
std::memset(reserve_space(space_needed), 0, space_needed);
add_size(static_cast<uint32_t>(space_needed));
}
std::copy_n(user, length, object().data() + sizeof(Changeset));
std::memcpy(object().data() + sizeof(Changeset), user, length);
object().set_user_size(length + 1);
return *this;
@ -700,12 +692,6 @@ namespace osmium {
return set_user(user.data(), static_cast<string_size_type>(user.size()));
}
/// @deprecated Use set_user(...) instead.
template <typename... TArgs>
OSMIUM_DEPRECATED void add_user(TArgs&&... args) {
set_user(std::forward<TArgs>(args)...);
}
}; // class ChangesetBuilder
#undef OSMIUM_FORWARD

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -48,13 +48,13 @@ namespace osmium {
DiffHandler() = default;
void node(const osmium::DiffNode&) const noexcept {
void node(const osmium::DiffNode& /*node*/) const noexcept {
}
void way(const osmium::DiffWay&) const noexcept {
void way(const osmium::DiffWay& /*way*/) const noexcept {
}
void relation(const osmium::DiffRelation&) const noexcept {
void relation(const osmium::DiffRelation& /*relation*/) const noexcept {
}
}; // class DiffHandler

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -49,6 +49,9 @@ namespace osmium {
* An input iterator wrapping any iterator over OSMObjects. When
* dereferenced it will yield DiffObject objects pointing to the
* underlying OSMObjects.
*
* Note that this class uses a mutable member variable internally.
* It can not be used safely in multiple threads!
*/
template <typename TBasicIterator>
class DiffIterator {
@ -88,8 +91,7 @@ namespace osmium {
m_prev(begin),
m_curr(begin),
m_next(begin == end ? begin : ++begin),
m_end(std::move(end)),
m_diff() {
m_end(std::move(end)) {
}
DiffIterator& operator++() {

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -62,7 +62,7 @@ namespace osmium {
HandlerWrapperBase(HandlerWrapperBase&&) noexcept = default;
HandlerWrapperBase& operator=(HandlerWrapperBase&&) noexcept = default;
virtual ~HandlerWrapperBase() = default;
virtual ~HandlerWrapperBase() noexcept = default;
virtual void node(const osmium::Node& /*node*/) {
}
@ -126,6 +126,14 @@ auto _name_##_dispatch(THandler& handler, const osmium::_type_& object, long) ->
m_handler(std::forward<TArgs>(args)...) {
}
HandlerWrapper(const HandlerWrapper&) = default;
HandlerWrapper& operator=(const HandlerWrapper&) = default;
HandlerWrapper(HandlerWrapper&&) noexcept = default;
HandlerWrapper& operator=(HandlerWrapper&&) noexcept = default;
~HandlerWrapper() noexcept override = default;
void node(const osmium::Node& node) final {
node_dispatch(m_handler, node, 0);
}

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -73,7 +73,6 @@ namespace osmium {
m_entities((entities & ~osmium::osm_entity_bits::area) | (m_with_areas ? osmium::osm_entity_bits::node | osmium::osm_entity_bits::way : osmium::osm_entity_bits::nothing)),
m_location_handler(location_handler),
m_reader(file, m_entities),
m_assembler_config(),
m_collector(m_assembler_config)
{
m_location_handler.ignore_errors();

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -74,6 +74,7 @@ namespace osmium {
* This constructor is not explicit on purpose allowing use of
* a Location everywhere a Coordinates object is needed.
*/
// cppcheck-suppress noExplicitConstructor
Coordinates(const osmium::Location& location) : // NOLINT(google-explicit-constructor, hicpp-explicit-conversions)
x(location.lon()),
y(location.lat()) {

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -44,6 +44,7 @@ DEALINGS IN THE SOFTWARE.
#include <osmium/osm/node_ref_list.hpp>
#include <osmium/osm/types.hpp>
#include <osmium/osm/way.hpp>
#include <osmium/util/compatibility.hpp>
#include <cstddef>
#include <stdexcept>
@ -56,7 +57,7 @@ namespace osmium {
* Exception thrown when an invalid geometry is encountered. An example
* would be a linestring with less than two points.
*/
class geometry_error : public std::runtime_error {
class OSMIUM_EXPORT geometry_error : public std::runtime_error {
std::string m_message;
osmium::object_id_type m_id;
@ -131,11 +132,11 @@ namespace osmium {
return Coordinates{location.lon(), location.lat()};
}
int epsg() const noexcept {
static int epsg() noexcept {
return 4326;
}
std::string proj_string() const {
static std::string proj_string() noexcept {
return "+proj=longlat +datum=WGS84 +no_defs";
}
@ -165,7 +166,7 @@ namespace osmium {
public:
GeometryFactory<TGeomImpl, TProjection>() :
GeometryFactory() :
m_projection(),
m_impl(m_projection.epsg()) {
}
@ -174,7 +175,7 @@ namespace osmium {
* Constructor for default initialized projection.
*/
template <typename... TArgs>
explicit GeometryFactory<TGeomImpl, TProjection>(TArgs&&... args) :
explicit GeometryFactory(TArgs&&... args) :
m_projection(),
m_impl(m_projection.epsg(), std::forward<TArgs>(args)...) {
}
@ -184,7 +185,7 @@ namespace osmium {
* projection is moved into the GeometryFactory.
*/
template <typename... TArgs>
explicit GeometryFactory<TGeomImpl, TProjection>(TProjection&& projection, TArgs&&... args) :
explicit GeometryFactory(TProjection&& projection, TArgs&&... args) :
m_projection(std::move(projection)),
m_impl(m_projection.epsg(), std::forward<TArgs>(args)...) {
}
@ -385,7 +386,7 @@ namespace osmium {
for (const auto& item : area) {
if (item.type() == osmium::item_type::outer_ring) {
auto& ring = static_cast<const osmium::OuterRing&>(item);
const auto& ring = static_cast<const osmium::OuterRing&>(item);
if (num_polygons > 0) {
m_impl.multipolygon_polygon_finish();
}
@ -396,7 +397,7 @@ namespace osmium {
++num_rings;
++num_polygons;
} else if (item.type() == osmium::item_type::inner_ring) {
auto& ring = static_cast<const osmium::InnerRing&>(item);
const auto& ring = static_cast<const osmium::InnerRing&>(item);
m_impl.multipolygon_inner_ring_start();
add_points(ring);
m_impl.multipolygon_inner_ring_finish();

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -54,7 +54,6 @@ DEALINGS IN THE SOFTWARE.
#include <osmium/geom/coordinates.hpp>
#include <osmium/geom/factory.hpp>
#include <osmium/util/compatibility.hpp>
#include <geos/geom/Coordinate.h>
#include <geos/geom/CoordinateSequence.h>
@ -70,20 +69,13 @@ DEALINGS IN THE SOFTWARE.
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <exception>
#include <iterator>
#include <memory>
#include <string>
#include <utility>
#include <vector>
// MSVC doesn't support throw_with_nested yet
#ifdef _MSC_VER
# define THROW throw
#else
# include <exception>
# define THROW std::throw_with_nested
#endif
namespace osmium {
struct geos_geometry_error : public geometry_error {
@ -123,16 +115,6 @@ namespace osmium {
m_geos_factory(&geos_factory) {
}
/**
* @deprecated Do not set SRID explicitly. It will be set to the
* correct value automatically.
*/
OSMIUM_DEPRECATED explicit GEOSFactoryImpl(int /* srid */, int srid) :
m_precision_model(new geos::geom::PrecisionModel),
m_our_geos_factory(new geos::geom::GeometryFactory{m_precision_model.get(), srid}),
m_geos_factory(m_our_geos_factory.get()) {
}
explicit GEOSFactoryImpl(int srid) :
m_precision_model(new geos::geom::PrecisionModel),
m_our_geos_factory(new geos::geom::GeometryFactory{m_precision_model.get(), srid}),
@ -145,7 +127,7 @@ namespace osmium {
try {
return point_type{m_geos_factory->createPoint(geos::geom::Coordinate{xy.x, xy.y})};
} catch (const geos::util::GEOSException& e) {
THROW(osmium::geos_geometry_error(e.what()));
std::throw_with_nested(osmium::geos_geometry_error(e.what()));
}
}
@ -155,7 +137,7 @@ namespace osmium {
try {
m_coordinate_sequence.reset(m_geos_factory->getCoordinateSequenceFactory()->create(static_cast<std::size_t>(0), 2));
} catch (const geos::util::GEOSException& e) {
THROW(osmium::geos_geometry_error(e.what()));
std::throw_with_nested(osmium::geos_geometry_error(e.what()));
}
}
@ -163,7 +145,7 @@ namespace osmium {
try {
m_coordinate_sequence->add(geos::geom::Coordinate{xy.x, xy.y});
} catch (const geos::util::GEOSException& e) {
THROW(osmium::geos_geometry_error(e.what()));
std::throw_with_nested(osmium::geos_geometry_error(e.what()));
}
}
@ -171,7 +153,7 @@ namespace osmium {
try {
return linestring_type{m_geos_factory->createLineString(m_coordinate_sequence.release())};
} catch (const geos::util::GEOSException& e) {
THROW(osmium::geos_geometry_error(e.what()));
std::throw_with_nested(osmium::geos_geometry_error(e.what()));
}
}
@ -195,7 +177,7 @@ namespace osmium {
m_polygons.emplace_back(m_geos_factory->createPolygon(m_rings[0].release(), inner_rings));
m_rings.clear();
} catch (const geos::util::GEOSException& e) {
THROW(osmium::geos_geometry_error(e.what()));
std::throw_with_nested(osmium::geos_geometry_error(e.what()));
}
}
@ -203,7 +185,7 @@ namespace osmium {
try {
m_coordinate_sequence.reset(m_geos_factory->getCoordinateSequenceFactory()->create(static_cast<std::size_t>(0), 2));
} catch (const geos::util::GEOSException& e) {
THROW(osmium::geos_geometry_error(e.what()));
std::throw_with_nested(osmium::geos_geometry_error(e.what()));
}
}
@ -211,7 +193,7 @@ namespace osmium {
try {
m_rings.emplace_back(m_geos_factory->createLinearRing(m_coordinate_sequence.release()));
} catch (const geos::util::GEOSException& e) {
THROW(osmium::geos_geometry_error(e.what()));
std::throw_with_nested(osmium::geos_geometry_error(e.what()));
}
}
@ -219,7 +201,7 @@ namespace osmium {
try {
m_coordinate_sequence.reset(m_geos_factory->getCoordinateSequenceFactory()->create(static_cast<std::size_t>(0), 2));
} catch (const geos::util::GEOSException& e) {
THROW(osmium::geos_geometry_error(e.what()));
std::throw_with_nested(osmium::geos_geometry_error(e.what()));
}
}
@ -227,7 +209,7 @@ namespace osmium {
try {
m_rings.emplace_back(m_geos_factory->createLinearRing(m_coordinate_sequence.release()));
} catch (const geos::util::GEOSException& e) {
THROW(osmium::geos_geometry_error(e.what()));
std::throw_with_nested(osmium::geos_geometry_error(e.what()));
}
}
@ -235,7 +217,7 @@ namespace osmium {
try {
m_coordinate_sequence->add(geos::geom::Coordinate{xy.x, xy.y});
} catch (const geos::util::GEOSException& e) {
THROW(osmium::geos_geometry_error(e.what()));
std::throw_with_nested(osmium::geos_geometry_error(e.what()));
}
}
@ -248,7 +230,7 @@ namespace osmium {
m_polygons.clear();
return multipolygon_type{m_geos_factory->createMultiPolygon(polygons)};
} catch (const geos::util::GEOSException& e) {
THROW(osmium::geos_geometry_error(e.what()));
std::throw_with_nested(osmium::geos_geometry_error(e.what()));
}
}
@ -264,8 +246,6 @@ namespace osmium {
} // namespace osmium
#undef THROW
#endif
#endif // OSMIUM_GEOM_GEOS_HPP

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -35,7 +35,7 @@ DEALINGS IN THE SOFTWARE.
#include <osmium/geom/coordinates.hpp>
#include <osmium/geom/util.hpp>
#include <osmium/osm/node_ref.hpp>
#include <osmium/osm/node_ref_list.hpp>
#include <osmium/osm/way.hpp>
#include <cmath>
@ -63,13 +63,13 @@ namespace osmium {
*
* @pre @code c1.valid() && c2.valid() @endcode
*/
inline double distance(const osmium::geom::Coordinates& c1, const osmium::geom::Coordinates& c2) {
double lonh = sin(deg_to_rad(c1.x - c2.x) * 0.5);
inline double distance(const osmium::geom::Coordinates& c1, const osmium::geom::Coordinates& c2) noexcept {
double lonh = std::sin(deg_to_rad(c1.x - c2.x) * 0.5);
lonh *= lonh;
double lath = sin(deg_to_rad(c1.y - c2.y) * 0.5);
double lath = std::sin(deg_to_rad(c1.y - c2.y) * 0.5);
lath *= lath;
const double tmp = cos(deg_to_rad(c1.y)) * cos(deg_to_rad(c2.y));
return 2.0 * EARTH_RADIUS_IN_METERS * asin(sqrt(lath + tmp * lonh));
const double tmp = std::cos(deg_to_rad(c1.y)) * std::cos(deg_to_rad(c2.y));
return 2.0 * EARTH_RADIUS_IN_METERS * std::asin(std::sqrt(lath + tmp * lonh));
}
/**
@ -78,7 +78,7 @@ namespace osmium {
inline double distance(const osmium::WayNodeList& wnl) {
double sum_length = 0;
for (auto it = wnl.begin(); it != wnl.end(); ++it) {
for (const auto* it = wnl.begin(); it != wnl.end(); ++it) {
if (std::next(it) != wnl.end()) {
sum_length += distance(it->location(), std::next(it)->location());
}
@ -87,6 +87,21 @@ namespace osmium {
return sum_length;
}
/**
* Calculate length of node list.
*/
inline double distance(const osmium::NodeRefList& nrl) {
double sum_length = 0;
for (const auto* it = nrl.begin(); it != nrl.end(); ++it) {
if (std::next(it) != nrl.end()) {
sum_length += distance(it->location(), std::next(it)->location());
}
}
return sum_length;
}
} // namespace haversine
} // namespace geom

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -49,7 +49,7 @@ namespace osmium {
constexpr double earth_radius_for_epsg3857 = 6378137.0;
constexpr double max_coordinate_epsg3857 = 20037508.34;
constexpr inline double lon_to_x(double lon) {
constexpr inline double lon_to_x(double lon) noexcept {
return earth_radius_for_epsg3857 * deg_to_rad(lon);
}
@ -116,6 +116,9 @@ namespace osmium {
* Convert the coordinates from WGS84 lon/lat to web mercator.
*
* @pre @code c.valid() @endcode
* @pre Coordinates must be in valid range, longitude between
* -180 and +180 degree, latitude between -MERCATOR_MAX_LAT
* and MERCATOR_MAX_LAT.
*/
inline Coordinates lonlat_to_mercator(const Coordinates& c) {
return Coordinates{detail::lon_to_x(c.x), detail::lat_to_y(c.y)};
@ -125,6 +128,8 @@ namespace osmium {
* Convert the coordinates from web mercator to WGS84 lon/lat.
*
* @pre @code c.valid() @endcode
* @pre Coordinates must be in valid range (longitude and
* latidude between -/+20037508.34).
*/
inline Coordinates mercator_to_lonlat(const Coordinates& c) {
return Coordinates{detail::x_to_lon(c.x), detail::y_to_lat(c.y)};
@ -145,15 +150,22 @@ namespace osmium {
MercatorProjection() { // NOLINT(hicpp-use-equals-default, modernize-use-equals-default)
}
/**
* Do coordinate transformation.
*
* @pre Coordinates must be in valid range, longitude between
* -180 and +180 degree, latitude between -MERCATOR_MAX_LAT
* and MERCATOR_MAX_LAT.
*/
Coordinates operator()(osmium::Location location) const {
return Coordinates{detail::lon_to_x(location.lon()), detail::lat_to_y(location.lat())};
}
int epsg() const noexcept {
static int epsg() noexcept {
return 3857;
}
std::string proj_string() const {
static std::string proj_string() noexcept {
return "+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";
}

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -82,7 +82,7 @@ namespace osmium {
/* Point */
point_type make_point(const osmium::geom::Coordinates& xy) const {
static point_type make_point(const osmium::geom::Coordinates& xy) {
return point_type{new OGRPoint{xy.x, xy.y}};
}

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -46,8 +46,15 @@ DEALINGS IN THE SOFTWARE.
#include <osmium/geom/mercator_projection.hpp>
#include <osmium/geom/util.hpp>
#include <osmium/osm/location.hpp>
#include <osmium/util/compatibility.hpp>
#include <proj_api.h>
#ifdef ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
# include <proj_api.h>
#else
# define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
# include <proj_api.h>
# undef ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
#endif
#include <memory>
#include <string>
@ -58,8 +65,10 @@ namespace osmium {
/**
* C++ wrapper for a Coordinate Reference System of the proj library.
*
* @deprecated Only supports the old PROJ API.
*/
class CRS {
class OSMIUM_DEPRECATED CRS {
struct ProjCRSDeleter {
void operator()(void* crs) {
@ -110,9 +119,10 @@ namespace osmium {
* Coordinates have to be in radians and are produced in radians.
*
* @throws osmium::projection_error if the projection fails
*
* @deprecated Only supports the old PROJ API.
*/
// cppcheck-suppress passedByValue (because c is small and we want to change it)
inline Coordinates transform(const CRS& src, const CRS& dest, Coordinates c) {
inline OSMIUM_DEPRECATED Coordinates transform(const CRS& src, const CRS& dest, Coordinates c) {
const int result = pj_transform(src.get(), dest.get(), 1, 1, &c.x, &c.y, nullptr);
if (result != 0) {
throw osmium::projection_error{std::string{"projection failed: "} + pj_strerrno(result)};
@ -130,8 +140,10 @@ namespace osmium {
* implementation of the Mercator projection is used, otherwise this
* falls back to using the proj.4 library. Note that this "magic" does
* not work if you use any of the constructors taking a string.
*
* @deprecated Only supports the old PROJ API.
*/
class Projection {
class OSMIUM_DEPRECATED Projection {
int m_epsg;
std::string m_proj_string;
@ -140,9 +152,9 @@ namespace osmium {
public:
explicit Projection(const std::string& proj_string) :
explicit Projection(std::string proj_string) :
m_epsg(-1),
m_proj_string(proj_string),
m_proj_string(std::move(proj_string)),
m_crs_user(proj_string) {
}
@ -158,6 +170,12 @@ namespace osmium {
m_crs_user(epsg) {
}
/**
* Do coordinate transformation.
*
* @pre Location must be in valid range (depends on projection
* used).
*/
Coordinates operator()(osmium::Location location) const {
if (m_epsg == 4326) {
return Coordinates{location.lon(), location.lat()};

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -47,6 +47,9 @@ namespace osmium {
/**
* A geometry factory implementation that can be used with the
* RapidJSON (https://github.com/miloyip/rapidjson) JSON writer.
*
* @deprecated The RapidJSON support will be removed in a future
* version of libosmium.
*/
template <typename TWriter>
class RapidGeoJSONFactoryImpl {

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -58,7 +58,7 @@ namespace osmium {
* level.
*/
inline constexpr uint32_t num_tiles_in_zoom(uint32_t zoom) noexcept {
return 1u << zoom;
return 1U << zoom;
}
/**
@ -77,8 +77,7 @@ namespace osmium {
inline constexpr uint32_t mercx_to_tilex(uint32_t zoom, double x) noexcept {
return static_cast<uint32_t>(detail::clamp<int32_t>(
static_cast<int32_t>((x + detail::max_coordinate_epsg3857) / tile_extent_in_zoom(zoom)),
0, num_tiles_in_zoom(zoom) -1
));
0, num_tiles_in_zoom(zoom) - 1));
}
/**
@ -89,8 +88,7 @@ namespace osmium {
inline constexpr uint32_t mercy_to_tiley(uint32_t zoom, double y) noexcept {
return static_cast<uint32_t>(detail::clamp<int32_t>(
static_cast<int32_t>((detail::max_coordinate_epsg3857 - y) / tile_extent_in_zoom(zoom)),
0, num_tiles_in_zoom(zoom) -1
));
0, num_tiles_in_zoom(zoom) - 1));
}
/**
@ -98,6 +96,10 @@ namespace osmium {
*/
struct Tile {
enum {
max_zoom = 30U
};
/// x coordinate
uint32_t x;
@ -119,7 +121,7 @@ namespace osmium {
x(tx),
y(ty),
z(zoom) {
assert(zoom <= 30u);
assert(zoom <= max_zoom);
assert(x < num_tiles_in_zoom(zoom));
assert(y < num_tiles_in_zoom(zoom));
}
@ -134,7 +136,7 @@ namespace osmium {
*/
explicit Tile(uint32_t zoom, const osmium::Location& location) :
z(zoom) {
assert(zoom <= 30u);
assert(zoom <= max_zoom);
assert(location.valid());
const auto coordinates = lonlat_to_mercator(location);
x = mercx_to_tilex(zoom, coordinates.x);
@ -151,7 +153,7 @@ namespace osmium {
*/
explicit Tile(uint32_t zoom, const osmium::geom::Coordinates& coordinates) :
z(zoom) {
assert(zoom <= 30u);
assert(zoom <= max_zoom);
x = mercx_to_tilex(zoom, coordinates.x);
y = mercy_to_tiley(zoom, coordinates.y);
}
@ -162,7 +164,7 @@ namespace osmium {
* each be between 0 and 2^zoom-1.
*/
bool valid() const noexcept {
if (z > 30) {
if (z > max_zoom) {
return false;
}
const auto max = num_tiles_in_zoom(z);

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -33,6 +33,8 @@ DEALINGS IN THE SOFTWARE.
*/
#include <osmium/util/compatibility.hpp>
#include <stdexcept>
#include <string>
@ -42,7 +44,7 @@ namespace osmium {
* Exception thrown when a projection object can not be initialized or the
* projection of some coordinates can not be calculated.
*/
struct projection_error : public std::runtime_error {
struct OSMIUM_EXPORT projection_error : public std::runtime_error {
explicit projection_error(const std::string& what) :
std::runtime_error(what) {

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@ -35,7 +35,6 @@ DEALINGS IN THE SOFTWARE.
#include <osmium/geom/coordinates.hpp>
#include <osmium/geom/factory.hpp>
#include <osmium/util/cast.hpp>
#include <osmium/util/endian.hpp>
#include <algorithm>
@ -69,9 +68,9 @@ namespace osmium {
std::string out;
out.reserve(str.size() * 2);
for (char c : str) {
out += lookup_hex[(static_cast<unsigned int>(c) >> 4u) & 0xfu];
out += lookup_hex[ static_cast<unsigned int>(c) & 0xfu];
for (const char c : str) {
out += lookup_hex[(static_cast<unsigned int>(c) >> 4U) & 0xfU];
out += lookup_hex[ static_cast<unsigned int>(c) & 0xfU];
}
return out;
@ -202,6 +201,34 @@ namespace osmium {
return data;
}
/* Polygon */
void polygon_start() {
m_data.clear();
set_size(header(m_data, wkbPolygon, true), 1);
m_ring_size_offset = m_data.size();
str_push(m_data, static_cast<uint32_t>(0));
}
void polygon_add_location(const osmium::geom::Coordinates& xy) {
str_push(m_data, xy.x);
str_push(m_data, xy.y);
}
polygon_type polygon_finish(std::size_t num_points) {
set_size(m_ring_size_offset, num_points);
std::string data;
using std::swap;
swap(data, m_data);
if (m_out_type == out_type::hex) {
return convert_to_hex(data);
}
return data;
}
/* MultiPolygon */
void multipolygon_start() {

View File

@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003

Some files were not shown because too many files have changed in this diff Show More