Skip to content

Commit 419c545

Browse files
Rub21geohacker
authored andcommitted
Update api db container to postgres 11
1 parent aefc29f commit 419c545

File tree

3 files changed

+66
-15
lines changed

3 files changed

+66
-15
lines changed

images/db/Dockerfile

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
FROM postgres:9.5
2-
RUN apt-get update
3-
RUN apt-get install -y make \
4-
postgresql-server-dev-9.5 \
5-
build-essential \
6-
postgresql-9.5-postgis-2.3 \
7-
&& apt-get clean && rm -rf /var/lib/apt/lists/*
8-
RUN mkdir -p db
9-
RUN mkdir -p lib
10-
ADD docker_postgres.sh docker-entrypoint-initdb.d/docker_postgres.sh
11-
ADD functions/ db/functions/
12-
ADD lib/quad_tile/ lib/quad_tile/
13-
RUN make -C db/functions/
14-
RUN chown -R postgres lib/
15-
RUN chown -R postgres db/
1+
FROM postgres:11
2+
3+
# Add db init script to install OSM-specific Postgres functions/extensions.
4+
ADD openstreetmap-postgres-init.sh /docker-entrypoint-initdb.d/
5+
6+
# Custom database functions are in a SQL file.
7+
ADD functions/functions.sql /usr/local/share/osm-db-functions.sql

images/db/functions/functions.sql

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--------------------------------------------------------------------------------
2+
-- From https://github.com/openstreetmap/openstreetmap-website/blob/af273f5d6ae160de0001ce1ac0c087d92a2463c6/db/functions/functions.sql
3+
-- SQL versions of the C database functions.
4+
--
5+
-- Pure pl/pgsql versions are *slower* than the C versions, and not recommended
6+
-- for production use. However, they are significantly easier to install, and
7+
-- require fewer dependencies.
8+
--------------------------------------------------------------------------------
9+
10+
-- tile_for_point function returns a Morton-encoded integer representing a z16
11+
-- tile which contains the given (scaled_lon, scaled_lat) coordinate. Note that
12+
-- these are passed into the function as (lat, lon) and should be scaled by
13+
-- 10^7.
14+
--
15+
-- The Morton encoding packs two dimensions down to one with fairly good
16+
-- spatial locality, and can be used to index points without the need for a
17+
-- proper 2D index.
18+
CREATE OR REPLACE FUNCTION tile_for_point(scaled_lat int4, scaled_lon int4)
19+
RETURNS int8
20+
AS $$
21+
DECLARE
22+
x int8; -- quantized x from lon,
23+
y int8; -- quantized y from lat,
24+
BEGIN
25+
x := round(((scaled_lon / 10000000.0) + 180.0) * 65535.0 / 360.0);
26+
y := round(((scaled_lat / 10000000.0) + 90.0) * 65535.0 / 180.0);
27+
28+
-- these bit-masks are special numbers used in the bit interleaving algorithm.
29+
-- see https://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN
30+
-- for the original algorithm and more details.
31+
x := (x | (x << 8)) & 16711935; -- 0x00FF00FF
32+
x := (x | (x << 4)) & 252645135; -- 0x0F0F0F0F
33+
x := (x | (x << 2)) & 858993459; -- 0x33333333
34+
x := (x | (x << 1)) & 1431655765; -- 0x55555555
35+
36+
y := (y | (y << 8)) & 16711935; -- 0x00FF00FF
37+
y := (y | (y << 4)) & 252645135; -- 0x0F0F0F0F
38+
y := (y | (y << 2)) & 858993459; -- 0x33333333
39+
y := (y | (y << 1)) & 1431655765; -- 0x55555555
40+
41+
RETURN (x << 1) | y;
42+
END;
43+
$$ LANGUAGE plpgsql IMMUTABLE;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
# From: https://github.com/openstreetmap/openstreetmap-website/blob/af273f5d6ae160de0001ce1ac0c087d92a2463c6/docker/postgres/openstreetmap-postgres-init.sh
5+
# Create 'openstreetmap' user
6+
# Password and superuser privilege are needed to successfully run test suite
7+
psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" <<-EOSQL
8+
CREATE USER openstreetmap SUPERUSER PASSWORD 'openstreetmap';
9+
GRANT ALL PRIVILEGES ON DATABASE openstreetmap TO openstreetmap;
10+
EOSQL
11+
12+
# Create btree_gist extensions
13+
psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -c "CREATE EXTENSION btree_gist" openstreetmap
14+
15+
# Define custom functions
16+
psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -f "/usr/local/share/osm-db-functions.sql" openstreetmap

0 commit comments

Comments
 (0)