pax_global_header00006660000000000000000000000064137753375520014533gustar00rootroot0000000000000052 comment=5b8c95fb1da8f9a1d7268ca90a720db4a7b9f84d OSM-binary-1.5.0/000077500000000000000000000000001377533755200134565ustar00rootroot00000000000000OSM-binary-1.5.0/.github/000077500000000000000000000000001377533755200150165ustar00rootroot00000000000000OSM-binary-1.5.0/.github/actions/000077500000000000000000000000001377533755200164565ustar00rootroot00000000000000OSM-binary-1.5.0/.github/actions/build-windows/000077500000000000000000000000001377533755200212455ustar00rootroot00000000000000OSM-binary-1.5.0/.github/actions/build-windows/action.yml000066400000000000000000000006371377533755200232530ustar00rootroot00000000000000name: Windows Build 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 shell: bash working-directory: build - name: Build run: cmake --build . shell: bash working-directory: build OSM-binary-1.5.0/.github/actions/build/000077500000000000000000000000001377533755200175555ustar00rootroot00000000000000OSM-binary-1.5.0/.github/actions/build/action.yml000066400000000000000000000007421377533755200215600ustar00rootroot00000000000000name: Build runs: using: composite steps: - name: Create build directory run: mkdir build shell: bash - name: Configure run: cmake -LA .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} shell: bash working-directory: build - name: Build run: make VERBOSE=1 shell: bash working-directory: build - name: Run outline run: build/tools/osmpbf-outline resources/sample.pbf shell: bash OSM-binary-1.5.0/.github/actions/install-macos/000077500000000000000000000000001377533755200212245ustar00rootroot00000000000000OSM-binary-1.5.0/.github/actions/install-macos/action.yml000066400000000000000000000002321377533755200232210ustar00rootroot00000000000000name: Install Prerequisites on macOS runs: using: composite steps: - name: Install packages run: brew install protobuf shell: bash OSM-binary-1.5.0/.github/actions/install-ubuntu/000077500000000000000000000000001377533755200214445ustar00rootroot00000000000000OSM-binary-1.5.0/.github/actions/install-ubuntu/action.yml000066400000000000000000000003001377533755200234350ustar00rootroot00000000000000name: Install Prerequisites on Ubuntu runs: using: composite steps: - name: Install packages run: sudo apt-get install -yq protobuf-compiler libprotobuf-dev shell: bash OSM-binary-1.5.0/.github/actions/install-windows/000077500000000000000000000000001377533755200216145ustar00rootroot00000000000000OSM-binary-1.5.0/.github/actions/install-windows/action.yml000066400000000000000000000003001377533755200236050ustar00rootroot00000000000000name: Install Prerequisites on Windows runs: using: composite steps: - name: Install packages run: vcpkg install protobuf:x64-windows zlib:x64-windows shell: powershell OSM-binary-1.5.0/.github/workflows/000077500000000000000000000000001377533755200170535ustar00rootroot00000000000000OSM-binary-1.5.0/.github/workflows/c.yml000066400000000000000000000042771377533755200200320ustar00rootroot00000000000000name: C CI on: [push, pull_request] jobs: ubuntu16: runs-on: ubuntu-16.04 env: CC: gcc CXX: g++ CXXFLAGS: -Werror -Wall -pedantic BUILD_TYPE: Debug steps: - uses: actions/checkout@v2 - uses: ./.github/actions/install-ubuntu - uses: ./.github/actions/build ubuntu18: runs-on: ubuntu-18.04 env: CC: gcc CXX: g++ CXXFLAGS: -Werror -Wall -pedantic BUILD_TYPE: Debug steps: - uses: actions/checkout@v2 - uses: ./.github/actions/install-ubuntu - uses: ./.github/actions/build ubuntu20: runs-on: ubuntu-20.04 env: CC: gcc CXX: g++ CXXFLAGS: -Werror -Wall -pedantic BUILD_TYPE: Debug steps: - uses: actions/checkout@v2 - uses: ./.github/actions/install-ubuntu - uses: ./.github/actions/build ubuntu20-clang: runs-on: ubuntu-20.04 env: CC: clang-10 CXX: clang++-10 CXXFLAGS: -Werror -Wall -pedantic BUILD_TYPE: Debug steps: - uses: actions/checkout@v2 - uses: ./.github/actions/install-ubuntu - uses: ./.github/actions/build ubuntu20-release: runs-on: ubuntu-20.04 env: CC: gcc CXX: g++ # disabled array-bounds warning because it is triggered by code generated by the protoc compiler CXXFLAGS: -Werror -Wall -pedantic -Wno-array-bounds BUILD_TYPE: Release steps: - uses: actions/checkout@v2 - uses: ./.github/actions/install-ubuntu - uses: ./.github/actions/build ubuntu20-make: runs-on: ubuntu-20.04 env: CC: gcc CXX: g++ CXXFLAGS: -Werror -Wall -pedantic steps: - uses: actions/checkout@v2 - uses: ./.github/actions/install-ubuntu - run: make -C src macos: runs-on: macos-latest env: CC: clang CXX: clang++ CXXFLAGS: -Werror -Wall -pedantic BUILD_TYPE: Debug steps: - uses: actions/checkout@v2 - uses: ./.github/actions/install-macos - uses: ./.github/actions/build windows: runs-on: windows-latest steps: - uses: actions/checkout@v2 - uses: ./.github/actions/install-windows - uses: ./.github/actions/build-windows OSM-binary-1.5.0/.github/workflows/java.yml000066400000000000000000000005521377533755200205210ustar00rootroot00000000000000name: Java CI on: [push, pull_request] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - run: sudo apt-get install protobuf-compiler - name: Set up JDK 1.8 uses: actions/setup-java@v1 with: java-version: 1.8 - name: Build with Maven run: mvn -B package --file pom.xml OSM-binary-1.5.0/.gitignore000066400000000000000000000001771377533755200154530ustar00rootroot00000000000000/build osmpbf.jar generated.java include/osmpbf/*.pb.h src/*.pb.h src/*.pb.o src/libosmpbf.a target *.swp obj-x86_64-linux-gnu OSM-binary-1.5.0/CHANGELOG.md000066400000000000000000000062741377533755200153000ustar00rootroot00000000000000## Unreleased ## Release notes for 1.5.0 (2021-01-06) - C: Support hardening buildflags set in the environment ([09845ca4](https://github.com/openstreetmap/OSM-binary/commit/09845ca4087c7404b1de33914233dbf53f9de4c3)) - C: Updated CMake configuration. This can now completely replace the configuration using the Makefiles. The Makefiles are deprecated now and will be removed in a future version. - Proto: Add optional way to add node locations to way ([e7d3201](https://github.com/openstreetmap/OSM-binary/commit/e7d3201a97a86ef0c0608bfcd960e44e54962d7b)) - Proto: Add optional LZ4 and ZSTD compressed data blocks ([218bfe8](https://github.com/openstreetmap/OSM-binary/commit/218bfe8ed800173279ede2d9028fd9a5c33d12e4)) ## Release notes for 1.4.0 (2020-10-20) - License the `.proto` and header files under MIT ([5a4c8c11](https://github.com/openstreetmap/OSM-binary/commit/5a4c8c11564104afca14b787ef14131053977b5b)) - Proto: Disable deprecated `optimize_for = LITE_RUNTIME` option ([f7b77826](https://github.com/openstreetmap/OSM-binary/commit/f7b77826e493ce272daf5b1fe8b2143a818134c9)) - Proto: Specify `proto2` syntax to fix warnings with protobuf 3.0.0 ([17f2228c](https://github.com/openstreetmap/OSM-binary/commit/17f2228ca80a6477af947c4d282b99a19482fb73)) - C: Build and install a shared library ([cfea70cd](https://github.com/openstreetmap/OSM-binary/commit/cfea70cdc8f321c950f53250cd9b580043ab3266)) - C: Add support for large files ([779715f1](https://github.com/openstreetmap/OSM-binary/commit/779715f1a09f32e235d6d621b37596632d8bcba0)) - Java: Deploy Java library to Maven Central ([7a05c39e](https://github.com/openstreetmap/OSM-binary/commit/7a05c39ea5dcb8b8794e2a1b531b506ce1fae5f8)) - Java: Update Java build - Enable GitHub CI for Java and C ([fcdf48d9](https://github.com/openstreetmap/OSM-binary/commit/fcdf48d942578af38897d4ea9f911bcdd888b3de), [2a636a31](https://github.com/openstreetmap/OSM-binary/commit/2a636a31f07d47cbb247a064bf8ec2bf9bc2bf65)) ## Release notes for 1.3.3 (2014-03-15) - Fixed ant build file. ## Release notes for 1.3.2 (2014-03-12) - Small bugfixes and build enhancements. - Improved Debian build in coordination with Debian maintainers. ## Release notes for 1.3.1 (2013-12-11) - Several building fixes and enhancements. ## Release notes for 1.3.0 (2012-12-04) - Add osmosis replication fields into the header. -- Changes from Frederick Ramm ## Release notes for 1.2.1 (2011-10-29) ## Release notes for 1.2.0 (NOT RELEASED) - Bad tag, so not releasable. - Switched to the lite (non-introspective) version of protocol buffers for a smaller library. - Includes support for "visible" flag on OSM objects. This allows PBF to handle OSM history files. - Namespace and include conventions changes for the C++ library. Everything is in the OSMPBF namespace. You now do: #include - Added stuff needed to build Debian/Ubuntu libosmpbf-dev package containing the C++ library. - Added osmpbf-outline tool that shows internals of a PBF file for debugging. - Added magic file that can recognize OSM PBF files. -- Changes from Jochen Topf Peter - Added a pom.xml -- Changes from Zsombor Welker OSM-binary-1.5.0/CMakeLists.txt000066400000000000000000000004671377533755200162250ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.7) project(osmpbf VERSION 1.5.0) include(GNUInstallDirs) set(CMAKE_CXX_STANDARD 11) find_package(Protobuf REQUIRED) add_subdirectory(osmpbf) # The osmpbf-outline tool does not compile on Windows because getopt.h is missing if(NOT MSVC) add_subdirectory(tools) endif() OSM-binary-1.5.0/LICENSE000066400000000000000000000167431377533755200144760ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. OSM-binary-1.5.0/README.md000066400000000000000000000040361377533755200147400ustar00rootroot00000000000000 # OSMPBF https://github.com/openstreetmap/OSM-binary Osmpbf is a Java/C library to read and write OpenStreetMap PBF files. PBF (Protocol buffer Binary Format) is a binary file format for OpenStreetMap data that uses Google Protocol Buffers as low-level storage. For more information see https://wiki.openstreetmap.org/wiki/PBF_Format . Note that this is a low-level library that does only part of the encoding/decoding needed for actually writing/reading an OSM PBF file. For something more complete see [libosmium](https://osmcode.org/libosmium/). [![Github Actions C Build Status](https://github.com/openstreetmap/OSM-binary/workflows/C%20CI/badge.svg?branch=master)](https://github.com/openstreetmap/OSM-binary/actions) [![Github Actions Java Build Status](https://github.com/openstreetmap/OSM-binary/workflows/Java%20CI/badge.svg?branch=master)](https://github.com/openstreetmap/OSM-binary/actions) ## Java Version We publish the Java library to [Maven Central](https://search.maven.org/): ```xml org.openstreetmap.pbf osmpbf 1.5.0 ``` To build the Java library run: ```sh mvn package ``` For a Java usage example, see [`ReadFileTest`](https://github.com/openstreetmap/OSM-binary/blob/master/test.java/crosby/binary/ReadFileTest.java) ## C++ Version (Earlier versions used Makefiles for building. Please switch to the CMake-based build, the Makefiles are deprecated and will be removed in a future version.) To compile: ```sh mkdir build && cd build cmake .. make ``` To install: ```sh make install ``` There is a tool named osmpbf-outline that shows a debug output of the contents of a PBF file. To run it: ```sh tools/osmpbf-outline osm-file.osm.pbf ``` ## Using the C++ Library To include in your program use: ```c #include ``` and link with: ``` -pthread -lz -lprotobuf -losmpbf ``` ## License The .proto definition files and osmpbf.h are licensed under the MIT license. The other source code is licensed under the LGPL v3+. OSM-binary-1.5.0/include/000077500000000000000000000000001377533755200151015ustar00rootroot00000000000000OSM-binary-1.5.0/include/osmpbf/000077500000000000000000000000001377533755200163675ustar00rootroot00000000000000OSM-binary-1.5.0/include/osmpbf/osmpbf.h000066400000000000000000000035021377533755200200260ustar00rootroot00000000000000#ifndef OSMPBF_H #define OSMPBF_H /* Copyright 2011-2014 Jochen Topf , Copyrigt 2012 Scott A. Crosby. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ // this describes the low-level blob storage #include // IWYU pragma: export // this describes the high-level OSM objects #include // IWYU pragma: export #define OSMPBF_VERSION "1.5.0" namespace OSMPBF { // the maximum size of a blob header in bytes const int max_blob_header_size = 64 * 1024; // 64 kB // the maximum size of an uncompressed blob in bytes const int max_uncompressed_blob_size = 32 * 1024 * 1024; // 32 MB // resolution for longitude/latitude used for conversion // between representation as double and as int const int lonlat_resolution = 1000 * 1000 * 1000; } #endif // OSMPBF_H OSM-binary-1.5.0/magic000066400000000000000000000001571377533755200144640ustar00rootroot00000000000000# Magic data for file(1) command. # Format is described in magic(5). 6 string OSMHeader OpenStreetMap PBF OSM-binary-1.5.0/osmpbf000077700000000000000000000000001377533755200153742srcustar00rootroot00000000000000OSM-binary-1.5.0/pom.xml000066400000000000000000000111201377533755200147660ustar00rootroot00000000000000 4.0.0 org.openstreetmap.pbf osmpbf jar 1.5.0 OSM-Binary Library for the OpenStreetMap PBF format https://github.com/openstreetmap/OSM-binary GNU General Lesser Public License (LGPL) version 3.0 http://www.gnu.org/licenses/lgpl-3.0.txt repo https://github.com/openstreetmap/OSM-binary https://github.com/openstreetmap/OSM-binary.git osm-dev OpenStreetMap developers dev@openstreetmap.org UTF-8 ${basedir}/src.java ${basedir}/test.java ${basedir}/resources org.apache.maven.plugins maven-compiler-plugin 3.8.1 1.8 1.8 org.xolstice.maven.plugins protobuf-maven-plugin 0.6.1 protoc generate-sources compile test-compile generate-sources ${basedir}/src **/*.proto org.apache.maven.plugins maven-source-plugin 3.2.0 attach-sources jar-no-fork org.apache.maven.plugins maven-javadoc-plugin 3.2.0 false attach-javadocs jar org.apache.maven.plugins maven-gpg-plugin 1.6 sign-artifacts verify sign dtrott http://maven.davidtrott.com/repository junit junit 4.13.1 test com.google.protobuf protobuf-java 3.13.0 ossrh https://oss.sonatype.org/service/local/staging/deploy/maven2 ossrh https://oss.sonatype.org/content/repositories/snapshots OSM-binary-1.5.0/resources/000077500000000000000000000000001377533755200154705ustar00rootroot00000000000000OSM-binary-1.5.0/resources/GranFileBlock1-deflate.osm.pbf000066400000000000000000000005661377533755200231120ustar00rootroot00000000000000 OSMHeader8,4xS/ NHM 33SrI+NOI-b ,Lv*/s˯4G OSMDataxbt6OK+N-1D0Lc4E0LsB(K,%!_C~\ G"i%x^h:\X$%q #]2 `|ӻ3OZF_ OSMData}xxbt6OK+N-1D0Lc4E0LsBȄK,!fFFf)f&f  乸8qHKP##5~e?&0S-Svo0OSM-binary-1.5.0/resources/GranFileBlock1-none.osm.pbf000066400000000000000000000007351377533755200224430ustar00rootroot00000000000000 OSMHeader0 ,"OsmSchema-V0.6" DenseNodes QuickBrownFox, OSMData  Z C1Offset1 C1Offset2 C1Offset3 C1Offset4 C1Offset5 C1Offset6 C1Offset7 C1Offset8T š " (@H Ě "f (@H ƚ "g(@H 썹%M OSMData  Z C2Offset1 C2Offset2 C2Offset3 C2Offset4 C2Offset5 C2Offset6 C2Offset7 C2Offset84 š @H Ě @H ƚ @H ,QOSM-binary-1.5.0/resources/SimpleFileBlock1-deflate.osm.pbf000066400000000000000000000007401377533755200234460ustar00rootroot00000000000000 OSMHeader8,4xS/ NHM 33SrI+NOI-b ,Lv*/s˯4G OSMDataxbt2OK+N-1D0Lc4E0LsBHK##Cä_le:i}rz1!')aBLLRL,NlEԥd8.@IV)&f6'e@,R<)fBzJ7YXYXXR؂X{Y!.pbbcb bbbq.F';ng}G{ 62ݰS8d>33 V: OSMData~yxbt2OK+N-1D0Lc4E0LsBȍ,..C@~@ "}c }Ⱦ >dX!sޝWT0y/)7OSM-binary-1.5.0/resources/SimpleFileBlock1-none.osm.pbf000066400000000000000000000011331377533755200227760ustar00rootroot00000000000000 OSMHeader0 ,"OsmSchema-V0.6" DenseNodes QuickBrownFox, OSMData  Z B1Offset1 B1Offset2 B1Offset3 B1Offset4 B1Offset5 B1Offset6 B1Offset7 B1Offset8% @{H @ HBB'BB."BJdR"BJx R?= BrrrJr{R  OSMData  Z B2Offset1 B2Offset2 B2Offset3 B2Offset4 B2Offset5 B2Offset6 B2Offset7 B2Offset8F  @H š @H Ě @H ƚ @H Ț @H ʚ @H 썹%MOSM-binary-1.5.0/resources/sample.pbf000066400000000000000000000226651377533755200174550ustar00rootroot00000000000000 OSMHeaderx8}F7dxq΍Ff]kdV/ NHM 33SrI+NOI- /* ,H/H͋tib/M+K-*Q03wbT())////.)JM-M,/JO, 2* OSMData.:.xXyTTg}ェzl.hC3bLLb{:v4=I/38DHDƤ9]ž#P#Zž/;s_33ܯ޻} ѹj|[F͙] `gcc; 7&淌68{ؔ^`!0BW~W-o7}u.C0Zݶ0 Λ] #Z\0ǎ5K r<; #cf{fP6;Ğ8~(vFwmɖ]wF,VU3 s#S_d>/-w|mF늑-}3f OIi=g[F_fF&A4w.pBh஑W= 4ꞅĄ5[#F7b 335 ׾~*LU06gǎ74df6׵~`˟y]7SM<ûb|[p;3{6Y=θ1+OI]2p zW5JwxQF]LU!>VHR%#Ss5gm R7:H΍+E+IEi(y5";V*+pu`&A[gkR}J^w[4SRJҏ=%ǤV!cRS0O9Q)y0]^Qs* 8oVDJ7{Z.)le8oMJȑ <.'(>ao+kDU^߲V"=F)!cEյElt:,& v[rI#4Jꀱ8r`dfrz+Y:6%*VJܨ16'ɝk%]m7]6AJԱF; _Z !oynJMT"eY[])\ m]qy ] (b%bW [㶐p՞ t )- (|L<!CFçRMؾʬznO>iRKRKrʩm<&/@ : .e+͎7F<Fʆ0%]Q.kMYF䘋"6d@-^Y;TUpWE^18w5הr ~.`tr h=hYgnГTCsC$KSLO.cnf({F&駋];.o},/_tuhKƒT5TϹ*pXviQt+ш1:ž>a21̰pb-xrf;]k'aaϽYWn~aPE֌0~8gT/EǶoȄ ؓ0A@QgjG6@- Al-+hPJs}n N DnwADU5*XT#5h URO=ἒLhcj5ú %^TP^kU$"I샄͚W姺?>-ԎUXA|cJIPQʗ:_h}x*DqFIgZ}ǻNKZF?M tY|Ty E* 4YC<Q,:b`τ)ywEICՁ1VxHbqT LlD뮡x{rd?95}qyKRY =|Euzx!cXS i/@΀b[L +eMKW57bIGn4jLt, ) <>2HYrDHa稔Tǝ5ͳeSd$g[U1ɶ?iSsi`ԇ9ç0IHWWlÈ0-m/Ѡ{QqT66>Έ*E5=zY /P(U'YO,|a~ u:{x~{aBIožZbRX@Q]QU05fc z[.Kݏ0 ?ٌcxxduo}KwB"#1 ]=.6G  RVʔ50JEӋ0'p4##U׺>NOr:U6|㖧┲?tI*=q۽\yE3T}B\ L :cb(}䨟@}&mcKkm]k=xER{~6jOA6B[0w]- j 4vmDr0åP}LVuq2><ުcƈ zyVli)@X|uL(m_qlQaK e>+kNc%S߮8e `8:wZkK.*q½ Cc!qǢ]Z m]˸3*y7$gEl#-O$kHvsE%g%.3H/6+HdI0iD1G@^vj{[E4`v0(`_ ` X<-ZK5R+lAro2mʰx#Z[ny~{vHlAևeq󵡦i e0i1:Hy.bZ` }unpczczuű/փZ;8v0^^MӮp!ZOpJJuJtA ^ YՃuvɢ!v#9)ލ[Y'dk+V9Pѝ*6`'든ҫy ;[Tvt[*oNFm&\Ўu ͳrD@$Vvm'gt@rGv|MUEfjقyz.T]\ON6a% 'L?lߚփJ<>ǂ)EyآvgpyxP'[wk;}Ijw|%K- _Sԥ9!1<]<)M_ȹ/jjp0.r1p0\ȹ% k\A^&XgP%~̾5-lԭ]C3(;;JםX# \ 84py eaMz&j;^t#Lh!Ku)HlQLyn r)TDX)jkcIQ2F~)3RA'`e%$U|.u2A"QC֩VlC v\:EU.Xv;{KHωIGa &)IPBAˈ'v~k 5}'Au]dI#6S}b wdډ,GT"1Xr_S?-2jh;*l7'݅yOQYk'ro`,FcRHtĄnZ7#&zPnDe_'h_:h %Z1Kt7Z=GHt &1Nx8O;EbNylq H DgEVpFQ$K'櫈o:*)|XueYhEQHok*.jEE*:CՄkugD^;%Yri6c71JOVICO+!.9$jurŅ0Kr:'*:S){q]ƽh[ҽ{ rtW7o<%m+Mpp]v~B7K'M<ʏ:EdVt-{Kr^7`wKA3+M?F%CH4=%SDl[=Kpt=8GLþZUZ+(/opS25"R$l+PHJC ",7d<0K sأ,'yO]01J*F-|QeYwF ]uk"ܙ.*#}vE1ո~hUD(_!yS1tS4w$6LJө2hoh#;?+}y<7$"NZA&8A4yL:ObO*TU0,iA~BI$Q:$݃ھ<$9*"l|W1J~˾=x#/@UOwW D{gtkg)YVK.q ϝVF{Dߘt(QdI*Д3 BUmP\ʗ X(= LĔFk%F"e'Y!~_jʝs'^iҖ:֚2f螃sm:ʳ/ҠFy kO߮\ i:5 OSMDataxVyPg{a:G\G$u#^5jf^ngХjV TT4CQFE! ƛU PP}_"ڝ?~sk\iԿ;1B X,`Uu#B}NDQgKpAE6h!{H&pv%I`kL\V5`B>ňFC0-KnL\BQtbNܒ2f!Jɂ{$NhEelPrؐCld[:y~.Eg8Pv{M蒜%)}o.i3x-̟D$.3H\j'D-@ ,J wQQ!BUdA1o牲+B1vhb,- nG}N0ǭ:"F"E|%8`OⱤ¢nQsaP`wUАñe $%wID?uY&*>tPa!ب LL} r  䂨>6q$=8F 7]-N -5ITBde&Z}$˒q YM\ T5i\ubHrsxLxqDEel>S$w h[DϏP0!*T *dޣ !kvW~jB\ cʈ{K^t63̽e5t01?;Nߣ;~\ g.]cƶ"8*|ޛj]wQkz>P~ ݆?jrn{޻v LW/\)*"%0 Ž^HYA(3?NcGY{C<0t^iE\C&te ӝ%Tu*?#ِÞ̡,j]vSqT;L'YT*:A,<ߴD,e1, ͯ_0ԯ]x극C/A5^% ot-}j(Kɮs;O$>}spY[R`~$A6MXzV{ՖW{Fw}͇p5;vk[:3:ׯϜ.R W:CB\dv>wH@{֫W;o:4=ֺ_{'R@_ے'7\d`0B|8:=9uB(^or\Q D=)Cj$ hy}w%[V>0UUzf57L| B<a->$XUpF?3^#s[K&x$2Ek؂kKN!uG H"F`5qt#TN:,ו"ub`צe+JmwAC?2iNzFrymM7Yx|Cmzrik(~F&nw ޷ ~N0ZqtoQ ?;&2.h jևkܲ~lWL-cY"1+!m@ӣA=b^FՐd,a5v0T6m)e/m+5qfLs]s k<L,v-`oo |f8-_G.#O+294 i-,sF,I1qob+,͠ ZQE3 'NH&[ *Eڭ-kH{h BA\|@ > %BP!$DRȜH5PdJ@jS33dt#dG ho}!~0c/Y%ky~ zTf1[G \XZU~ܗ[CY{r޷1/]^V?OcmV;]&rls޽MBoHX Q ?_qmf|bPVց򐱭PG+7TJ=oV& Ԕ0% O  This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package crosby.binary; import java.io.UncheckedIOException; import java.util.Date; import java.util.List; import com.google.protobuf.InvalidProtocolBufferException; import crosby.binary.file.BlockReaderAdapter; import crosby.binary.file.FileBlock; import crosby.binary.file.FileBlockPosition; import crosby.binary.file.FileFormatException; public abstract class BinaryParser implements BlockReaderAdapter { protected int granularity; private long lat_offset; private long lon_offset; protected int date_granularity; private String[] strings; /** Take a Info protocol buffer containing a date and convert it into a java Date object */ protected Date getDate(Osmformat.Info info) { if (info.hasTimestamp()) { return new Date(date_granularity * info.getTimestamp()); } else return NODATE; } public static final Date NODATE = new Date(-1); /** Get a string based on the index used. * * Index 0 is reserved to use as a delimiter, therefore, index 1 corresponds to the first string in the table * @param id the index * @return the string at the given index */ protected String getStringById(int id) { return strings[id]; } @Override public void handleBlock(FileBlock message) { try { if (message.getType().equals("OSMHeader")) { Osmformat.HeaderBlock headerblock = Osmformat.HeaderBlock .parseFrom(message.getData()); parse(headerblock); } else if (message.getType().equals("OSMData")) { Osmformat.PrimitiveBlock primblock = Osmformat.PrimitiveBlock .parseFrom(message.getData()); parse(primblock); } } catch (InvalidProtocolBufferException e) { throw new UncheckedIOException(new FileFormatException(e)); } } @Override public boolean skipBlock(FileBlockPosition block) { // System.out.println("Seeing block of type: "+block.getType()); if (block.getType().equals("OSMData")) return false; if (block.getType().equals("OSMHeader")) return false; System.out.println("Skipped block of type: " + block.getType()); return true; } /** Convert a latitude value stored in a protobuf into a double, compensating for granularity and latitude offset */ public double parseLat(long degree) { // Support non-zero offsets. (We don't currently generate them) return (granularity * degree + lat_offset) * .000000001; } /** Convert a longitude value stored in a protobuf into a double, compensating for granularity and longitude offset */ public double parseLon(long degree) { // Support non-zero offsets. (We don't currently generate them) return (granularity * degree + lon_offset) * .000000001; } /** Parse a Primitive block (containing a string table, other paramaters, and PrimitiveGroups */ public void parse(Osmformat.PrimitiveBlock block) { Osmformat.StringTable stablemessage = block.getStringtable(); strings = new String[stablemessage.getSCount()]; for (int i = 0; i < strings.length; i++) { strings[i] = stablemessage.getS(i).toStringUtf8(); } granularity = block.getGranularity(); lat_offset = block.getLatOffset(); lon_offset = block.getLonOffset(); date_granularity = block.getDateGranularity(); for (Osmformat.PrimitiveGroup groupmessage : block .getPrimitivegroupList()) { // Exactly one of these should trigger on each loop. parseNodes(groupmessage.getNodesList()); parseWays(groupmessage.getWaysList()); parseRelations(groupmessage.getRelationsList()); if (groupmessage.hasDense()) parseDense(groupmessage.getDense()); } } /** Parse a list of Relation protocol buffers and send the resulting relations to a sink. */ protected abstract void parseRelations(List rels); /** Parse a DenseNode protocol buffer and send the resulting nodes to a sink. */ protected abstract void parseDense(Osmformat.DenseNodes nodes); /** Parse a list of Node protocol buffers and send the resulting nodes to a sink. */ protected abstract void parseNodes(List nodes); /** Parse a list of Way protocol buffers and send the resulting ways to a sink. */ protected abstract void parseWays(List ways); /** Parse a header message. */ protected abstract void parse(Osmformat.HeaderBlock header); }OSM-binary-1.5.0/src.java/crosby/binary/BinarySerializer.java000066400000000000000000000125661377533755200241050ustar00rootroot00000000000000/** Copyright (c) 2010 Scott A. Crosby. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package crosby.binary; import java.io.Closeable; import java.io.Flushable; import java.io.IOException; import java.io.UncheckedIOException; import java.util.ArrayList; import java.util.List; import crosby.binary.Osmformat.PrimitiveGroup; import crosby.binary.file.BlockOutputStream; import crosby.binary.file.FileBlock; /** * Generic serializer common code * * Serialize a set of blobs and process them. Subclasses implement handlers for * different API's (osmosis, mkgmap, splitter, etc.) * * All data is converted into PrimGroupWriterInterface objects, which are then * ordered to process their data at the appropriate time. * */ public class BinarySerializer implements Closeable, Flushable { /** * Interface used to write a group of primitives. One of these for each * group type (Node, Way, Relation, DenseNode, Changeset) */ protected interface PrimGroupWriterInterface { /** This callback is invoked on each group that is going into the fileblock in order to give it a chance to * add to the stringtable pool of strings. */ public void addStringsToStringtable(); /** * This callback is invoked to request that the primgroup serialize itself into the given protocol buffer object. */ public Osmformat.PrimitiveGroup serialize(); } /** Set the granularity (precision of lat/lon, measured in unites of nanodegrees. */ public void configGranularity(int granularity) { this.granularity = granularity; } /** Set whether metadata is to be omitted */ public void configOmit(boolean omit_metadata) { this.omit_metadata = omit_metadata; } /** Configure the maximum number of entities in a batch */ public void configBatchLimit(int batch_limit) { this.batch_limit = batch_limit; } // Parameters affecting the output size. protected final int MIN_DENSE = 10; protected int batch_limit = 4000; // Parameters affecting the output. protected int granularity = 100; protected int date_granularity = 1000; protected boolean omit_metadata = false; /** How many primitives have been seen in this batch */ protected int batch_size = 0; protected int total_entities = 0; private final StringTable stringtable = new StringTable(); protected List groups = new ArrayList<>(); protected BlockOutputStream output; public BinarySerializer(BlockOutputStream output) { this.output = output; } public StringTable getStringTable() { return stringtable; } @Override public void flush() throws IOException { processBatch(); output.flush(); } @Override public void close() throws IOException { flush(); output.close(); } long debug_bytes = 0; public void processBatch() { // System.out.format("Batch of %d groups: ",groups.size()); if (groups.size() == 0) return; Osmformat.PrimitiveBlock.Builder primblock = Osmformat.PrimitiveBlock .newBuilder(); stringtable.clear(); // Preprocessing: Figure out the stringtable. for (PrimGroupWriterInterface i : groups) i.addStringsToStringtable(); stringtable.finish(); // Now, start serializing. for (PrimGroupWriterInterface i : groups) { PrimitiveGroup group = i.serialize(); if (group != null) primblock.addPrimitivegroup(group); } primblock.setStringtable(stringtable.serialize()); primblock.setGranularity(this.granularity); primblock.setDateGranularity(this.date_granularity); // Only generate data with offset (0,0) // Osmformat.PrimitiveBlock message = primblock.build(); // System.out.println(message); debug_bytes += message.getSerializedSize(); // if (message.getSerializedSize() > 1000000) // System.out.println(message); try { output.write(FileBlock.newInstance("OSMData", message .toByteString(), null)); } catch (IOException e) { throw new UncheckedIOException(e); } finally { batch_size = 0; groups.clear(); } // System.out.format("\n"); } /** Convert from a degrees represented as a double into the serialized offset in nanodegrees.. */ public long mapRawDegrees(double degrees) { return (long) ((degrees / .000000001)); } /** Convert from a degrees represented as a double into the serialized offset. */ public int mapDegrees(double degrees) { return (int) ((degrees / .0000001) / (granularity / 100)); } } OSM-binary-1.5.0/src.java/crosby/binary/StringTable.java000066400000000000000000000122761377533755200230430ustar00rootroot00000000000000/** Copyright (c) 2010 Scott A. Crosby. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package crosby.binary; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import com.google.protobuf.ByteString; /** * Class for mapping a set of strings to integers, giving frequently occurring * strings small integers. */ public class StringTable { public StringTable() { clear(); } private HashMap counts; private HashMap stringmap; private String[] set; /** * Increments the count of the given string * @param s the string */ public void incr(String s) { counts.merge(s, 1, Integer::sum); } /** After the stringtable has been built, return the offset of a string in it. * * Note, value '0' is reserved for use as a delimiter and will not be returned. * @param s the string to lookup * @return the offset of the string */ public int getIndex(String s) { return stringmap.get(s); } public void finish() { Comparator comparator = (s1, s2) -> counts.get(s2) - counts.get(s1); /* Sort the stringtable */ /* When a string is referenced, strings in the stringtable with indices: 0 : Is reserved (used as a delimiter in tags A: 1 to 127 : Uses can be represented with 1 byte B: 128 to 128**2-1 : Uses can be represented with 2 bytes, C: 128*128 to X : Uses can be represented with 3 bytes in the unlikely case we have >16k strings in a block. No block will contain enough strings that we'll need 4 bytes. There are goals that will improve compression: 1. I want to use 1 bytes for the most frequently occurring strings, then 2 bytes, then 3 bytes. 2. I want to use low integers as frequently as possible (for better entropy encoding out of deflate) 3. I want the stringtable to compress as small as possible. Condition 1 is obvious. Condition 2 makes deflate compress stringtable references more effectively. When compressing entities, delta coding causes small positive integers to occur more frequently than larger integers. Even though a stringtable references to indices of 1 and 127 both use one byte in a decompressed file, the small integer bias causes deflate to use fewer bits to represent the smaller index when compressed. Condition 3 is most effective when adjacent strings in the stringtable have a lot of common substrings. So, when I decide on the master stringtable to use, I put the 127 most frequently occurring strings into A (accomplishing goal 1), and sort them by frequency (to accomplish goal 2), but for B and C, which contain the less progressively less frequently encountered strings, I sort them lexicographically, to maximize goal 3 and ignoring goal 2. Goal 1 is the most important. Goal 2 helped enough to be worth it, and goal 3 was pretty minor, but all should be re-benchmarked. */ set = counts.keySet().toArray(new String[0]); if (set.length > 0) { // Sort based on the frequency. Arrays.sort(set, comparator); // Each group of keys that serializes to the same number of bytes is // sorted lexicographically. // to maximize deflate compression. // Don't sort the first array. There's not likely to be much benefit, and we want frequent values to be small. //Arrays.sort(set, Math.min(0, set.length-1), Math.min(1 << 7, set.length-1)); Arrays.sort(set, Math.min(1 << 7, set.length-1), Math.min(1 << 14, set.length-1)); Arrays.sort(set, Math.min(1 << 14, set.length-1), Math.min(1 << 21, set.length-1), comparator); } stringmap = new HashMap<>(2 * set.length); for (int i = 0; i < set.length; i++) { stringmap.put(set[i], i + 1); // Index 0 is reserved for use as a delimiter. } counts = null; } public void clear() { counts = new HashMap<>(100); stringmap = null; set = null; } public Osmformat.StringTable.Builder serialize() { Osmformat.StringTable.Builder builder = Osmformat.StringTable .newBuilder(); builder.addS(ByteString.copyFromUtf8("")); // Add a unused string at offset 0 which is used as a delimiter. for (String s : set) { builder.addS(ByteString.copyFromUtf8(s)); } return builder; } } OSM-binary-1.5.0/src.java/crosby/binary/file/000077500000000000000000000000001377533755200206715ustar00rootroot00000000000000OSM-binary-1.5.0/src.java/crosby/binary/file/BlockInputStream.java000066400000000000000000000026651377533755200247730ustar00rootroot00000000000000/** Copyright (c) 2010 Scott A. Crosby. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package crosby.binary.file; import java.io.Closeable; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; public class BlockInputStream implements Closeable { // TODO: Should be seekable input stream! public BlockInputStream(InputStream input, BlockReaderAdapter adaptor) { this.input = input; this.adaptor = adaptor; } public void process() throws IOException { try { while (true) { FileBlock.process(input, adaptor); } } catch (EOFException e) { adaptor.complete(); } } @Override public void close() throws IOException { input.close(); } InputStream input; BlockReaderAdapter adaptor; } OSM-binary-1.5.0/src.java/crosby/binary/file/BlockOutputStream.java000066400000000000000000000045221377533755200251660ustar00rootroot00000000000000/** Copyright (c) 2010 Scott A. Crosby. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package crosby.binary.file; import java.io.Closeable; import java.io.DataOutputStream; import java.io.Flushable; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; enum CompressFlags { NONE, DEFLATE } public class BlockOutputStream implements Closeable, Flushable { public BlockOutputStream(OutputStream output) { this.outwrite = new DataOutputStream(output); this.compression = CompressFlags.DEFLATE; } public void setCompress(CompressFlags flag) { compression = flag; } public void setCompress(String s) { if (s.equals("none")) compression = CompressFlags.NONE; else if (s.equals("deflate")) compression = CompressFlags.DEFLATE; else throw new IllegalArgumentException("Unknown compression type: " + s); } /** Write a block with the stream's default compression flag */ public void write(FileBlock block) throws IOException { this.write(block, compression); } /** Write a specific block with a specific compression flags */ public void write(FileBlock block, CompressFlags compression) throws IOException { FileBlockPosition ref = block.writeTo(outwrite, compression); writtenblocks.add(ref); } @Override public void flush() throws IOException { outwrite.flush(); } @Override public void close() throws IOException { outwrite.flush(); outwrite.close(); } OutputStream outwrite; List writtenblocks = new ArrayList<>(); CompressFlags compression; } OSM-binary-1.5.0/src.java/crosby/binary/file/BlockReaderAdapter.java000066400000000000000000000026701377533755200252170ustar00rootroot00000000000000/** Copyright (c) 2010 Scott A. Crosby. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package crosby.binary.file; /** An adaptor that receives blocks from an input stream */ public interface BlockReaderAdapter { /** * Does the reader understand this block? Does it want the data in it? * * A reference contains the metadata about a block and can saved --- or * stored ---- for future random access. However, during a strea read of the * file, does the user want this block? * * handleBlock will be called on all blocks that are not skipped, in file * order. * * */ boolean skipBlock(FileBlockPosition message); /** Called with the data in the block. */ void handleBlock(FileBlock message); /** Called when the file is fully read. */ void complete(); } OSM-binary-1.5.0/src.java/crosby/binary/file/FileBlock.java000066400000000000000000000130331377533755200233660ustar00rootroot00000000000000/** Copyright (c) 2010 Scott A. Crosby. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package crosby.binary.file; import java.io.DataOutputStream; import java.io.EOFException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.UncheckedIOException; import java.util.Arrays; import java.util.zip.Deflater; import com.google.protobuf.ByteString; import crosby.binary.Fileformat; import crosby.binary.Fileformat.BlobHeader; /** A full fileblock object contains both the metadata and data of a fileblock */ public class FileBlock extends FileBlockBase { /** Contains the contents of a block for use or further processing */ ByteString data; // serialized Format.Blob /** Don't be noisy unless the warning occurs somewhat often */ static int warncount = 0; private FileBlock(String type, ByteString blob, ByteString indexdata) { super(type, indexdata); this.data = blob; } public static FileBlock newInstance(String type, ByteString blob, ByteString indexdata) { if (blob != null && blob.size() > MAX_BODY_SIZE/2) { System.err.println("Warning: Fileblock has body size too large and may be considered corrupt"); if (blob != null && blob.size() > MAX_BODY_SIZE-1024*1024) { throw new IllegalArgumentException("This file has too many entities in a block. Parsers will reject it."); } } if (indexdata != null && indexdata.size() > MAX_HEADER_SIZE/2) { System.err.println("Warning: Fileblock has indexdata too large and may be considered corrupt"); if (indexdata != null && indexdata.size() > MAX_HEADER_SIZE-512) { throw new IllegalArgumentException("This file header is too large. Parsers will reject it."); } } return new FileBlock(type, blob, indexdata); } protected void deflateInto(crosby.binary.Fileformat.Blob.Builder blobbuilder) { int size = data.size(); Deflater deflater = new Deflater(); deflater.setInput(data.toByteArray()); deflater.finish(); byte[] out = new byte[size]; deflater.deflate(out); if (!deflater.finished()) { // Buffer wasn't long enough. Be noisy. ++warncount; if (warncount > 10 && warncount%100 == 0) System.out.println("Compressed buffers are too short, causing extra copy"); out = Arrays.copyOf(out, size + size / 64 + 16); deflater.deflate(out, deflater.getTotalOut(), out.length - deflater.getTotalOut()); if (!deflater.finished()) { throw new UncheckedIOException(new EOFException()); } } ByteString compressed = ByteString.copyFrom(out, 0, deflater .getTotalOut()); blobbuilder.setZlibData(compressed); deflater.end(); } public FileBlockPosition writeTo(OutputStream outwrite, CompressFlags flags) throws IOException { BlobHeader.Builder builder = Fileformat.BlobHeader .newBuilder(); if (indexdata != null) builder.setIndexdata(indexdata); builder.setType(type); Fileformat.Blob.Builder blobbuilder = Fileformat.Blob.newBuilder(); if (flags == CompressFlags.NONE) { blobbuilder.setRaw(data); blobbuilder.setRawSize(data.size()); } else { blobbuilder.setRawSize(data.size()); if (flags == CompressFlags.DEFLATE) deflateInto(blobbuilder); else throw new IllegalArgumentException("Compression flag not understood"); } Fileformat.Blob blob = blobbuilder.build(); builder.setDatasize(blob.getSerializedSize()); Fileformat.BlobHeader message = builder.build(); int size = message.getSerializedSize(); // System.out.format("Outputed header size %d bytes, header of %d bytes, and blob of %d bytes\n", // size,message.getSerializedSize(),blob.getSerializedSize()); (new DataOutputStream(outwrite)).writeInt(size); message.writeTo(outwrite); long offset = -1; if (outwrite instanceof FileOutputStream) offset = ((FileOutputStream) outwrite).getChannel().position(); blob.writeTo(outwrite); return FileBlockPosition.newInstance(this, offset, size); } /** Reads or skips a fileblock. */ static void process(InputStream input, BlockReaderAdapter callback) throws IOException { FileBlockHead fileblock = FileBlockHead.readHead(input); if (callback.skipBlock(fileblock)) { // System.out.format("Attempt to skip %d bytes\n",header.getDatasize()); fileblock.skipContents(input); } else { callback.handleBlock(fileblock.readContents(input)); } } public ByteString getData() { return data; } } OSM-binary-1.5.0/src.java/crosby/binary/file/FileBlockBase.java000066400000000000000000000036031377533755200241630ustar00rootroot00000000000000/** Copyright (c) 2010 Scott A. Crosby. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package crosby.binary.file; import com.google.protobuf.ByteString; /** * Base class that contains the metadata about a fileblock. * * Subclasses of this include additional fields, such as byte offsets that let a * fileblock be read in a random-access fashion, or the data itself. * * @author crosby * */ public class FileBlockBase { /** If a block header is bigger than this, fail. We use excessively large header size as an indication of corrupt files */ static final int MAX_HEADER_SIZE = 64*1024; /** If a block's size is bigger than this, fail. We use excessively large block sizes as an indication of corrupt files */ static final int MAX_BODY_SIZE = 32*1024*1024; protected FileBlockBase(String type, ByteString indexdata) { this.type = type; this.indexdata = indexdata; } /** Identifies the type of the data within a block */ protected final String type; /** * Block metadata, stored in the index block and as a prefix for every * block. */ protected final ByteString indexdata; public String getType() { return type; } public ByteString getIndexData() { return indexdata; } } OSM-binary-1.5.0/src.java/crosby/binary/file/FileBlockHead.java000066400000000000000000000066241377533755200241600ustar00rootroot00000000000000/** Copyright (c) 2010 Scott A. Crosby. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package crosby.binary.file; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import com.google.protobuf.ByteString; import crosby.binary.Fileformat; /** * Intermediate representation of the header of a fileblock when a set of * fileblocks is read as in a stream. The data in the fileblock must be either * skipped (where the returned value is a reference to the fileblock) or parsed. * * @author crosby * */ public class FileBlockHead extends FileBlockReference { protected FileBlockHead(String type, ByteString indexdata) { super(type, indexdata); } /** * Read the header. After reading the header, either the contents must be * skipped or read */ static FileBlockHead readHead(InputStream input) throws IOException { DataInputStream datinput = new DataInputStream(input); int headersize = datinput.readInt(); // System.out.format("Header size %d %x\n",headersize,headersize); if (headersize > MAX_HEADER_SIZE) { throw new FileFormatException("Unexpectedly long header "+MAX_HEADER_SIZE+ " bytes. Possibly corrupt file."); } byte[] buf = new byte[headersize]; datinput.readFully(buf); // System.out.format("Read buffer for header of %d bytes\n",buf.length); Fileformat.BlobHeader header = Fileformat.BlobHeader .parseFrom(buf); FileBlockHead fileblock = new FileBlockHead(header.getType(), header .getIndexdata()); fileblock.datasize = header.getDatasize(); if (header.getDatasize() > MAX_BODY_SIZE) { throw new FileFormatException("Unexpectedly long body "+MAX_BODY_SIZE+ " bytes. Possibly corrupt file."); } fileblock.input = input; if (input instanceof FileInputStream) fileblock.data_offset = ((FileInputStream) input).getChannel() .position(); return fileblock; } /** * Assumes the stream is positioned over at the start of the data, skip over * it. * * @throws IOException */ void skipContents(InputStream input) throws IOException { if (input.skip(getDatasize()) != getDatasize()) assert false : "SHORT READ"; } /** * Assumes the stream is positioned over at the start of the data, read it * and return the complete FileBlock * * @throws IOException */ FileBlock readContents(InputStream input) throws IOException { DataInputStream datinput = new DataInputStream(input); byte[] buf = new byte[getDatasize()]; datinput.readFully(buf); return parseData(buf); } } OSM-binary-1.5.0/src.java/crosby/binary/file/FileBlockPosition.java000066400000000000000000000075751377533755200251310ustar00rootroot00000000000000/** Copyright (c) 2010 Scott A. Crosby. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package crosby.binary.file; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; import java.util.zip.DataFormatException; import java.util.zip.Inflater; import com.google.protobuf.ByteString; import com.google.protobuf.InvalidProtocolBufferException; import crosby.binary.Fileformat; /** * Stores the position in the stream of a fileblock so that it can be easily * read in a random-access fashion. * * We can turn this into a 'real' block by appropriately seeking into the file * and doing a 'read'. * * */ public class FileBlockPosition extends FileBlockBase { protected FileBlockPosition(String type, ByteString indexdata) { super(type, indexdata); } /** Parse out and decompress the data part of a fileblock helper function. */ FileBlock parseData(byte[] buf) throws InvalidProtocolBufferException { FileBlock out = FileBlock.newInstance(type, null, indexdata); Fileformat.Blob blob = Fileformat.Blob.parseFrom(buf); if (blob.hasRaw()) { out.data = blob.getRaw(); } else if (blob.hasZlibData()) { byte[] buf2 = new byte[blob.getRawSize()]; Inflater decompresser = new Inflater(); decompresser.setInput(blob.getZlibData().toByteArray()); // decompresser.getRemaining(); try { decompresser.inflate(buf2); } catch (DataFormatException e) { throw new UncheckedIOException(new FileFormatException(e)); } assert (decompresser.finished()); decompresser.end(); out.data = ByteString.copyFrom(buf2); } return out; } public int getDatasize() { return datasize; } /* * Given any form of fileblock and an offset/length value, return a * reference that can be used to dereference and read the contents. */ static FileBlockPosition newInstance(FileBlockBase base, long offset, int length) { FileBlockPosition out = new FileBlockPosition(base.type, base.indexdata); out.datasize = length; out.data_offset = offset; return out; } public FileBlock read(InputStream input) throws IOException { if (input instanceof FileInputStream) { ((FileInputStream) input).getChannel().position(data_offset); byte[] buf = new byte[getDatasize()]; (new DataInputStream(input)).readFully(buf); return parseData(buf); } else { throw new IllegalArgumentException("Random access binary reads require seekability"); } } /** * TODO: Convert this reference into a serialized representation that can be * stored. */ public ByteString serialize() { throw new UnsupportedOperationException("TODO"); } /** TODO: Parse a serialized representation of this block reference */ static FileBlockPosition parseFrom(ByteString b) { throw new UnsupportedOperationException("TODO"); } protected int datasize; /** Offset into the file of the data part of the block */ long data_offset; } OSM-binary-1.5.0/src.java/crosby/binary/file/FileBlockReference.java000066400000000000000000000032521377533755200252070ustar00rootroot00000000000000/** Copyright (c) 2010 Scott A. Crosby. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package crosby.binary.file; import java.io.IOException; import java.io.InputStream; import com.google.protobuf.ByteString; /** * A FileBlockPosition that remembers what file this is so that it can simply be * dereferenced */ public class FileBlockReference extends FileBlockPosition { /** * Convenience cache for storing the input this reference is contained * within so that it can be cached */ protected InputStream input; protected FileBlockReference(String type, ByteString indexdata) { super(type, indexdata); } public FileBlock read() throws IOException { return read(input); } static FileBlockPosition newInstance(FileBlockBase base, InputStream input, long offset, int length) { FileBlockReference out = new FileBlockReference(base.type, base.indexdata); out.datasize = length; out.data_offset = offset; out.input = input; return out; } } OSM-binary-1.5.0/src.java/crosby/binary/file/FileFormatException.java000066400000000000000000000020501377533755200254400ustar00rootroot00000000000000/** Copyright (c) 2010 Scott A. Crosby. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package crosby.binary.file; import java.io.IOException; public class FileFormatException extends IOException { public FileFormatException(String string) { super(string); } public FileFormatException(Throwable cause) { super(cause); } /** * */ private static final long serialVersionUID = -8128010128748910923L; } OSM-binary-1.5.0/src/000077500000000000000000000000001377533755200142455ustar00rootroot00000000000000OSM-binary-1.5.0/src/CMakeLists.txt000066400000000000000000000017001377533755200170030ustar00rootroot00000000000000protobuf_generate_cpp(CPPS HS fileformat.proto osmformat.proto) add_library(osmpbf STATIC ${CPPS}) target_include_directories(osmpbf SYSTEM PUBLIC ${Protobuf_INCLUDE_DIRS}) install(TARGETS osmpbf ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) add_library(osmpbf_shared SHARED ${CPPS}) target_link_libraries(osmpbf_shared PRIVATE protobuf::libprotobuf) target_include_directories(osmpbf_shared SYSTEM PUBLIC ${Protobuf_INCLUDE_DIRS}) set_target_properties(osmpbf_shared PROPERTIES OUTPUT_NAME osmpbf VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}) install(TARGETS osmpbf_shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(FILES ${CMAKE_SOURCE_DIR}/include/osmpbf/osmpbf.h ${CMAKE_BINARY_DIR}/osmpbf/osmformat.pb.h ${CMAKE_BINARY_DIR}/osmpbf/fileformat.pb.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/osmpbf) OSM-binary-1.5.0/src/LICENSE000066400000000000000000000020641377533755200152540ustar00rootroot00000000000000MIT License Copyright (c) OpenStreetMap developers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. OSM-binary-1.5.0/src/Makefile000066400000000000000000000031071377533755200157060ustar00rootroot00000000000000 # these default settings can be overridden by setting environment variables PREFIX ?= /usr/local LIBDIR ?= $(PREFIX)/lib CXX ?= g++ CXXFLAGS ?= -O3 AR ?= ar PROTOC ?= protoc SONAME ?= libosmpbf.so.1 VERSION ?= 1.5.0 CXXFLAGS += -Wall -Wextra -pedantic -Wredundant-decls -Wdisabled-optimization -Wctor-dtor-privacy -Wnon-virtual-dtor -Woverloaded-virtual -Wsign-promo -Wno-long-long .PHONY: clean install all: libosmpbf.a libosmpbf.so ../include/osmpbf/fileformat.pb.h ../include/osmpbf/osmformat.pb.h libosmpbf.a: fileformat.pb.o osmformat.pb.o $(AR) -cr $@ fileformat.pb.o osmformat.pb.o libosmpbf.so: fileformat.pb.o osmformat.pb.o $(CXX) $(CPPFLAGS) $(LDFLAGS) -shared -Wl,-soname,$(SONAME) -o $@ fileformat.pb.o osmformat.pb.o %.pb.o: %.pb.cc $(CXX) $(CPPFLAGS) $(CXXFLAGS) -fPIC -c -o $@ $< %.pb.cc ../include/osmpbf/%.pb.h: %.proto $(PROTOC) --proto_path=. --cpp_out=. $< cp -v $(subst .proto,.pb.h,$<) ../include/osmpbf/ install: install -m 755 -d $(DESTDIR)$(LIBDIR) install -m 644 libosmpbf.a $(DESTDIR)$(LIBDIR) install -m 755 libosmpbf.so $(DESTDIR)$(LIBDIR)/libosmpbf.so.$(VERSION) ln -s libosmpbf.so.$(VERSION) $(DESTDIR)$(LIBDIR)/$(SONAME) ln -s libosmpbf.so.$(VERSION) $(DESTDIR)$(LIBDIR)/libosmpbf.so install -m 755 -d $(DESTDIR)$(PREFIX)/include/osmpbf install -m 644 ../include/osmpbf/osmpbf.h $(DESTDIR)$(PREFIX)/include/osmpbf install -m 644 ../include/osmpbf/fileformat.pb.h $(DESTDIR)$(PREFIX)/include/osmpbf install -m 644 ../include/osmpbf/osmformat.pb.h $(DESTDIR)$(PREFIX)/include/osmpbf clean: rm -f *.pb.h *.pb.cc *.pb.o libosmpbf.a OSM-binary-1.5.0/src/fileformat.proto000066400000000000000000000041561377533755200174700ustar00rootroot00000000000000/** Copyright (c) 2010 Scott A. Crosby. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ syntax = "proto2"; option java_package = "crosby.binary"; package OSMPBF; //protoc --java_out=../.. fileformat.proto // // STORAGE LAYER: Storing primitives. // message Blob { optional int32 raw_size = 2; // When compressed, the uncompressed size oneof data { bytes raw = 1; // No compression // Possible compressed versions of the data. bytes zlib_data = 3; // For LZMA compressed data (optional) bytes lzma_data = 4; // Formerly used for bzip2 compressed data. Deprecated in 2010. bytes OBSOLETE_bzip2_data = 5 [deprecated=true]; // Don't reuse this tag number. // For LZ4 compressed data (optional) bytes lz4_data = 6; // For ZSTD compressed data (optional) bytes zstd_data = 7; } } /* A file contains an sequence of fileblock headers, each prefixed by their length in network byte order, followed by a data block containing the actual data. Types starting with a "_" are reserved. */ message BlobHeader { required string type = 1; optional bytes indexdata = 2; required int32 datasize = 3; } OSM-binary-1.5.0/src/osmformat.proto000066400000000000000000000216551377533755200173520ustar00rootroot00000000000000/** Copyright (c) 2010 Scott A. Crosby. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ syntax = "proto2"; option java_package = "crosby.binary"; package OSMPBF; /* OSM Binary file format This is the master schema file of the OSM binary file format. This file is designed to support limited random-access and future extendability. A binary OSM file consists of a sequence of FileBlocks (please see fileformat.proto). The first fileblock contains a serialized instance of HeaderBlock, followed by a sequence of PrimitiveBlock blocks that contain the primitives. Each primitiveblock is designed to be independently parsable. It contains a string table storing all strings in that block (keys and values in tags, roles in relations, usernames, etc.) as well as metadata containing the precision of coordinates or timestamps in that block. A primitiveblock contains a sequence of primitive groups, each containing primitives of the same type (nodes, densenodes, ways, relations). Coordinates are stored in signed 64-bit integers. Lat&lon are measured in units nanodegrees. The default of granularity of 100 nanodegrees corresponds to about 1cm on the ground, and a full lat or lon fits into 32 bits. Converting an integer to a latitude or longitude uses the formula: $OUT = IN * granularity / 10**9$. Many encoding schemes use delta coding when representing nodes and relations. */ ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// /* Contains the file header. */ message HeaderBlock { optional HeaderBBox bbox = 1; /* Additional tags to aid in parsing this dataset */ repeated string required_features = 4; repeated string optional_features = 5; optional string writingprogram = 16; optional string source = 17; // From the bbox field. /* Tags that allow continuing an Osmosis replication */ // Replication timestamp, expressed in seconds since the epoch, // otherwise the same value as in the "timestamp=..." field // in the state.txt file used by Osmosis. optional int64 osmosis_replication_timestamp = 32; // Replication sequence number (sequenceNumber in state.txt). optional int64 osmosis_replication_sequence_number = 33; // Replication base URL (from Osmosis' configuration.txt file). optional string osmosis_replication_base_url = 34; } /** The bounding box field in the OSM header. BBOX, as used in the OSM header. Units are always in nanodegrees -- they do not obey granularity rules. */ message HeaderBBox { required sint64 left = 1; required sint64 right = 2; required sint64 top = 3; required sint64 bottom = 4; } /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// message PrimitiveBlock { required StringTable stringtable = 1; repeated PrimitiveGroup primitivegroup = 2; // Granularity, units of nanodegrees, used to store coordinates in this block. optional int32 granularity = 17 [default=100]; // Offset value between the output coordinates and the granularity grid in units of nanodegrees. optional int64 lat_offset = 19 [default=0]; optional int64 lon_offset = 20 [default=0]; // Granularity of dates, normally represented in units of milliseconds since the 1970 epoch. optional int32 date_granularity = 18 [default=1000]; } // Group of OSMPrimitives. All primitives in a group must be the same type. message PrimitiveGroup { repeated Node nodes = 1; optional DenseNodes dense = 2; repeated Way ways = 3; repeated Relation relations = 4; repeated ChangeSet changesets = 5; } /** String table, contains the common strings in each block. Note that we reserve index '0' as a delimiter, so the entry at that index in the table is ALWAYS blank and unused. */ message StringTable { repeated bytes s = 1; } /* Optional metadata that may be included into each primitive. */ message Info { optional int32 version = 1 [default = -1]; optional int64 timestamp = 2; optional int64 changeset = 3; optional int32 uid = 4; optional uint32 user_sid = 5; // String IDs // The visible flag is used to store history information. It indicates that // the current object version has been created by a delete operation on the // OSM API. // When a writer sets this flag, it MUST add a required_features tag with // value "HistoricalInformation" to the HeaderBlock. // If this flag is not available for some object it MUST be assumed to be // true if the file has the required_features tag "HistoricalInformation" // set. optional bool visible = 6; } /** Optional metadata that may be included into each primitive. Special dense format used in DenseNodes. */ message DenseInfo { repeated int32 version = 1 [packed = true]; repeated sint64 timestamp = 2 [packed = true]; // DELTA coded repeated sint64 changeset = 3 [packed = true]; // DELTA coded repeated sint32 uid = 4 [packed = true]; // DELTA coded repeated sint32 user_sid = 5 [packed = true]; // String IDs for usernames. DELTA coded // The visible flag is used to store history information. It indicates that // the current object version has been created by a delete operation on the // OSM API. // When a writer sets this flag, it MUST add a required_features tag with // value "HistoricalInformation" to the HeaderBlock. // If this flag is not available for some object it MUST be assumed to be // true if the file has the required_features tag "HistoricalInformation" // set. repeated bool visible = 6 [packed = true]; } // This is kept for backwards compatibility but not used anywhere. message ChangeSet { required int64 id = 1; } message Node { required sint64 id = 1; // Parallel arrays. repeated uint32 keys = 2 [packed = true]; // String IDs. repeated uint32 vals = 3 [packed = true]; // String IDs. optional Info info = 4; // May be omitted in omitmeta required sint64 lat = 8; required sint64 lon = 9; } /* Used to densly represent a sequence of nodes that do not have any tags. We represent these nodes columnwise as five columns: ID's, lats, and lons, all delta coded. When metadata is not omitted, We encode keys & vals for all nodes as a single array of integers containing key-stringid and val-stringid, using a stringid of 0 as a delimiter between nodes. ( ( )* '0' )* */ message DenseNodes { repeated sint64 id = 1 [packed = true]; // DELTA coded optional DenseInfo denseinfo = 5; repeated sint64 lat = 8 [packed = true]; // DELTA coded repeated sint64 lon = 9 [packed = true]; // DELTA coded // Special packing of keys and vals into one array. May be empty if all nodes in this block are tagless. repeated int32 keys_vals = 10 [packed = true]; } message Way { required int64 id = 1; // Parallel arrays. repeated uint32 keys = 2 [packed = true]; repeated uint32 vals = 3 [packed = true]; optional Info info = 4; repeated sint64 refs = 8 [packed = true]; // DELTA coded // The following two fields are optional. They are only used in a special // format where node locations are also added to the ways. This makes the // files larger, but allows creating way geometries directly. // // If this is used, you MUST set the optional_features tag "LocationsOnWays" // and the number of values in refs, lat, and lon MUST be the same. repeated sint64 lat = 9 [packed = true]; // DELTA coded, optional repeated sint64 lon = 10 [packed = true]; // DELTA coded, optional } message Relation { enum MemberType { NODE = 0; WAY = 1; RELATION = 2; } required int64 id = 1; // Parallel arrays. repeated uint32 keys = 2 [packed = true]; repeated uint32 vals = 3 [packed = true]; optional Info info = 4; // Parallel arrays repeated int32 roles_sid = 8 [packed = true]; // This should have been defined as uint32 for consistency, but it is now too late to change it repeated sint64 memids = 9 [packed = true]; // DELTA encoded repeated MemberType types = 10 [packed = true]; } OSM-binary-1.5.0/test.java/000077500000000000000000000000001377533755200153555ustar00rootroot00000000000000OSM-binary-1.5.0/test.java/crosby/000077500000000000000000000000001377533755200166565ustar00rootroot00000000000000OSM-binary-1.5.0/test.java/crosby/binary/000077500000000000000000000000001377533755200201425ustar00rootroot00000000000000OSM-binary-1.5.0/test.java/crosby/binary/ReadFileTest.java000066400000000000000000001024511377533755200233230ustar00rootroot00000000000000package crosby.binary; import crosby.binary.Osmformat.*; import crosby.binary.file.BlockInputStream; import crosby.binary.file.BlockReaderAdapter; import org.junit.Assert; import org.junit.Test; import java.io.InputStream; import java.io.PrintWriter; import java.io.StringWriter; import java.util.List; /** * Demonstrates how to read a file. Reads sample.pbf from the resources folder * and prints details about it to the standard output. * * @author Michael Tandy */ public class ReadFileTest { @Test public void test() throws Exception { String expected = ("" + "Got header block.\n" + "Dense node, ID 653970877 @ 51.763603,-0.228757\n" + "Dense node, ID 647105170 @ 51.763591,-0.234465\n" + "Dense node, ID 672663476 @ 51.765749,-0.229070\n" + "Dense node, ID 241806356 @ 51.768945,-0.232662\n" + "Dense node, ID 692945017 @ 51.766185,-0.230069\n" + "Dense node, ID 1709246734 @ 51.766433,-0.230854\n" + "Dense node, ID 175685506 @ 51.765169,-0.229374\n" + "Dense node, ID 647105129 @ 51.769327,-0.218457\n" + "Dense node, ID 647105160 @ 51.768192,-0.231686\n" + "Dense node, ID 672663473 @ 51.765530,-0.229187\n" + "Dense node, ID 647105141 @ 51.773204,-0.222598\n" + "Dense node, ID 25365926 @ 51.766340,-0.233556\n" + "Dense node, ID 1685167296 @ 51.766924,-0.234783\n" + "Dense node, ID 677439943 @ 51.763178,-0.230230\n" + "Dense node, ID 1701110757 @ 51.766400,-0.228489\n" + "Dense node, ID 663806673 @ 51.765470,-0.229220\n" + "Dense node, ID 502550970 @ 51.765118,-0.233667\n" + "Dense node, ID 692887095 @ 51.766318,-0.229190\n" + "Dense node, ID 1685167376 @ 51.760411,-0.241161\n" + "Dense node, ID 175697821 @ 51.765000,-0.232204\n" + "Dense node, ID 677438877 @ 51.764126,-0.228303\n" + "Dense node, ID 175685111 @ 51.764882,-0.229966\n" + "Dense node, ID 647105131 @ 51.769022,-0.217223\n" + "Dense node, ID 240134267 @ 51.764217,-0.233120\n" + "Dense node, ID 691203111 @ 51.765755,-0.230230\n" + "Dense node, ID 1685167394 @ 51.761213,-0.240218\n" + "Dense node, ID 534873274 @ 51.763918,-0.236563\n" + "Dense node, ID 676945192 @ 51.765148,-0.230615\n" + "Dense node, ID 691203106 @ 51.764494,-0.233449\n" + "Dense node, ID 647105155 @ 51.769580,-0.232061\n" + "Dense node, ID 32950368 @ 51.769048,-0.232790\n" + "Dense node, ID 647105133 @ 51.769183,-0.216784\n" + "Dense node, ID 175683944 @ 51.763140,-0.232112\n" + "Dense node, ID 623540467 @ 51.765719,-0.225990\n" + "Dense node, ID 647225601 @ 51.762732,-0.231722\n" + "Dense node, ID 32953195 @ 51.761987,-0.231091\n" + "Dense node, ID 653970876 @ 51.763436,-0.229153\n" + "Dense node, ID 676945352 @ 51.765646,-0.228469\n" + "Dense node, ID 663806670 @ 51.765540,-0.228771\n" + "Dense node, ID 1709246676 @ 51.766438,-0.231121\n" + "Dense node, ID 647105047 @ 51.774057,-0.222895\n" + "Dense node, ID 175697862 @ 51.765004,-0.232747\n" + "Dense node, ID 647105145 @ 51.771007,-0.230355\n" + "Dense node, ID 647105167 @ 51.762860,-0.236278\n" + "Dense node, ID 1111758067 @ 51.771433,-0.216984\n" + "Dense node, ID 647105166 @ 51.767468,-0.234229\n" + "Dense node, ID 692887118 @ 51.766186,-0.228918\n" + "Dense node, ID 663806658 @ 51.765679,-0.228614\n" + "Dense node, ID 175685507 @ 51.765508,-0.229788\n" + "Dense node, ID 647224486 @ 51.766388,-0.228706\n" + "Dense node, ID 502552074 @ 51.766711,-0.229590\n" + "Dense node, ID 647105132 @ 51.768905,-0.216932\n" + "Dense node, ID 25365925 @ 51.766651,-0.233518\n" + "Dense node, ID 623540472 @ 51.765321,-0.225475\n" + "Dense node, ID 691202857 @ 51.766804,-0.231711\n" + "Dense node, ID 175686201 @ 51.765721,-0.228361\n" + "Dense node, ID 927070648 @ 51.763087,-0.232061\n" + "Dense node, ID 25365924 @ 51.767090,-0.233453\n" + "Dense node, ID 676945335 @ 51.765388,-0.228437\n" + "Dense node, ID 647105127 @ 51.769321,-0.219637\n" + "Dense node, ID 647105134 @ 51.769124,-0.216290\n" + "Dense node, ID 30983853 @ 51.764268,-0.233185\n" + "Dense node, ID 647105164 @ 51.767548,-0.233295\n" + "Dense node, ID 502552081 @ 51.766833,-0.233484\n" + "Dense node, ID 691202855 @ 51.766809,-0.231946\n" + "Dense node, ID 647057820 @ 51.765382,-0.226710\n" + "Dense node, ID 691202869 @ 51.767216,-0.231947\n" + "Dense node, ID 647105159 @ 51.768849,-0.232458\n" + "Dense node, ID 1739780291 @ 51.764890,-0.226086\n" + "Dense node, ID 676945267 @ 51.763905,-0.228040\n" + "Dense node, ID 663806664 @ 51.765444,-0.229274\n" + "Dense node, ID 647105143 @ 51.771399,-0.230034\n" + "Dense node, ID 691202858 @ 51.765928,-0.232698\n" + "Dense node, ID 1701110775 @ 51.766290,-0.228709\n" + "Dense node, ID 365548881 @ 51.763854,-0.232807\n" + "Dense node, ID 647224465 @ 51.765604,-0.226263\n" + "Dense node, ID 691202873 @ 51.766711,-0.232826\n" + "Dense node, ID 287659881 @ 51.766233,-0.228823\n" + "Dense node, ID 1685167328 @ 51.765389,-0.235803\n" + "Dense node, ID 1685167381 @ 51.762135,-0.238938\n" + "Dense node, ID 1685167371 @ 51.768683,-0.233758\n" + "Dense node, ID 1709246791 @ 51.765771,-0.229747\n" + "Dense node, ID 647105156 @ 51.769420,-0.232072\n" + "Dense node, ID 647105139 @ 51.773291,-0.221257\n" + "Dense node, ID 32953193 @ 51.763418,-0.232387\n" + "Dense node, ID 676945199 @ 51.765151,-0.230782\n" + "Dense node, ID 647105147 @ 51.770210,-0.231976\n" + "Dense node, ID 672628083 @ 51.764391,-0.225433\n" + "Dense node, ID 25365922 @ 51.768145,-0.233167\n" + "Dense node, ID 1709246741 @ 51.765960,-0.229886\n" + "Dense node, ID 647105153 @ 51.769673,-0.232265\n" + "Dense node, ID 30983851 @ 51.765372,-0.233546\n" + "Dense node, ID 691202863 @ 51.765224,-0.232225\n" + "Dense node, ID 691202838 @ 51.767798,-0.233387\n" + "Dense node, ID 175684459 @ 51.763370,-0.231564\n" + "Dense node, ID 1685167313 @ 51.762503,-0.238485\n" + "Dense node, ID 692945016 @ 51.765714,-0.230069\n" + "Dense node, ID 25365921 @ 51.768513,-0.232722\n" + "Dense node, ID 676945322 @ 51.765118,-0.229479\n" + "Dense node, ID 534873251 @ 51.763658,-0.236760\n" + "Dense node, ID 1685167341 @ 51.768171,-0.234063\n" + "Dense node, ID 691203110 @ 51.765769,-0.230874\n" + "Dense node, ID 676945292 @ 51.764506,-0.228754\n" + "Dense node, ID 1685167391 @ 51.761506,-0.239827\n" + "Dense node, ID 676945241 @ 51.763212,-0.229644\n" + "Dense node, ID 663806653 @ 51.765898,-0.228877\n" + "Dense node, ID 623624259 @ 51.764905,-0.234965\n" + "Dense node, ID 1685167373 @ 51.763777,-0.237235\n" + "Dense node, ID 676945320 @ 51.765375,-0.230143\n" + "Dense node, ID 240134268 @ 51.764403,-0.232382\n" + "Dense node, ID 676945316 @ 51.764949,-0.230532\n" + "Dense node, ID 623624154 @ 51.765244,-0.234365\n" + "Dense node, ID 647105142 @ 51.774147,-0.226321\n" + "Dense node, ID 1739780285 @ 51.764824,-0.226000\n" + "Dense node, ID 175697671 @ 51.765012,-0.233620\n" + "Dense node, ID 647224613 @ 51.764970,-0.229134\n" + "Dense node, ID 647105121 @ 51.769055,-0.221268\n" + "Dense node, ID 692887101 @ 51.766293,-0.228488\n" + "Dense node, ID 175683342 @ 51.763273,-0.229558\n" + "Dense node, ID 240134269 @ 51.765577,-0.230133\n" + "Dense node, ID 691203053 @ 51.766871,-0.230638\n" + "Dense node, ID 1697422651 @ 51.763725,-0.228467\n" + "Dense node, ID 534873285 @ 51.764110,-0.236786\n" + "Dense node, ID 647105148 @ 51.770131,-0.232104\n" + "Dense node, ID 647105165 @ 51.767482,-0.233317\n" + "Dense node, ID 534873185 @ 51.763403,-0.236752\n" + "Dense node, ID 175685104 @ 51.764391,-0.231506\n" + "Dense node, ID 647105163 @ 51.768079,-0.233048\n" + "Dense node, ID 651652536 @ 51.764591,-0.224432\n" + "Dense node, ID 647105115 @ 51.766990,-0.227373\n" + "Dense node, ID 677439944 @ 51.763332,-0.229790\n" + "Dense node, ID 647105162 @ 51.768232,-0.232866\n" + "Dense node, ID 676945319 @ 51.765218,-0.230449\n" + "Dense node, ID 1539682123 @ 51.769102,-0.232828\n" + "Dense node, ID 534873208 @ 51.763536,-0.236889\n" + "Dense node, ID 647105128 @ 51.769354,-0.219090\n" + "Dense node, ID 1739780280 @ 51.764758,-0.225914\n" + "Dense node, ID 175698323 @ 51.767216,-0.231110\n" + "Dense node, ID 676945189 @ 51.764650,-0.230926\n" + "Dense node, ID 1739780294 @ 51.764955,-0.224922\n" + "Dense node, ID 676945326 @ 51.765291,-0.229382\n" + "Dense node, ID 663806672 @ 51.765417,-0.229059\n" + "Dense node, ID 45169425 @ 51.769130,-0.233478\n" + "Dense node, ID 672663469 @ 51.765930,-0.229036\n" + "Dense node, ID 675146 @ 51.769270,-0.232860\n" + "Dense node, ID 691203054 @ 51.766658,-0.230273\n" + "Dense node, ID 1606957353 @ 51.760049,-0.241558\n" + "Dense node, ID 647105125 @ 51.769248,-0.220260\n" + "Dense node, ID 534874147 @ 51.765262,-0.235825\n" + "Dense node, ID 14713407 @ 51.765828,-0.227391\n" + "Dense node, ID 818056434 @ 51.766040,-0.233470\n" + "Dense node, ID 1111758069 @ 51.769198,-0.216444\n" + "Dense node, ID 175699187 @ 51.765663,-0.231004\n" + "Dense node, ID 175698155 @ 51.767389,-0.230809\n" + "Dense node, ID 691202861 @ 51.765516,-0.231002\n" + "Dense node, ID 651594517 @ 51.763745,-0.228419\n" + "Dense node, ID 691203051 @ 51.765901,-0.231217\n" + "Dense node, ID 647224485 @ 51.765127,-0.226399\n" + "Dense node, ID 1709246749 @ 51.765632,-0.230025\n" + "Dense node, ID 677440300 @ 51.762625,-0.231624\n" + "Dense node, ID 647105172 @ 51.764294,-0.233070\n" + "Dense node, ID 175686498 @ 51.765424,-0.228052\n" + "Dense node, ID 692944963 @ 51.764665,-0.233953\n" + "Dense node, ID 663806656 @ 51.765763,-0.228715\n" + "Dense node, ID 647105154 @ 51.769626,-0.232179\n" + "Dense node, ID 676945317 @ 51.765015,-0.230385\n" + "Dense node, ID 647105169 @ 51.763033,-0.235323\n" + "Dense node, ID 692945021 @ 51.766617,-0.229479\n" + "Dense node, ID 1709246789 @ 51.766231,-0.230173\n" + "Dense node, ID 175686499 @ 51.765976,-0.228635\n" + "Dense node, ID 691202866 @ 51.767110,-0.232955\n" + "Dense node, ID 1111758072 @ 51.769507,-0.216315\n" + "Dense node, ID 647105123 @ 51.769155,-0.220818\n" + "Dense node, ID 672663468 @ 51.765622,-0.228672\n" + "Dense node, ID 676945197 @ 51.765281,-0.230541\n" + "Dense node, ID 692945020 @ 51.766471,-0.229673\n" + "Dense node, ID 175697881 @ 51.764664,-0.232747\n" + "Dense node, ID 175685109 @ 51.764946,-0.230095\n" + "Dense node, ID 1685167304 @ 51.760787,-0.240738\n" + "Dense node, ID 692944951 @ 51.764943,-0.234254\n" + "Dense node, ID 692945019 @ 51.766225,-0.229673\n" + "Dense node, ID 676945334 @ 51.765467,-0.228255\n" + "Dense node, ID 175684463 @ 51.765445,-0.226790\n" + "Dense node, ID 692944957 @ 51.764651,-0.234168\n" + "Dense node, ID 647105144 @ 51.771332,-0.229905\n" + "Dense node, ID 691203055 @ 51.765928,-0.230187\n" + "Dense node, ID 676945331 @ 51.765589,-0.229749\n" + "Dense node, ID 672663474 @ 51.765638,-0.229315\n" + "Dense node, ID 647105146 @ 51.770283,-0.231836\n" + "Dense node, ID 534873171 @ 51.763005,-0.237147\n" + "Dense node, ID 647105157 @ 51.769307,-0.232308\n" + "Dense node, ID 676945327 @ 51.765347,-0.229744\n" + "Dense node, ID 675150 @ 51.766907,-0.229904\n" + "Dense node, ID 663806666 @ 51.765165,-0.228973\n" + "Dense node, ID 691202871 @ 51.766950,-0.232826\n" + "Dense node, ID 672663477 @ 51.765646,-0.228948\n" + "Dense node, ID 647105158 @ 51.769015,-0.232297\n" + "Dense node, ID 673784380 @ 51.762202,-0.231241\n" + "Dense node, ID 647105152 @ 51.769739,-0.232330\n" + "Dense node, ID 692945022 @ 51.766344,-0.228825\n" + "Dense node, ID 676945315 @ 51.764929,-0.230336\n" + "Dense node, ID 676945346 @ 51.765450,-0.228506\n" + "Dense node, ID 647105119 @ 51.768119,-0.223854\n" + "Dense node, ID 175698430 @ 51.766924,-0.231110\n" + "Dense node, ID 1685167387 @ 51.765901,-0.235408\n" + "Dense node, ID 175685910 @ 51.766003,-0.227820\n" + "Dense node, ID 820969139 @ 51.767836,-0.231358\n" + "Dense node, ID 647105102 @ 51.763883,-0.232727\n" + "Dense node, ID 675151 @ 51.766141,-0.228136\n" + "Dense node, ID 175698324 @ 51.766008,-0.231131\n" + "Dense node, ID 1685167282 @ 51.762958,-0.237989\n" + "Dense node, ID 502552090 @ 51.765557,-0.233577\n" + "Dense node, ID 623624155 @ 51.765449,-0.234590\n" + "Dense node, ID 267826070 @ 51.764017,-0.232970\n" + "Dense node, ID 25365930 @ 51.766791,-0.234972\n" + "Dense node, ID 676945195 @ 51.765156,-0.230570\n" + "Dense node, ID 1709246675 @ 51.766423,-0.230168\n" + "Dense node, ID 647105137 @ 51.774248,-0.218055\n" + "Dense node, ID 651652534 @ 51.764261,-0.225160\n" + "Dense node, ID 676945293 @ 51.764816,-0.229133\n" + "Dense node, ID 1692947499 @ 51.773860,-0.225851\n" + "Dense node, ID 623624257 @ 51.765396,-0.234075\n" + "Dense node, ID 175697824 @ 51.764998,-0.232032\n" + "Dense node, ID 672663478 @ 51.765575,-0.229104\n" + "Dense node, ID 1685167290 @ 51.763311,-0.237639\n" + "Dense node, ID 390911769 @ 51.766861,-0.229798\n" + "Dense node, ID 676945323 @ 51.765506,-0.229937\n" + "Dense node, ID 647105136 @ 51.773720,-0.217976\n" + "Dense node, ID 1539682039 @ 51.768036,-0.233265\n" + "Dense node, ID 691202860 @ 51.766247,-0.230595\n" + "Dense node, ID 1145410964 @ 51.769148,-0.232860\n" + "Dense node, ID 647105130 @ 51.769188,-0.217728\n" + "Dense node, ID 691203049 @ 51.766645,-0.234564\n" + "Dense node, ID 1539682089 @ 51.768368,-0.232938\n" + "Dense node, ID 175698550 @ 51.766911,-0.230809\n" + "Dense node, ID 623540479 @ 51.765560,-0.224961\n" + "Dense node, ID 677439941 @ 51.763240,-0.230472\n" + "Dense node, ID 25365927 @ 51.766333,-0.232681\n" + "Dense node, ID 647105135 @ 51.770431,-0.216476\n" + "Dense node, ID 30983852 @ 51.764773,-0.233577\n" + "Dense node, ID 647105150 @ 51.769938,-0.232265\n" + "Dense node, ID 623624261 @ 51.764407,-0.235985\n" + "Dense node, ID 647105149 @ 51.770024,-0.232212\n" + "Dense node, ID 677439946 @ 51.763219,-0.229690\n" + "Dense node, ID 691203109 @ 51.765671,-0.232912\n" + "Dense node, ID 647105171 @ 51.764248,-0.233242\n" + "Dense node, ID 1709246746 @ 51.766196,-0.230058\n" + "Dense node, ID 175685106 @ 51.764728,-0.230781\n" + "Dense node, ID 663806661 @ 51.765857,-0.228507\n" + "Dense node, ID 677439947 @ 51.764197,-0.228387\n" + "Dense node, ID 647105117 @ 51.767435,-0.226150\n" + "Dense node, ID 647105168 @ 51.762754,-0.235838\n" + "Dense node, ID 623624267 @ 51.764016,-0.233964\n" + "Dense node, ID 1709246737 @ 51.766423,-0.230671\n" + "Dense node, ID 175684462 @ 51.764271,-0.229245\n" + "Dense node, ID 175698551 @ 51.766539,-0.230166\n" + "Dense node, ID 675148 @ 51.768657,-0.232378\n" + "Dense node, ID 676945332 @ 51.764887,-0.229157\n" + "Dense node, ID 675149 @ 51.767913,-0.231459\n" + "Dense node, ID 692945018 @ 51.766178,-0.229758\n" + "Dense node, ID 623540483 @ 51.765155,-0.224456\n" + "Dense node, ID 676945350 @ 51.765533,-0.228712\n" + "Dense node, ID 175698975 @ 51.765729,-0.233577\n" + "Dense node, ID 175685102 @ 51.764176,-0.232069\n" + "Dense node, ID 676945347 @ 51.765417,-0.228572\n" + "Dense node, ID 534873262 @ 51.763775,-0.236889\n" + "Dense node, ID 25365931 @ 51.765437,-0.236066\n" + "Dense node, ID 672663470 @ 51.765668,-0.229614\n" + "Dense node, ID 647105138 @ 51.773941,-0.221418\n" + "Dense node, ID 647105151 @ 51.769819,-0.232340\n" + "Dense node, ID 32953194 @ 51.762232,-0.231263\n" + "Dense node, ID 1685167315 @ 51.766349,-0.235121\n" + "Dense node, ID 1111758071 @ 51.769058,-0.216775\n" + "Dense node, ID 691203098 @ 51.764324,-0.234279\n" + "Dense node, ID 175698553 @ 51.766253,-0.230172\n" + "Dense node, ID 1685167287 @ 51.767572,-0.234395\n" + "Dense node, ID 672663471 @ 51.765452,-0.229359\n" + "Dense node, ID 676945325 @ 51.765209,-0.229575\n" + "Dense node, ID 623624156 @ 51.765622,-0.234693\n" + "Dense node, ID 647105140 @ 51.773198,-0.222341\n" + "Dense node, ID 25365928 @ 51.766333,-0.232198\n" + "Dense node, ID 676945329 @ 51.765389,-0.229634\n" + "Dense node, ID 663806668 @ 51.765337,-0.228533\n" + "Dense node, ID 692944966 @ 51.764977,-0.233985\n" + "Dense node, ID 691203099 @ 51.764162,-0.234157\n" + "Dense node, ID 175685100 @ 51.764091,-0.232103\n" + "Dense node, ID 25365923 @ 51.767521,-0.233449\n" + "Dense node, ID 647105161 @ 51.767973,-0.232169\n" + "Dense node, ID 672663467 @ 51.765478,-0.228989\n" + "Dense node, ID 691202854 @ 51.766818,-0.232419\n" + "Way ID 158788812\n" + " Nodes: 1709246789 1709246746 1709246741 1709246791 \n" + " Key=value pairs: highway=footway \n" + "Way ID 53588781\n" + " Nodes: 676945323 676945327 676945325 676945326 676945331 676945323 \n" + " Key=value pairs: landuse=garages source=survey \n" + "Way ID 158788810\n" + " Nodes: 1709246675 1709246737 1709246734 1709246676 \n" + " Key=value pairs: highway=footway \n" + "Way ID 156255508\n" + " Nodes: 45169425 1685167371 1685167341 1685167287 1685167296 1685167315 1685167387 1685167328 1685167373 1685167290 1685167282 1685167313 1685167381 1685167391 1685167394 1685167304 1685167376 1606957353 \n" + " Key=value pairs: carriageway_ref=A highway=motorway lanes=3 layer=-1 lit=yes maxspeed=national name=Hatfield Tunnel oneway=yes ref=A1(M) source:maxspeed=local_knowledge tunnel=yes \n" + "Way ID 54932035\n" + " Nodes: 691202854 691202855 691202857 \n" + " Key=value pairs: highway=residential name=Jasmine Gardens source=OS_OpenData_StreetView \n" + "Way ID 16946553\n" + " Nodes: 175697671 175697862 175697821 175697824 \n" + " Key=value pairs: highway=residential name=Oak Tree Close \n" + "Way ID 52083876\n" + " Nodes: 663806653 663806656 663806658 \n" + " Key=value pairs: highway=service \n" + "Way ID 55081202\n" + " Nodes: 692944951 692944957 692944963 692944966 692944951 \n" + " Key=value pairs: leisure=common source=yahoo \n" + "Way ID 16946600\n" + " Nodes: 175698430 175698550 691203053 691203054 175698551 1709246675 175698553 1709246789 691203055 \n" + " Key=value pairs: highway=residential name=Harmony Close source=OS_OpenData_StreetView \n" + "Way ID 16946559\n" + " Nodes: 175697862 175697881 \n" + " Key=value pairs: created_by=Potlatch 0.5d highway=residential name=Oak Tree Close \n" + "Way ID 16945846\n" + " Nodes: 175684459 175685100 175685102 175685104 676945189 175685106 676945315 175685109 175685111 175684462 \n" + " Key=value pairs: highway=residential name=Stockbreach Close \n" + "Way ID 54932037\n" + " Nodes: 175698553 691202860 \n" + " Key=value pairs: highway=residential name=Harmony Close source=OS_OpenData_StreetView \n" + "Way ID 16946584\n" + " Nodes: 175698155 175698323 175698430 1709246676 175698324 691203051 \n" + " Key=value pairs: highway=residential name=The Minims source=OS_OpenData_StreetView \n" + "Way ID 8361329\n" + " Nodes: 25365926 25365927 25365928 \n" + " Key=value pairs: highway=residential name=The Paddock source=OS_OpenData_StreetView \n" + "Way ID 16945926\n" + " Nodes: 175686498 175686201 663806661 175686499 \n" + " Key=value pairs: highway=residential name=Wellfield Close \n" + "Way ID 52083878\n" + " Nodes: 663806664 663806666 663806668 663806670 663806672 663806673 663806664 \n" + " Key=value pairs: leisure=common source=yahoo \n" + "Way ID 3084923\n" + " Nodes: 675146 1145410964 1539682123 32950368 241806356 675148 675149 820969139 175698155 675150 390911769 647224486 675151 175685910 14713407 175684463 647057820 647224485 1739780291 \n" + " Key=value pairs: abutters=residential highway=secondary name=Wellfield Road ref=B197 \n" + "Way ID 8361331\n" + " Nodes: 25365925 691203049 25365930 25365931 \n" + " Key=value pairs: highway=residential name=Walsingham Close source=OS_OpenData_StreetView \n" + "Way ID 54932038\n" + " Nodes: 175699187 691202861 \n" + " Key=value pairs: highway=residential name=Middlefield source=OS_OpenData_StreetView \n" + "Way ID 16946620\n" + " Nodes: 175698975 691203109 175699187 691203110 691203111 \n" + " Key=value pairs: highway=residential name=Middlefield source=OS_OpenData_StreetView \n" + "Way ID 157868709\n" + " Nodes: 1701110757 1701110775 \n" + " Key=value pairs: bridge=yes cycleway=track highway=cycleway layer=1 name=Alban Way ncn_ref=61 railway=abandoned \n" + "Way ID 52083877\n" + " Nodes: 663806656 663806661 \n" + " Key=value pairs: highway=service \n" + "Way ID 53588764\n" + " Nodes: 676945267 677438877 677439947 676945292 676945293 676945332 647224613 175686498 \n" + " Key=value pairs: highway=footway \n" + "Way ID 49161822\n" + " Nodes: 30983851 623624257 623624154 623624259 623624261 \n" + " Key=value pairs: highway=residential name=Worcester Road \n" + "Way ID 49161823\n" + " Nodes: 623624259 691203098 691203099 623624267 \n" + " Key=value pairs: highway=residential name=Ely Close \n" + "Way ID 53588782\n" + " Nodes: 676945327 676945329 \n" + " Key=value pairs: bicycle=no highway=footway source=survey \n" + "Way ID 54932044\n" + " Nodes: 691202869 691202855 \n" + " Key=value pairs: highway=residential name=Jasmine Gardens source=OS_OpenData_StreetView \n" + "Way ID 49161817\n" + " Nodes: 623624154 623624155 623624156 \n" + " Key=value pairs: highway=residential name=Malvern Close \n" + "Way ID 53588780\n" + " Nodes: 676945350 676945352 676945334 676945335 676945346 676945347 676945350 \n" + " Key=value pairs: building=yes name=Friendship House source=survey \n" + "Way ID 53588749\n" + " Nodes: 676945199 676945316 676945317 676945195 676945319 676945197 676945199 \n" + " Key=value pairs: landuse=garages source=survey \n" + "Way ID 4673618\n" + " Nodes: 675148 25365921 1539682089 25365922 1539682039 691202838 25365923 25365924 25365925 25365926 175698975 30983851 175697671 30983852 691203106 30983853 240134267 267826070 365548881 32953193 175683944 927070648 647225601 677440300 32953194 673784380 32953195 \n" + " Key=value pairs: highway=tertiary name=Lemsford Road \n" + "Way ID 53638158\n" + " Nodes: 677439941 677439943 677439944 677439946 676945241 175683342 653970876 653970877 1697422651 651594517 676945267 677438877 677439947 647224485 1739780291 1739780285 1739780280 672628083 651652534 651652536 1739780294 623540483 623540479 623540472 623540467 647224465 647057820 175684463 14713407 175685910 675151 692887101 647224486 647105115 647105117 647105119 647105121 647105123 647105125 647105127 647105128 647105129 647105130 647105131 647105132 1111758071 647105133 1111758069 647105134 1111758072 647105135 1111758067 647105136 647105137 647105138 647105139 647105140 647105141 647105047 1692947499 647105142 647105143 647105144 647105145 647105146 647105147 647105148 647105149 647105150 647105151 647105152 647105153 647105154 647105155 647105156 647105157 647105158 647105159 647105160 647105161 647105162 647105163 647105164 647105165 647105166 534874147 534873285 534873274 534873262 534873251 534873208 534873185 534873171 647105167 647105168 647105169 647105170 647105171 647105172 647105102 647225601 677439941 \n" + " Key=value pairs: landuse=residential \n" + "Way ID 53588748\n" + " Nodes: 676945322 676945325 676945327 676945320 676945192 676945315 \n" + " Key=value pairs: bicycle=no highway=footway source=survey \n" + "Way ID 50772651\n" + " Nodes: 175685111 676945322 175685506 647224613 \n" + " Key=value pairs: highway=residential name=Town Fields \n" + "Way ID 158788824\n" + " Nodes: 175685507 1709246749 \n" + " Key=value pairs: highway=footway \n" + "Way ID 54932042\n" + " Nodes: 691202866 691202871 691202873 \n" + " Key=value pairs: highway=residential name=Jasmine Gardens source=OS_OpenData_StreetView \n" + "Way ID 53152061\n" + " Nodes: 672663467 672663468 672663469 672663470 672663471 672663473 672663474 672663476 672663477 672663478 672663467 \n" + " Key=value pairs: amenity=retirement _home building=yes name=Greenacres source:area=yahoo source:name=survey \n" + "Way ID 53638215\n" + " Nodes: 175685506 676945329 175685507 \n" + " Key=value pairs: highway=service source=survey \n" + "Way ID 157868710\n" + " Nodes: 1701110775 287659881 692887118 1709246791 1709246749 240134269 240134268 \n" + " Key=value pairs: cycleway=track highway=cycleway name=Alban Way ncn_ref=61 railway=abandoned \n" + "Way ID 54932036\n" + " Nodes: 25365927 691202858 \n" + " Key=value pairs: highway=residential name=The Paddock source=OS_OpenData_StreetView \n" + "Way ID 54932039\n" + " Nodes: 175697821 691202863 \n" + " Key=value pairs: highway=residential name=Oak Tree Close source=OS_OpenData_StreetView \n" + "Way ID 55081204\n" + " Nodes: 692945016 692945017 692945018 692945019 692945020 692945021 692945022 692945016 \n" + " Key=value pairs: leisure=common \n" + "Way ID 55071941\n" + " Nodes: 692887118 692887101 \n" + " Key=value pairs: foot=yes highway=footway \n" + "Way ID 157868707\n" + " Nodes: 240134268 240134269 1709246749 1709246791 692887118 287659881 \n" + " Key=value pairs: cycleway=track highway=cycleway name=Alban Way ncn_ref=61 \n" + "Got some relations to parse.\n" + "Complete!\n").replace("\n", System.lineSeparator()); try (InputStream input = ReadFileTest.class.getResourceAsStream("/sample.pbf"); StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter)) { BlockReaderAdapter brad = new TestBinaryParser(printWriter); new BlockInputStream(input, brad).process(); Assert.assertEquals(expected, stringWriter.toString()); } } private static class TestBinaryParser extends BinaryParser { private final PrintWriter writer; private TestBinaryParser(PrintWriter writer) { this.writer = writer; } @Override protected void parseRelations(List rels) { if (!rels.isEmpty()) writer.println("Got some relations to parse."); Relation r = null; } @Override protected void parseDense(DenseNodes nodes) { long lastId = 0; long lastLat = 0; long lastLon = 0; for (int i = 0; i < nodes.getIdCount(); i++) { lastId += nodes.getId(i); lastLat += nodes.getLat(i); lastLon += nodes.getLon(i); writer.printf("Dense node, ID %d @ %.6f,%.6f%n", lastId, parseLat(lastLat), parseLon(lastLon)); } } @Override protected void parseNodes(List nodes) { for (Node n : nodes) { writer.printf("Regular node, ID %d @ %.6f,%.6f%n", n.getId(), parseLat(n.getLat()), parseLon(n.getLon())); } } @Override protected void parseWays(List ways) { for (Way w : ways) { writer.println("Way ID " + w.getId()); writer.print(" Nodes: "); long lastRef = 0; for (Long ref : w.getRefsList()) { lastRef += ref; writer.print(lastRef); writer.print(" "); } writer.println(); writer.print(" Key=value pairs: "); for (int i = 0; i < w.getKeysCount(); i++) { writer.print(getStringById(w.getKeys(i))); writer.print("="); writer.print(getStringById(w.getVals(i))); writer.print(" "); } writer.println(); } } @Override protected void parse(HeaderBlock header) { writer.println("Got header block."); } public void complete() { writer.println("Complete!"); } } } OSM-binary-1.5.0/test.java/crosby/binary/WriteFileTest.java000066400000000000000000000265151377533755200235500ustar00rootroot00000000000000/** * Copyright (c) 2010 Scott A. Crosby. *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package crosby.binary; import com.google.protobuf.ByteString; import crosby.binary.Osmformat.*; import crosby.binary.Osmformat.StringTable; import crosby.binary.Osmformat.Relation.MemberType; import crosby.binary.file.BlockOutputStream; import crosby.binary.file.FileBlock; import org.junit.Assert; import org.junit.Test; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Paths; public class WriteFileTest { @Test public void testSimpleFileBlock1() throws Exception { test("deflate", "/SimpleFileBlock1-deflate.osm.pbf"); test("none", "/SimpleFileBlock1-none.osm.pbf"); } @Test public void testGranFileBlock1() throws Exception { test("deflate", "/GranFileBlock1-deflate.osm.pbf"); test("none", "/GranFileBlock1-none.osm.pbf"); } private void test(String compress, String resource) throws IOException, URISyntaxException { try (ByteArrayOutputStream bytes = new ByteArrayOutputStream()) { BuildTestFile builder = new BuildTestFile(new BlockOutputStream(bytes), compress); if (resource.startsWith("/SimpleFileBlock1")) { builder.makeSimpleFileBlock1(); } else if (resource.startsWith("/GranFileBlock1")) { builder.makeGranFileBlock1(); } else { throw new IllegalArgumentException(); } byte[] expected = Files.readAllBytes(Paths.get(WriteFileTest.class.getResource(resource).toURI())); Assert.assertArrayEquals(expected, bytes.toByteArray()); } } } class BuildTestFile { private final BlockOutputStream output; public static final long BILLION = 1000000000L; StringTable makeStringTable(String prefix) { return StringTable.newBuilder() .addS(ByteString.copyFromUtf8("")) // Never used. .addS(ByteString.copyFromUtf8(prefix + "Offset1")) .addS(ByteString.copyFromUtf8(prefix + "Offset2")) .addS(ByteString.copyFromUtf8(prefix + "Offset3")) .addS(ByteString.copyFromUtf8(prefix + "Offset4")) .addS(ByteString.copyFromUtf8(prefix + "Offset5")) .addS(ByteString.copyFromUtf8(prefix + "Offset6")) .addS(ByteString.copyFromUtf8(prefix + "Offset7")) .addS(ByteString.copyFromUtf8(prefix + "Offset8")) .build(); } void makeSimpleFileBlock1() throws IOException { PrimitiveBlock.Builder b1 = PrimitiveBlock.newBuilder(); b1.setStringtable(makeStringTable("B1")); b1.addPrimitivegroup( PrimitiveGroup.newBuilder() .addNodes(Node.newBuilder() .setId(101).setLat(13 * 10 * 1000 * 1000).setLon(-14 * 10 * 1000 * 1000) .addKeys(1).addVals(2)) .addNodes(Node.newBuilder() .setId(101).setLat(12345678).setLon(-23456789)) // Should be 1.2345678 degrees lat and -2.3456789 lon. ); b1.addPrimitivegroup( PrimitiveGroup.newBuilder() .addWays(Way.newBuilder() .setId(201) .addRefs(101).addRefs(1).addRefs(-1).addRefs(10).addRefs(-20) // Delta coded. Should be 101, 102, 101, 111, 91. .addKeys(2).addVals(1).addKeys(3).addVals(4)) .addWays(Way.newBuilder() .setId(-301) .addRefs(211).addRefs(1).addRefs(-1).addRefs(10).addRefs(-300) // Delta coded. Should be 211, 212, 211, 221, -79 .addKeys(4).addVals(3).addKeys(5).addVals(6)) .addWays(Way.newBuilder() .setId(401).addRefs(211).addRefs(1)) .addWays(Way.newBuilder() .setId(501)) ); b1.addPrimitivegroup( PrimitiveGroup.newBuilder() .addRelations(Relation.newBuilder() .setId(601) .addTypes(MemberType.NODE).addMemids(50).addRolesSid(2) .addTypes(MemberType.NODE).addMemids(3).addRolesSid(3) .addTypes(MemberType.WAY).addMemids(3).addRolesSid(4) .addTypes(MemberType.RELATION).addMemids(3).addRolesSid(5)) .addRelations(Relation.newBuilder() .setId(701) .addTypes(MemberType.RELATION).addMemids(60).addRolesSid(6) .addTypes(MemberType.RELATION).addMemids(5).addRolesSid(7) .addKeys(1).addVals(2))); b1.addPrimitivegroup( PrimitiveGroup.newBuilder() .setDense(DenseNodes.newBuilder() .addId(1001).addId(110).addId(-2000).addId(8889) .addLat(12 * 10000000).addLat(1500000).addLat(-12 * 10000000).addLat(-12 * 10000000) .addLon(-12 * 10000000).addLon(2500000).addLon(13 * 10000000).addLon(2 * 10000000) .addKeysVals(1).addKeysVals(2).addKeysVals(0) .addKeysVals(0) .addKeysVals(2).addKeysVals(3).addKeysVals(4).addKeysVals(5).addKeysVals(0) .addKeysVals(3).addKeysVals(3).addKeysVals(0) )); output.write(FileBlock.newInstance("OSMData", b1.build().toByteString(), null)); PrimitiveBlock.Builder b2 = PrimitiveBlock.newBuilder(); b2.setLatOffset(10 * BILLION + 109208300) .setLonOffset(20 * BILLION + 901802700) .setGranularity(1200); b2.setStringtable(makeStringTable("B2")); // Test out granularity stuff. b2.addPrimitivegroup( PrimitiveGroup.newBuilder() .addNodes(Node.newBuilder().setId(100000).setLat(0).setLon(0)) .addNodes(Node.newBuilder().setId(100001).setLat(1000).setLon(2000)) .addNodes(Node.newBuilder().setId(100002).setLat(1001).setLon(2001)) .addNodes(Node.newBuilder().setId(100003).setLat(1002).setLon(2002)) .addNodes(Node.newBuilder().setId(100004).setLat(1003).setLon(2003)) .addNodes(Node.newBuilder().setId(100005).setLat(1004).setLon(2004))); output.write(FileBlock.newInstance("OSMData", b2.build().toByteString(), null)); } BuildTestFile(BlockOutputStream output, String compress) throws IOException { this.output = output; this.output.setCompress(compress); HeaderBlock.Builder b = HeaderBlock.newBuilder(); b.addRequiredFeatures("OsmSchema-V0.6").addRequiredFeatures("DenseNodes").setSource("QuickBrownFox"); this.output.write(FileBlock.newInstance("OSMHeader", b.build().toByteString(), null)); } void makeGranFileBlock1() throws IOException { PrimitiveBlock.Builder b1 = PrimitiveBlock.newBuilder(); b1.setLatOffset(10 * BILLION + 109208300) .setLonOffset(20 * BILLION + 901802700) .setGranularity(1200) .setDateGranularity(2500); b1.setStringtable(makeStringTable("C1")); b1.addPrimitivegroup( PrimitiveGroup.newBuilder() .addNodes(Node.newBuilder() .setId(100001) .setLat(1000).setLon(2000) .setInfo(Info.newBuilder() .setTimestamp(1001) .setChangeset(-12) .setUid(21) .setUserSid(6) .build()) .build()) .addNodes(Node.newBuilder() .setId(100002) .setLat(1001).setLon(2001) .setInfo(Info.newBuilder() .setVersion(102) .setTimestamp(1002) .setChangeset(12) .setUid(-21) .setUserSid(5) .build()) .build()) .addNodes(Node.newBuilder() .setId(100003) .setLat(1003).setLon(2003) .setInfo(Info.newBuilder() .setVersion(103) .setUserSid(4) .build()) .build()) ); // The same, but with different granularities. PrimitiveBlock.Builder b2 = PrimitiveBlock.newBuilder(); b2.setLatOffset(12 * BILLION + 303) .setLonOffset(22 * BILLION + 404) .setGranularity(1401) .setDateGranularity(3003); b2.setStringtable(makeStringTable("C2")); b2.addPrimitivegroup( PrimitiveGroup.newBuilder() .addNodes(Node.newBuilder() .setId(100001) .addKeys(1).addVals(2) .addKeys(1).addVals(3) // Support multiple vals for a key. .addKeys(3).addVals(4) .setLat(1000).setLon(2000) .build()) .addNodes(Node.newBuilder() .setId(100002) .setLat(1001).setLon(2001) .build()) .addNodes(Node.newBuilder() .setId(100003) .setLat(1003).setLon(2003) .addKeys(5).addVals(6) .build()) ); output.write(FileBlock.newInstance("OSMData", b1.build().toByteString(), null)); output.write(FileBlock.newInstance("OSMData", b2.build().toByteString(), null)); } } OSM-binary-1.5.0/tools/000077500000000000000000000000001377533755200146165ustar00rootroot00000000000000OSM-binary-1.5.0/tools/.gitignore000066400000000000000000000000171377533755200166040ustar00rootroot00000000000000osmpbf-outline OSM-binary-1.5.0/tools/CMakeLists.txt000066400000000000000000000010721377533755200173560ustar00rootroot00000000000000find_package(ZLIB REQUIRED) find_package(Threads) include_directories("${CMAKE_SOURCE_DIR}/include") include_directories(${CMAKE_BINARY_DIR}) add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64) add_executable(osmpbf-outline osmpbf-outline.cpp) target_include_directories(osmpbf-outline SYSTEM PRIVATE ${ZLIB_INCLUDE_DIR}) target_link_libraries(osmpbf-outline PRIVATE osmpbf ZLIB::ZLIB protobuf::libprotobuf) install(TARGETS osmpbf-outline RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES osmpbf-outline.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) OSM-binary-1.5.0/tools/Makefile000066400000000000000000000012521377533755200162560ustar00rootroot00000000000000 # these default settings can be overridden by setting environment variables PREFIX ?= /usr/local CXX ?= g++ CXXFLAGS ?= -g CXXFLAGS += -I../include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Wall -Wextra -pedantic -Wredundant-decls -Wdisabled-optimization -Wctor-dtor-privacy -Wnon-virtual-dtor -Woverloaded-virtual -Wsign-promo -Wno-long-long LDFLAGS += -L../src -pthread -lz -lprotobuf -losmpbf .PHONY: clean install all: osmpbf-outline osmpbf-outline: osmpbf-outline.cpp $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $< $(LDFLAGS) install: install -m 755 -d $(DESTDIR)$(PREFIX)/bin install -m 755 -s osmpbf-outline $(DESTDIR)$(PREFIX)/bin clean: rm -f osmpbf-outline OSM-binary-1.5.0/tools/osmpbf-outline.1000066400000000000000000000023331377533755200176440ustar00rootroot00000000000000.TH osmpbf-outline 1 LOCAL .SH NAME osmpbf-outline - outline the content of an .osm.pbf or .osh.pbf file .SH SYNOPSIS .B osmpbf-outline [ .B --color ] .I filename .SH DESCRIPTION .I osmpbf-outline generates a colored outline of an .osm.pbf or .osh.pbf file, revealing its inner structure. It does not decode all information nor does it check for of possible mistakes, but it will warn on some bad mistakes one can make when generating .osm.pbf files. This tool can be used by authors of .osm.pbf readers and writers and is useful to understand the inner blob/block structure of .osm.pbf files. Its source code is heavily documented and can be used as a good starting point understanding on how to read and write .osm.pbf files with C++. .SH OPTIONS .TP 5 .B -c, --color usually colorization is disabled when writing to a file descriptor that is not a tty (eg. when the output is piped to a file or to a pager like more or less). Some pagers can handle ANSI color code ( .I more can, less can when invoked as .I less -R ). To enforce colorization when working with such pagers, specify the .B --color flag. .SH EXAMPLES osmpbf-outline germany.osm.pbf .SH AUTHOR Peter Koerner Jochen Topf OSM-binary-1.5.0/tools/osmpbf-outline.cpp000066400000000000000000000310311377533755200202630ustar00rootroot00000000000000// used for va_list in debug-print methods #include // file io lib #include // getopt is used to check for the --color-flag #include // zlib compression is used inside the pbf blobs #include // netinet or winsock2 provides the network-byte-order conversion function #ifdef D_HAVE_WINSOCK #include #else #include #endif // this is the header to pbf format #include // should the output use color? bool usecolor = false; // buffer for reading a compressed blob from file char buffer[OSMPBF::max_uncompressed_blob_size]; // buffer for decompressing the blob char unpack_buffer[OSMPBF::max_uncompressed_blob_size]; // pbf struct of a BlobHeader OSMPBF::BlobHeader blobheader; // pbf struct of a Blob OSMPBF::Blob blob; // pbf struct of an OSM HeaderBlock OSMPBF::HeaderBlock headerblock; // pbf struct of an OSM PrimitiveBlock OSMPBF::PrimitiveBlock primblock; // prints a formatted message to stdout, optionally color coded void msg(const char* format, int color, va_list args) { if (usecolor) { fprintf(stdout, "\x1b[0;%dm", color); } vfprintf(stdout, format, args); if (usecolor) { fprintf(stdout, "\x1b[0m\n"); } else { fprintf(stdout, "\n"); } } // prints a formatted message to stdout, color coded to red void err(const char* format, ...) { va_list args; va_start(args, format); msg(format, 31, args); va_end(args); exit(1); } // prints a formatted message to stdout, color coded to yellow void warn(const char* format, ...) { va_list args; va_start(args, format); msg(format, 33, args); va_end(args); } // prints a formatted message to stdout, color coded to green void info(const char* format, ...) { va_list args; va_start(args, format); msg(format, 32, args); va_end(args); } // prints a formatted message to stdout, color coded to white void debug(const char* format, ...) { va_list args; va_start(args, format); msg(format, 37, args); va_end(args); } // application main method int main(int argc, char *argv[]) { // check if the output is a tty so we can use colors #ifdef WIN32 usecolor = 0; #else usecolor = isatty(1); #endif static struct option long_options[] = { {"color", no_argument, 0, 'c'}, {0, 0, 0, 0} }; while (1) { int c = getopt_long(argc, argv, "c", long_options, 0); if (c == -1) { break; } switch (c) { case 'c': usecolor = true; break; default: exit(1); } } // check for proper command line args if (optind != argc-1) { err("usage: %s [--color] file.osm.pbf", argv[0]); } // open specified file FILE *fp = fopen(argv[optind], "rb"); if (!fp) { err("can't open file '%s'", argv[optind]); } // read while the file has not reached its end while (!feof(fp)) { // storage of size, used multiple times int32_t sz; // read the first 4 bytes of the file, this is the size of the blob-header if (fread(&sz, sizeof(sz), 1, fp) != 1) { break; // end of file reached } // convert the size from network byte-order to host byte-order sz = ntohl(sz); // ensure the blob-header is smaller then MAX_BLOB_HEADER_SIZE if (sz > OSMPBF::max_blob_header_size) { err("blob-header-size is bigger then allowed (%u > %u)", sz, OSMPBF::max_blob_header_size); } // read the blob-header from the file if (fread(buffer, sz, 1, fp) != 1) { err("unable to read blob-header from file"); } // parse the blob-header from the read-buffer if (!blobheader.ParseFromArray(buffer, sz)) { err("unable to parse blob header"); } // tell about the blob-header info("\nBlobHeader (%d bytes)", sz); debug(" type = %s", blobheader.type().c_str()); // size of the following blob sz = blobheader.datasize(); debug(" datasize = %u", sz); // optional indexdata if (blobheader.has_indexdata()) { debug(" indexdata = %u bytes", blobheader.indexdata().size()); } // ensure the blob is smaller then MAX_BLOB_SIZE if (sz > OSMPBF::max_uncompressed_blob_size) { err("blob-size is bigger then allowed (%u > %u)", sz, OSMPBF::max_uncompressed_blob_size); } // read the blob from the file if (fread(buffer, sz, 1, fp) != 1) { err("unable to read blob from file"); } // parse the blob from the read-buffer if (!blob.ParseFromArray(buffer, sz)) { err("unable to parse blob"); } // tell about the blob-header info("Blob (%d bytes)", sz); // set when we find at least one data stream bool found_data = false; // if the blob has uncompressed data if (blob.has_raw()) { // we have at least one datastream found_data = true; // size of the blob-data sz = blob.raw().size(); // check that raw_size is set correctly if (sz != blob.raw_size()) { warn(" reports wrong raw_size: %u bytes", blob.raw_size()); } // tell about the blob-data debug(" contains uncompressed data: %u bytes", sz); // copy the uncompressed data over to the unpack_buffer memcpy(unpack_buffer, buffer, sz); } // if the blob has zlib-compressed data if (blob.has_zlib_data()) { // issue a warning if there is more than one data steam, a blob may only contain one data stream if (found_data) { warn(" contains several data streams"); } // we have at least one datastream found_data = true; // the size of the compressesd data sz = blob.zlib_data().size(); // tell about the compressed data debug(" contains zlib-compressed data: %u bytes", sz); debug(" uncompressed size: %u bytes", blob.raw_size()); // zlib information z_stream z; // next byte to decompress z.next_in = (unsigned char*) blob.zlib_data().c_str(); // number of bytes to decompress z.avail_in = sz; // place of next decompressed byte z.next_out = (unsigned char*) unpack_buffer; // space for decompressed data z.avail_out = blob.raw_size(); // misc z.zalloc = Z_NULL; z.zfree = Z_NULL; z.opaque = Z_NULL; if (inflateInit(&z) != Z_OK) { err(" failed to init zlib stream"); } if (inflate(&z, Z_FINISH) != Z_STREAM_END) { err(" failed to inflate zlib stream"); } if (inflateEnd(&z) != Z_OK) { err(" failed to deinit zlib stream"); } // unpacked size sz = z.total_out; } // if the blob has lzma-compressed data if (blob.has_lzma_data()) { // issue a warning if there is more than one data steam, a blob may only contain one data stream if (found_data) { warn(" contains several data streams"); } // we have at least one datastream found_data = true; // tell about the compressed data debug(" contains lzma-compressed data: %u bytes", blob.lzma_data().size()); debug(" uncompressed size: %u bytes", blob.raw_size()); // issue a warning, lzma compression is not yet supported err(" lzma-decompression is not supported"); } // check we have at least one data-stream if (!found_data) { err(" does not contain any known data stream"); } // switch between different blob-types if (blobheader.type() == "OSMHeader") { // tell about the OSMHeader blob info(" OSMHeader"); // parse the HeaderBlock from the blob if (!headerblock.ParseFromArray(unpack_buffer, sz)) { err("unable to parse header block"); } // tell about the bbox if (headerblock.has_bbox()) { OSMPBF::HeaderBBox bbox = headerblock.bbox(); debug(" bbox: %.7f,%.7f,%.7f,%.7f", (double)bbox.left() / OSMPBF::lonlat_resolution, (double)bbox.bottom() / OSMPBF::lonlat_resolution, (double)bbox.right() / OSMPBF::lonlat_resolution, (double)bbox.top() / OSMPBF::lonlat_resolution); } // tell about the required features for (int i = 0, l = headerblock.required_features_size(); i < l; i++) { debug(" required_feature: %s", headerblock.required_features(i).c_str()); } // tell about the optional features for (int i = 0, l = headerblock.optional_features_size(); i < l; i++) { debug(" optional_feature: %s", headerblock.optional_features(i).c_str()); } // tell about the writing program if (headerblock.has_writingprogram()) { debug(" writingprogram: %s", headerblock.writingprogram().c_str()); } // tell about the source if (headerblock.has_source()) { debug(" source: %s", headerblock.source().c_str()); } } else if (blobheader.type() == "OSMData") { // tell about the OSMData blob info(" OSMData"); // parse the PrimitiveBlock from the blob if (!primblock.ParseFromArray(unpack_buffer, sz)) { err("unable to parse primitive block"); } // tell about the block's meta info debug(" granularity: %u", primblock.granularity()); debug(" lat_offset: %u", primblock.lat_offset()); debug(" lon_offset: %u", primblock.lon_offset()); debug(" date_granularity: %u", primblock.date_granularity()); // tell about the stringtable debug(" stringtable: %u items", primblock.stringtable().s_size()); // number of PrimitiveGroups debug(" primitivegroups: %u groups", primblock.primitivegroup_size()); // iterate over all PrimitiveGroups for (int i = 0, l = primblock.primitivegroup_size(); i < l; i++) { // one PrimitiveGroup from the the Block OSMPBF::PrimitiveGroup pg = primblock.primitivegroup(i); bool found_items=false; // tell about nodes if (pg.nodes_size() > 0) { found_items = true; debug(" nodes: %d", pg.nodes_size()); if (pg.nodes(0).has_info()) { debug(" with meta-info"); } } // tell about dense nodes if (pg.has_dense()) { found_items = true; debug(" dense nodes: %d", pg.dense().id_size()); if (pg.dense().has_denseinfo()) { debug(" with meta-info"); } } // tell about ways if (pg.ways_size() > 0) { found_items = true; debug(" ways: %d", pg.ways_size()); if (pg.ways(0).has_info()) { debug(" with meta-info"); } } // tell about relations if (pg.relations_size() > 0) { found_items = true; debug(" relations: %d", pg.relations_size()); if (pg.relations(0).has_info()) { debug(" with meta-info"); } } if (!found_items) { warn(" contains no items"); } } } else { // unknown blob type warn(" unknown blob type: %s", blobheader.type().c_str()); } } // close the file pointer fclose(fp); // clean up the protobuf lib google::protobuf::ShutdownProtobufLibrary(); }