Skip to content

Commit 471beb8

Browse files
committed
Project refactoring
1 parent 44ec415 commit 471beb8

File tree

23 files changed

+137
-102
lines changed

23 files changed

+137
-102
lines changed

.docker-ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ gem 'puma', '~> 6.0'
99

1010
gem 'hanami-api'
1111

12+
# gem 'duckdb'
1213
gem 'overpass_parser', git: 'https://github.com/teritorio/overpass_parser-rb.git'
1314
gem 'pg'
1415
gem 'sorbet-runtime'

README.md

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,12 @@ An Overpass-API on SQL Database.
44

55
Underpass-API aim to be a [Overpass-API](https://github.com/drolbr/Overpass-API) compatible engine built upon [converter](https://github.com/teritorio/overpass_parser-rb) from Overpass Language to SQL.
66

7-
## Prepare the data
7+
## Prepare the data & Run the server
88

99
Folow the instruction of one of the backends:
10-
* Postgres/PostGIS, Osmosis schema
11-
* DuckDB/Spatial, Quackosm schema
10+
* [Postgres+PostGIS / Osmosis](backends/postgres_osmosis/README.md), Osmosis schema
11+
* [DuckDB+Spatial / QuackOSM](backends/duckdb_quackosm/README.md), Quackosm schema
1212

13-
## Run the server
13+
## Query
1414

15-
Install dependencies
16-
```
17-
bundle
18-
```
19-
20-
Run the HTTP server
21-
```
22-
DB=landes_nofilter_noclip_compact.parquet
23-
bundle exec rackup
24-
```
15+
The API as available at http://localhost:9292/interpreter

backends/duckdb_quackosm.md

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

backends/duckdb_quackosm.sql

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

backends/duckdb_quackosm/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# DuckDB/Spatial, Quackosm schema
2+
3+
Prepare Docker
4+
```sh
5+
docker compose --profile '*' build
6+
```
7+
8+
## Prepare the data
9+
10+
```sh
11+
docker compose run --rm quackosm
12+
```
13+
14+
```sh
15+
quackosm /data/landes-latest.osm.pbf
16+
mv files/landes-latest_nofilter_noclip_compact.parquet /data/extract_nofilter_noclip_compact.parquet
17+
```
18+
19+
## Run the server
20+
21+
Run the HTTP server
22+
```
23+
docker compose up
24+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: "3.3"
2+
3+
services:
4+
quackosm:
5+
profiles: [tools]
6+
build:
7+
context: docker/quackosm
8+
volumes:
9+
- ../../data:/data
10+
11+
api:
12+
extends:
13+
file: ../../docker-compose-base.yaml
14+
service: api
15+
environment:
16+
BACKEND: DuckdbQuackosm
17+
DB: /data/extract_nofilter_noclip_compact.parquet
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM python:3.12-slim
2+
3+
RUN apt update -y && apt install -y \
4+
build-essential
5+
6+
RUN pip install quackosm[cli]
7+
8+
CMD /bin/bash

backends/duckdb_quackosm.rb renamed to backends/duckdb_quackosm/duckdb_quackosm.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ def initialize
88
parquet = ENV['DB']
99
db = DuckDB::Database.open # database in memory
1010
@@con = db.connect
11-
@@con.query(File.read(__FILE__.gsub(/\.rb$/, '.sql')).gsub('#{parquet}', parquet))
11+
@@con.query(File.read(File.dirname(__FILE__) + '/view.sql').gsub('#{parquet}', parquet))
12+
1213
@dialect = OverpassParser::SqlDialect::Duckdb.new
1314
end
1415

backends/duckdb_quackosm/view.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
INSTALL 'spatial';
2+
LOAD 'spatial';
3+
4+
CREATE OR REPLACE TEMP VIEW node AS
5+
SELECT split_part(feature_id, '/', 2)::bigint AS id, NULL::int AS version, NULL::timestamp AS created, NULL::int AS changeset, NULL::int AS uid, tags, NULL::bigint[] AS nodes, NULL::json AS members, ST_GeomFromWKB(geometry) AS geom, feature_id[1] AS osm_type FROM '#{parquet}' WHERE feature_id < 'o';
6+
7+
CREATE OR REPLACE TEMP VIEW way AS
8+
SELECT split_part(feature_id, '/', 2)::bigint AS id, NULL::int AS version, NULL::timestamp AS created, NULL::int AS changeset, NULL::int AS uid, tags, NULL::bigint[] AS nodes, NULL::json AS members, ST_GeomFromWKB(geometry) AS geom, feature_id[1] AS osm_type FROM '#{parquet}' WHERE feature_id > 'w';
9+
10+
CREATE OR REPLACE TEMP VIEW relation AS
11+
SELECT split_part(feature_id, '/', 2)::bigint AS id, NULL::int AS version, NULL::timestamp AS created, NULL::int AS changeset, NULL::int AS uid, tags, NULL::bigint[] AS nodes, NULL::json AS members, ST_GeomFromWKB(geometry) AS geom, feature_id[1] AS osm_type FROM '#{parquet}' WHERE feature_id > 'o' AND feature_id < 's';
12+
13+
CREATE OR REPLACE TEMP VIEW nwr AS
14+
SELECT split_part(feature_id, '/', 2)::bigint AS id, NULL::int AS version, NULL::timestamp AS created, NULL::int AS changeset, NULL::int AS uid, tags, NULL::bigint[] AS nodes, NULL::json AS members, ST_GeomFromWKB(geometry) AS geom, feature_id[1] AS osm_type FROM '#{parquet}';
15+
16+
CREATE OR REPLACE TEMP VIEW area AS
17+
SELECT split_part(feature_id, '/', 2)::bigint + CASE feature_id[1] WHEN 'r' THEN 3600000000 ELSE 0 END AS id, NULL::int AS version, NULL::timestamp AS created, NULL::int AS changeset, NULL::int AS uid, tags, NULL::bigint[] AS nodes, NULL::json AS members, ST_GeomFromWKB(geometry) AS geom, CASE feature_id[1] WHEN 'w' THEN 'w' ELSE 'a' END AS osm_type FROM '#{parquet}' wHERE feature_id > 'm' AND list_contains(['POLYGON', 'MULTIPOLYGON'], ST_GeometryType(ST_GeomFromWKB(geometry)));

0 commit comments

Comments
 (0)