Skip to content

Commit 60b0e97

Browse files
authored
Merge pull request #5 from gedankenstuecke/dockerize
Create docker image to run make.sh
2 parents aa5296c + d14956d commit 60b0e97

File tree

4 files changed

+145
-16
lines changed

4 files changed

+145
-16
lines changed

Dockerfile

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
FROM postgis/postgis:15-3.5 AS development_build
2+
3+
RUN apt-get update \
4+
&& apt-get install -y --no-install-recommends \
5+
ca-certificates gnupg lsb-release locales \
6+
wget curl \
7+
git-core unzip \
8+
&& locale-gen $LANG && update-locale LANG=$LANG
9+
10+
11+
# Get packages
12+
RUN apt-get update \
13+
&& apt-get install -y --no-install-recommends \
14+
make \
15+
fonts-hanazono \
16+
fonts-noto-cjk \
17+
fonts-noto-hinted \
18+
fonts-noto-unhinted \
19+
fonts-unifont \
20+
gdal-bin \
21+
graphicsmagick \
22+
liblua5.3-dev \
23+
libosmium2-dev \
24+
libprotozero-dev \
25+
lua5.3 \
26+
mapnik-utils \
27+
npm \
28+
osm2pgsql \
29+
osmium-tool \
30+
osmosis \
31+
python-is-python3 \
32+
python3-mapnik \
33+
python3-lxml \
34+
python3-psycopg2 \
35+
python3-shapely \
36+
python3-pip \
37+
sudo \
38+
vim \
39+
&& apt-get clean autoclean \
40+
&& apt-get autoremove --yes \
41+
&& rm -rf /var/lib/{apt,dpkg,cache,log}/
42+
43+
RUN wget https://downloads.sourceforge.net/gs-fonts/ghostscript-fonts-std-8.11.tar.gz
44+
RUN tar xvf ghostscript-fonts-std-8.11.tar.gz
45+
RUN mkdir -p /usr/share/fonts/type1/
46+
RUN mv fonts/ /usr/share/fonts/type1/gsfonts
47+
48+
# Install python libraries
49+
50+
RUN pip install pyyaml nik4 requests
51+
52+
# Install carto for stylesheet
53+
RUN npm install -g [email protected]
54+
55+
56+
COPY . /workdir
57+
58+
RUN mkdir -p /workdir/openstreetmap-carto/data
59+
RUN mkdir -p /workdir/output
60+
61+
WORKDIR /workdir
62+
63+
RUN chown postgres:postgres -R /workdir
64+
65+
USER postgres

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,59 @@ Make a image of OSM data of an area from 2 dates, showing what was changed.
2626
cd osm-mapping-party-before-after
2727
```
2828
29+
### Install & use via Docker image
30+
31+
Alternatively, if you do not want to install the whole pipeline yourself, you can run this setup in a Docker container that is ready to use.
32+
We start, by cloning this repository:
33+
34+
```bash
35+
git clone --recurse-submodules https://github.com/amandasaurus/osm-mapping-party-before-after
36+
cd osm-mapping-party-before-after
37+
git submodule init
38+
git submodule update
39+
```
40+
Then we build the image that is specified in the `Dockerfile`, picking a name for the image, e.g. `before_after_builder`.
41+
Depending on how you installed Docker, you might have to run `sudo` for each `docker` command.
42+
43+
```bash
44+
docker build -t before_after_builder .
45+
```
46+
47+
This step needs to be run only once, and it can take a few minutes as it will download and build all the dependencies needed.
48+
Once the step is finished, you can launch the container like so:
49+
50+
```bash
51+
./docker_run.sh before_after_builder /full/path/to/in-out-dir/
52+
```
53+
54+
The command takes two parameters:
55+
56+
1. the name of the container (as specified above)
57+
2. a full path to a directory you want to use for accessing and writing files to from the container (i.e. Input and output files). Depending on how you installed/run Docker, this folder might need full read/write permissions for other users (e.g. run `chmod 777`).
58+
59+
The `docker_run.sh` command will launch the container itself, including the necessary postgres database etc.
60+
It will also create two virtual docker volumes (named `pgdata` and `osm_data`).
61+
These volumes are used to store external data, i.e. the database contents and the `openstreetmap-carto` external files.
62+
63+
Once the docker container is running, you can connect into it to get a bash inside to run the commands as outlined below using:
64+
65+
```bash
66+
docker exec -ti map-before-after bash
67+
```
68+
69+
The resulting shell puts you into the equivalent of the root of this repository, in a folder called `/workdir`. From there you can use this repository as outlined below.
70+
71+
All output files are saved in the `/workdir` by default, you can from there move them into `/workdir/output` inside the container to access files on your host operating system.
72+
73+
A [ready-built image is available on Docker Hub](https://hub.docker.com/r/gedankenstuecke/osm-mapping-party-before-after).
74+
2975
## Usage
3076
3177
1. Download an OSM history file (`.osh.pbf`) e.g. from [Geofabrik's internal download server](https://osm-internal.download.geofabrik.de/?landing_page=true). You will need to log in with an OSM account.
3278
1. Calculate the `BBOX` with [BBoxFinder.com](http://bboxfinder.com/).
3379
1. *Draw a rectangle*
3480
1. Copy the *Box* value
81+
1. Make sure coordinates are in `long/lat` format (can be changed in the bottom-right)
3582
1. Run the following command:
3683
```bash
3784
./make.sh OSM_HISTORY_FILE.osh.pbf BEFORE_TIME AFTER_TIME BBOX MIN_ZOOM MAX_ZOOM

