Skip to content

Commit 4e0056b

Browse files
committed
Merge remote-tracking branch 'origin/master' into add_option_to_avoid_blank_nodes
2 parents 0c7f051 + 62d71c5 commit 4e0056b

File tree

14 files changed

+184
-204
lines changed

14 files changed

+184
-204
lines changed

.github/workflows/native-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: update apt
1313
run: sudo apt update
1414
- name: install dependencies
15-
run: sudo apt install -y gcc g++ libboost-dev libboost-serialization-dev libexpat1-dev cmake libbz2-dev zlib1g-dev libomp-dev
15+
run: sudo apt install -y gcc g++ libexpat1-dev cmake libbz2-dev zlib1g-dev libomp-dev
1616
- name: cmake
1717
run: mkdir build && cd build && cmake ..
1818
- name: make
@@ -29,7 +29,7 @@ jobs:
2929
- name: update apt
3030
run: sudo apt update
3131
- name: install dependencies
32-
run: sudo apt install -y clang libboost-dev libboost-serialization-dev libexpat1-dev cmake libbz2-dev zlib1g-dev libomp-dev
32+
run: sudo apt install -y clang libexpat1-dev cmake libbz2-dev zlib1g-dev libomp-dev
3333
- name: cmake
3434
run: mkdir build && cd build && cmake ..
3535
shell: bash

CMakeLists.txt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,6 @@ find_package(EXPAT REQUIRED)
6767
find_package(BZip2 REQUIRED)
6868
find_package(OpenMP)
6969