docker_run.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# run docker with correct minimal settings to mount
4+
# a) postgres db
5+
# b) opencarto data directory
6+
# c) import/export directory for files
7+
# and also use correct user etc
8+
9+
# Requires 1 parameters: 1. name of the docker image, 2. full path to input/output directory
10+
# depending on your setup, the input/output directory needs to have `chmod 777` on the directory to work
11+
12+
IMAGE_NAME=$1
13+
OUTPUT_DIR=$2
14+
15+
16+
docker run --rm -e POSTGRES_PASSWORD="unused" -v pgdata:/var/lib/postgresql/data -v osm_data:/workdir/openstreetmap-carto/data -v $OUTPUT_DIR:/workdir/output --name map-before-after $IMAGE_NAME

make.sh

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,21 @@ if [ ! -s "$ROOT/openstreetmap-carto/project.xml" ] ; then
8484

8585
fi
8686

87-
if [ ! -e "$ROOT/openstreetmap-carto/.external-data-done" ] ; then
88-
cd "$ROOT/openstreetmap-carto/"
89-
echo "Downloading external datasets..."
90-
./scripts/get-external-data.py
91-
touch .external-data-done
92-
cd "$ROOT"
93-
fi
94-
9587
if [ "$(psql -At -c "select count(*) from pg_database where datname = 'gis';")" = "0" ] ; then
9688
echo "Creating gis database..."
9789
createdb gis
9890
psql -d gis -c "create extension postgis;"
9991
psql -d gis -c "create extension hstore;"
10092
fi
10193