70-
# zlib-ng
71-
set(ZLIB_COMPAT ON)
72-
set(WITH_GTEST OFF)
73-
set(ZLIB_ENABLE_TESTS OFF)
74-
add_subdirectory(vendor/zlib-ng/zlib-ng)
75-
76-
set(ZLIB_USE_STATIC_LIBS ON)
77-
set(ZLIB_INCLUDE_DIR "${CMAKE_BINARY_DIR}/vendor/zlib-ng/zlib-ng")
78-
set(ZLIB_LIBRARY "${CMAKE_BINARY_DIR}/vendor/zlib-ng/zlib-ng/libz.a")
79-
80-
# Disable installation of google stuff
81-
set(INSTALL_GMOCK OFF)
82-
set(INSTALL_GTEST OFF)
83-
8470
find_package(Git QUIET)
8571
if (GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
8672
# Update submodules as needed
@@ -100,6 +86,21 @@ if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/vendor/google/googletest/CMakeLists.
10086
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
10187
endif ()
10288

89+
# zlib-ng
90+
set(ZLIB_COMPAT ON)
91+
set(WITH_GTEST OFF)
92+
set(ZLIB_ENABLE_TESTS OFF)
93+
add_subdirectory(vendor/zlib-ng/zlib-ng)
94+
95+
set(ZLIB_USE_STATIC_LIBS ON)
96+
set(ZLIB_INCLUDE_DIR "${CMAKE_BINARY_DIR}/vendor/zlib-ng/zlib-ng")
97+
set(ZLIB_LIBRARY "${CMAKE_BINARY_DIR}/vendor/zlib-ng/zlib-ng/libz.a")
98+
99+
# Disable installation of google stuff
100+
set(INSTALL_GMOCK OFF)
101+
set(INSTALL_GTEST OFF)
102+
103+
103104
find_package(POPL REQUIRED)
104105
include_directories(SYSTEM ${POPL_INCLUDE_DIR})
105106
find_package(Protozero REQUIRED)

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM ubuntu:24.04
22

3-
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y git clang clang-tidy g++ libboost-dev libboost-serialization-dev libexpat1-dev cmake libbz2-dev zlib1g-dev libomp-dev
3+
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y git g++ libexpat1-dev cmake libbz2-dev libomp-dev zlib1g-dev
44
COPY . /app/
5-
RUN cd /app/ && make
5+
RUN cd /app/ && mkdir -p build && cd build && cmake .. && make -j
66
ENTRYPOINT ["/app/build/apps/osm2rdf"]

Makefile

Lines changed: 0 additions & 105 deletions
This file was deleted.

README.md

Lines changed: 36 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,62 @@
11
# osm2rdf
22

3-
`osm2rdf` is a tool for converting the complete [OpenStreetMap](https://www.openstreetmap.org) (OSM) data to [RDF Turtle](https://www.w3.org/TR/turtle) (TTL).
3+
`osm2rdf` is a tool for converting [OpenStreetMap](https://www.openstreetmap.org) (OSM) data to [RDF Turtle](https://www.w3.org/TR/turtle) (TTL).
44

5-
We consider the following prefixes being used in our code and documentation:
5+
It also pre-computes the spatial relations `sfIntersects`, `sfContains`, `sfCovers`, `sfTouches`, `sfCrosses`, `sfOverlaps`, and `sfEquals` between all OSM objects.
66

7-
```
8-
PREFIX ogc: <http://www.opengis.net/rdf#>
9-
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
10-
PREFIX osm2rdf: <https://osm2rdf.cs.uni-freiburg.de/rdf#>
11-
```
12-
13-
The produced triples include:
14-
15-
1. One triple `<o> <key> <value> .` for each key-value pair (called "tag" in OSM) of each object.
16-
2. Two triples `<o> geo:hasGeometry <geom_o> . <geom_o> geo:asWKT <wkt> .` for the shape of each object (using [WKT](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry) to represent the shape).
17-
3. One triple `<o1> ogc:sfContains <o2> .` for each pair of objects, where `<o1>` geometrically contains `<o2>`.
18-
4. One triple `<o1> ogc:sfIntersects <o2> .` for each pair of objects, where `<o1>` geometrically intersects `<o2>`.
19-
5. Triples for various other kinds of information (see `osm2rdf --help` for the many options of the tool).
20-
21-
For the complete OSM data, the tool takes around 15 hours on standard hardware and produces around 40 billion triples with a size of around 200 GB for the compressed TTL file.
22-
23-
## Accompanying services and materials
7+
## Services and materials
248

25-
Weekly updated downloads for the complete data as well as for each individual country are provided on https://osm2rdf.cs.uni-freiburg.de .
9+
Weekly updated downloads for the complete OSM as well as for individual countries are provided [here](https://osm2rdf.cs.uni-freiburg.de).
2610

27-
A SPARQL endpoint (based on [the QLever SPARQL engine](https://github.com/ad-freiburg/qlever)) for the complete OSM data is available under https://qlever.cs.uni-freiburg.de/osm-planet . The UI provides many example queries (click on the "Examples" button).
11+
A SPARQL endpoint (based on [the QLever SPARQL engine](https://github.com/ad-freiburg/qlever)) for the complete OSM data is available under https://qlever.dev/osm-planet.
12+
Example: [all buildings under a powerline](https://qlever.dev/osm-planet/Wd07W1).
13+
The UI provides more example queries (click "Examples").
2814

2915
The basic method behind `osm2rdf` is described in [this SIGSPATIAL'21 paper](https://ad-publications.cs.uni-freiburg.de/SIGSPATIAL_osm2rdf_BBKL_2021.pdf).
3016

31-
The algorithm behind computing the predicates `geo:sfContains` and `geo:sfIntersects` will be published soon. For the complete OSM data, there are around 2 billion non-trivial geometric objects (this count excludes points that are merely base points of more complex shapes). It is very challenging to compute geometric relations between such a large number of objects in finite time.
17+
The methods behind computing the spatial relations are described in [this SIGSPATIAL'25 paper](https://ad-publications.cs.uni-freiburg.de/SIGSPATIAL_spatialjoin_BBK_2025.pdf).
3218

33-
## Getting started
19+
## Requirements
3420

35-
Some features require [boost](https://www.boost.org/) version **1.78 or newer**.
36-
To enable these features boost has to be updated manually on most systems as distributions do ship older versions.
21+
* cmake
22+
* Compiler for C++17
23+
* libexpat1
24+
* zlib
25+
* libbz2
26+
* libomp (optional, for multithreading)
3727

38-
### Docker
28+
## Quickstart
29+
30+
Fetch this repo:
3931

40-
The provided `Makefile` contains targets which build a Docker image, prepare input and output directories and downloads data.
41-
To run `osm2rdf` on germany it is enough to call:
4232
```
43-
make docker-de
33+
$ git clone https://github.com/ad-freiburg/osm2rdf.git
4434
```
45-
This creates the directories `input`, `output`, and `scratch`, downloads the data and runs `osm2rdf` with default parameters.
46-
47-
Alternatively use the provided `Dockerfile` to compile and run `osm2rdf`:
35+
Build `osm2rdf`:
36+
```
37+
$ cd osm2rdf
38+
$ mkdir -p build && cd build
39+
$ cmake ..
40+
$ make -j
41+
```
42+
Fetch an OSM input file and print TTL to stdout:
43+
```
44+
$ wget https://download.geofabrik.de/europe/germany/baden-wuerttemberg/freiburg-regbez-latest.osm.pbf
45+
$ ./apps/osm2rdf freiburg-regbex-latest.osm.pbf
4846
```
49-
$ mkdir input
50-
$ mkdir output
51-
$ mkdir scratch
5247

53-
$ docker build -t osm2rdf .
48+
For more options, see `--help`, `-h`, `-hh`, and `-hhh`.
5449

55-
$ wget -O ./input/germany-latest.osm.pbf https://download.geofabrik.de/europe/germany-latest.osm.pbf
56-
$ docker run --rm -v `pwd`/input/:/input/ -v `pwd`/output/:/output/ -v `pwd`/scratch/:/scratch/ -it osm2rdf /input/germany-latest.osm.pbf -o /output/germany-latest.osm.ttl -t /scratch/
57-
```
5850

59-
### Without Docker
51+
## Docker
6052

61-
On Ubuntu 20.04 the following packages are required to build osm2rdf:
53+
Alternatively you may use the provided `Dockerfile` to compile and run `osm2rdf`:
6254
```
63-
clang clang-tidy g++ libboost-dev libboost-serialization-dev libexpat1-dev cmake libbz2-dev zlib1g-dev libomp-dev
55+
$ docker build -t osm2rdf .
6456
```
65-
`clang` is optional, but without it `clang-tidy` has [unrelated error messages](https://stackoverflow.com/a/52728225).
6657

67-
Clone and build `osm2rdf`:
68-
```
69-
$ git clone https://github.com/ad-freiburg/osm2rdf.git
70-
$ cd osm2rdf
71-
$ mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug .. && make -j4 && cd ..
72-
```
73-
Prepare `input`, `output` and `scratch` folders and download some data and convert the data to `ttl`:
7458
```
7559
$ mkdir input
76-
$ mkdir output
77-
$ mkdir scratch
78-
$ wget -O ./input/freiburg-regbez-latest.osm.pbf https://download.geofabrik.de/europe/germany/baden-wuerttemberg/freiburg-regbez-latest.osm.pbf
79-
$ ./build/osm2rdf ./input/freiburg-regbez-latest.osm.pbf -o ./output/freiburg-regbez-latest.osm.ttl
60+
$ wget -O input/freiburg-regbez-latest.osm.pbf https://download.geofabrik.de/europe/germany/baden-wuerttemberg/freiburg-regbez-latest.osm.pbf
61+
$ docker run -v `pwd`/input/:/input/ -it osm2rdf /input/freiburg-regbex-latest.osm.pbf
8062
```
81-
82-
More `.pbf` files can be found on the [Geofabrik Download Server](https://download.geofabrik.de/index.html)

include/osm2rdf/osm/Constants.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
namespace osm2rdf::osm::constants {
2323

24-
static const int AREA_PRECISION = 12;
24+
static const int AREA_PRECISION = 4;
25+
static const int LENGTH_PRECISION = 2;
2526
static const int BASE10_BASE = 10;
2627
static const double BASE_SIMPLIFICATION_FACTOR = 0.001;
2728

include/osm2rdf/osm/OsmiumHandler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class OsmiumHandler : public osmium::handler::Handler {
8888
void handleBuffers(
8989
osmium::memory::Buffer& buffer,
9090
osmium::area::MultipolygonManager<osmium::area::Assembler>& mp_manager);
91+
void handleRelBuffers(
92+
osmium::memory::Buffer& buffer);
9193
void handleAreaBuffers(osmium::memory::Buffer& areaBuffer);
9294
};
9395
} // namespace osm2rdf::osm

src/osm/Area.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
// You should have received a copy of the GNU General Public License
1818
// along with osm2rdf. If not, see <https://www.gnu.org/licenses/>.
1919

20+
#include "osm2rdf/osm/Area.h"
21+
2022
#include <iostream>
2123
#include <limits>
2224

23-
#include "osm2rdf/osm/Area.h"
2425
#include "osm2rdf/osm/Constants.h"
2526
#include "osmium/osm/area.hpp"
2627
#include "util/geo/Geo.h"
@@ -33,7 +34,35 @@ osm2rdf::osm::Area::Area() {
3334

3435
// ____________________________________________________________________________
3536
void osm2rdf::osm::Area::finalize() noexcept {
36-
_geomArea = ::util::geo::area(_geom);
37+
// poly in area preserving projection
38+
::util::geo::DMultiPolygon lambertPoly;
39+
lambertPoly.resize(_geom.size());
40+
41+
double EARTH_RAD = 6371008.7714; // mean radius
42+
43+
for (size_t i = 0; i < _geom.size(); i++) {
44+
const auto& poly = _geom[i];
45+
lambertPoly[i].getOuter().reserve(poly.getOuter().size());
46+
for (const auto& p : poly.getOuter()) {
47+
lambertPoly[i].getOuter().push_back(
48+
::util::geo::DPoint{EARTH_RAD * (p.getX() * util::geo::RAD),
49+
EARTH_RAD * (sin(p.getY() * util::geo::RAD))});
50+
}
51+
52+
lambertPoly[i].getInners().reserve(poly.getInners().size());
53+
54+
for (const auto& inner : poly.getInners()) {
55+
lambertPoly[i].getInners().push_back({});
56+
lambertPoly[i].getInners().back().reserve(inner.size());
57+
for (const auto& p : inner) {
58+
lambertPoly[i].getInners().back().push_back(
59+
::util::geo::DPoint{EARTH_RAD * (p.getX() * util::geo::RAD),
60+
EARTH_RAD * (sin(p.getY() * util::geo::RAD))});
61+
}
62+
}
63+
}
64+
65+
_geomArea = ::util::geo::area(lambertPoly);
3766
}
3867

3968
// ____________________________________________________________________________
@@ -115,8 +144,7 @@ ::util::geo::DPolygon osm2rdf::osm::Area::convexHull() const noexcept {
115144
}
116145

117146
// ____________________________________________________________________________
118-
::util::geo::DPolygon osm2rdf::osm::Area::orientedBoundingBox()
119-
const noexcept {
147+
::util::geo::DPolygon osm2rdf::osm::Area::orientedBoundingBox() const noexcept {
120148
return ::util::geo::convexHull(::util::geo::getOrientedEnvelope(_geom));
121149
}
122150

@@ -129,8 +157,7 @@ const ::util::geo::DPoint osm2rdf::osm::Area::centroid() const noexcept {
129157
bool osm2rdf::osm::Area::operator==(
130158
const osm2rdf::osm::Area& other) const noexcept {
131159
return _id == other._id && _objId == other._objId &&
132-
_geomArea == other._geomArea &&
133-
_envelope == other._envelope &&
160+
_geomArea == other._geomArea && _envelope == other._envelope &&
134161
_geom == other._geom;
135162
}
136163

0 commit comments

Comments
 (0)