94+
if [ ! -e "$ROOT/openstreetmap-carto/data/.external-data-done" ] ; then
95+
cd "$ROOT/openstreetmap-carto/"
96+
echo "Downloading external datasets..."
97+
./scripts/get-external-data.py
98+
touch data/.external-data-done
99+
cd "$ROOT"
100+
fi
101+
102102
if [ "$BEFORE_FILENAME" -nt "$ROOT/.$PREFIX.$TIME_BEFORE.$BBOX_COMMA.generated" ] ; then
103103
cd "$ROOT/openstreetmap-carto"
104104
osm2pgsql -G --hstore --style openstreetmap-carto.style --tag-transform-script openstreetmap-carto.lua -d gis "$BEFORE_FILENAME"
@@ -112,11 +112,11 @@ for ZOOM in $(seq "$MIN_ZOOM" "$MAX_ZOOM") ; do
112112
if [ "$ROOT/.$PREFIX.$TIME_BEFORE.$BBOX_COMMA.generated" -nt "$PREFIX.$TIME_BEFORE.$BBOX_COMMA.z${ZOOM}.png" ] ; then
113113
# eventually the image is too large, so then just break out of the loop
114114
echo "Generating zoom ${ZOOM} level"
115-
nik4 openstreetmap-carto/project.xml "$PREFIX.$TIME_BEFORE.$BBOX_COMMA.z${ZOOM}.png" -b $BBOX_SPACE -z "$ZOOM" || break
115+
nik4.py openstreetmap-carto/project.xml "$PREFIX.$TIME_BEFORE.$BBOX_COMMA.z${ZOOM}.png" -b $BBOX_SPACE -z "$ZOOM" || break
116116
NEW="$(mktemp tmp.XXXXXX.png)"
117-
gm convert "$PREFIX.$TIME_BEFORE.$BBOX_COMMA.z${ZOOM}.png" -background white label:"${TIME_BEFORE}" -gravity center -append "$NEW"
118-
mv "$NEW" "$PREFIX.$TIME_BEFORE.$BBOX_COMMA.z${ZOOM}.png"
119-
gm convert "$PREFIX.$TIME_BEFORE.$BBOX_COMMA.z${ZOOM}.png" -background white label:"Data © OpenStreetMap contributors, ODbL" -gravity center -append "$NEW"
117+
#gm convert "$PREFIX.$TIME_BEFORE.$BBOX_COMMA.z${ZOOM}.png" -background white -label "${TIME_BEFORE}" -gravity center -append "$NEW"
118+
#mv "$NEW" "$PREFIX.$TIME_BEFORE.$BBOX_COMMA.z${ZOOM}.png"
119+
gm convert "$PREFIX.$TIME_BEFORE.$BBOX_COMMA.z${ZOOM}.png" -background white -label "${TIME_BEFORE}, data © OpenStreetMap contributors, ODbL" -gravity center -append "$NEW"
120120
mv "$NEW" "$PREFIX.$TIME_BEFORE.$BBOX_COMMA.z${ZOOM}.png"
121121
fi
122122
done
@@ -133,11 +133,11 @@ for ZOOM in $(seq "$MIN_ZOOM" "$MAX_ZOOM") ; do
133133
if [ "$ROOT/.$PREFIX.$TIME_AFTER.$BBOX_COMMA.generated" -nt "$PREFIX.$TIME_AFTER.$BBOX_COMMA.z${ZOOM}.png" ] ; then
134134
# eventually the image is too large, so then just break out of the loop
135135
echo "Generating zoom ${ZOOM} level"
136-
nik4 openstreetmap-carto/project.xml "$PREFIX.$TIME_AFTER.$BBOX_COMMA.z${ZOOM}.png" -b $BBOX_SPACE -z "$ZOOM" || break
136+
nik4.py openstreetmap-carto/project.xml "$PREFIX.$TIME_AFTER.$BBOX_COMMA.z${ZOOM}.png" -b $BBOX_SPACE -z "$ZOOM" || break
137137
NEW="$(mktemp tmp.XXXXXX.png)"
138-
gm convert "$PREFIX.$TIME_AFTER.$BBOX_COMMA.z${ZOOM}.png" -background white -label "$TIME_AFTER" -gravity center -append "$NEW"
139-
mv "$NEW" "$PREFIX.$TIME_AFTER.$BBOX_COMMA.z${ZOOM}.png"
140-
gm convert "$PREFIX.$TIME_AFTER.$BBOX_COMMA.z${ZOOM}.png" -background white -label "Data © OpenStreetMap contributors, ODbL" -gravity center -append "$NEW"
138+
#gm convert "$PREFIX.$TIME_AFTER.$BBOX_COMMA.z${ZOOM}.png" -background white -label "$TIME_AFTER" -gravity center -append "$NEW"
139+
#mv "$NEW" "$PREFIX.$TIME_AFTER.$BBOX_COMMA.z${ZOOM}.png"
140+
gm convert "$PREFIX.$TIME_AFTER.$BBOX_COMMA.z${ZOOM}.png" -background white -label "${TIME_AFTER}, data © OpenStreetMap contributors, ODbL" -gravity center -append "$NEW"
141141
mv "$NEW" "$PREFIX.$TIME_AFTER.$BBOX_COMMA.z${ZOOM}.png"
142142
fi
143143
done
@@ -155,6 +155,7 @@ for ZOOM in $(seq "$MIN_ZOOM" "$MAX_ZOOM") ; do
155155
if [ "$BEFORE" -nt "$NEW_PNG" ] || [ "$AFTER" -nt "$NEW_PNG" ] ; then
156156
TMP="$(mktemp tmp.XXXXXX.png)"
157157
gm montage -geometry +0+0 "$BEFORE" "$AFTER" "$TMP"
158+
158159
gm convert "$TMP" -background white -label "Data © OpenStreetMap contributors, ODbL" -gravity center -append "$NEW_PNG"
159160
fi
160161

0 commit comments

Comments
 (0)