• Stars
    star
    285
  • Rank 145,115 (Top 3 %)
  • Language
    C
  • License
    GNU General Publi...
  • Created over 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A docker compose project to setup an OSM PostGIS database with automatic updates from OSM periodically

Docker-OSM

A docker compose project to setup an OSM PostGIS database with automatic updates from OSM periodically. The only files you need is a PBF file, geojson (if you intend to restrict data download to a smaller extent than the one specified by the PBF) and run the docker compose project.

General architecture

Alt text

Quick setup

As a quick example, we are going to setup Docker-OSM with default values everywhere:

Alternatively you can execute the settings_downloader.sh script to download the pbf and the clip file

bash ./settings_downloader.sh GEOJSON_URL CONTINENT COUNTRY ie
bash ./settings_downloader.sh https://github.com/kartoza/docker-osm/raw/develop/settings/clip.geojson africa south-africa

For a full list of allowed file names read json file countries.json

Alternatively you can use the python script pbf_downloader.py

For local usage, the containers are set up using docker-compose configuration. The configuration files consists of two sets of config file. The first one is .env which contains lists of environment variables. Copy the .env file from the .example.env in this repo.

cp .example.env .env

For subsequent configuration, edit the .env files to tweak your options.

The second set of configuration is using a docker-compose.yml files, which is a compose files docker-compose is using.

For minimum set of production environment, the configuration file is described in docker-compose.yml file. The other YAML files with prefix docker-compose is a configuration file that you can merge with the basic docker-compose.yml file. To use more than one configuration file, you edit .env file and change the COMPOSE_FILE variable to include all the compose file you desired, separated by a colon : for each file.

For example, by default, the example file is using both docker-compose.yml and docker-compose.develop.yml because we expect you to provide the necessary settings in settings folder. Thus the COMPOSE_FILE variable looks like this:

COMPOSE_FILE=docker-compose.yml:docker-compose.develop.yml

In production environment, normally all the persistent data is stored in a volume, instead of bind mounted. In this case only the docker-compose.yml is enough, and you need to provide the settings inside the volume itself.

To build the image yourself, include the docker-compose.build.yml file.

To use helper services such as pgadmin, include docker-compose.pgadmin.yml, and docker-compose.web.yml for web demo.

If you are familiar with how docker-compose work, you can also use a standard convention by putting docker-compose.override.yml file and include it in the COMPOSE_FILE variable.

To store the configuration for long-term use (for archiving or diffing of different configuration). You can interpolate the current variables in .env and generate a full config files:

docker-compose config > docker-compose.production.yml

The above command will include and merged all your config files specified in COMPOSE_FILE variable and also fill out the variables parameterized in the docker-compose file.

  • If you want to connect from your local QGIS Desktop:
    • In the file docker-compose.yml, uncomment the block:
# Uncomment to use the postgis database from outside the docker network
ports:
 - "35432:5432"
  • Do make run in the build directory. This will download and execute the docker-osm project. It might be very long depending of your bandwidth and the PBF you are importing.
  • In QGIS, add a new PostGIS connection: localhost, database gis, port 35432, docker for both username and password.
  • That's it! You have an OSM database, up and running. The update is done every 2 minutes from the main OSM website.

For further reading and customizations, read below.

Docker cloud

Dockerfiles are executed on Docker Cloud kartoza/docker-osm

docker pull kartoza/docker-osm:imposm-latest
docker pull kartoza/docker-osm:osmupdate-latest

To run you can use the provided docker-compose project and use the images hosted on the internet. This is useful if you want to integrate Docker-OSM in your existing docker-compose project.

Usage

PBF File

In this example we will set up an OSM database for South Africa that will pull for updates every 2 minutes.

Specify a PBF file for your area in the environment variables for osm_downloader container. You can download some PBF files on these URLS for instance :

You must put only one PBF file in the settings folder. Only the last one will be read.

OSM Features

In settings, you can edit the mapping.yml to customize the PostGIS schema. You can find the documentation about the mapping configuration on the imposm website: https://imposm.org/docs/imposm3/latest/mapping.html The default file in Docker-OSM is coming from https://raw.githubusercontent.com/omniscale/imposm3/master/example-mapping.yml

Note Imposm is designed for spatial analysis, not for OSM contribution analysis. If you need such a feature, you need to use another database schema supporting OSM Metadata. You can check the OSM Wiki for "Lossless" schemas.

Updates

You can configure the time interval in the docker-compose file. By default, it's two minutes. If you set the TIME variable to 0, no diff files will be imported.

The default update stream is worldwide. So even if you imported a local PBF, if you don't set a clipping area, you will end with data from all over the world.

Clipping

During the initial import or post update imposm uses the flag -limito which allows you to define a smaller area that you can work with.
This is always desirable to limit the features being imported into the database rather than clipping them.

NB: Ensure you add a geojson covering the area you intend to clip into the settings folder. The geojson can be the same extent of the administrative area for your country, or it can be a smaller extent. The CRS of the geojson should always be EPSG:4326.

NB: It is encouraged to simplify the geometry for the clip.geojson as a simplified geometry is easier to process during the import. Rather use the minimum bounding box for the area you intend to clip your dataset with.

QGIS project

There is a default QGIS project provided in the web/ folder, named osm_mirror_qgis_project.qgz. To be able to load the layers in this project correctly in QGIS, first run make materialized_views and make elevation then set up your connection service file with the following parameters. The host parameter is where you have set up docker-osm:

[docker-osm]
dbname=gis
port=35432
user=docker
password=docker
host=<host>
sslmode=disable

QGIS Styles

The database is provided with some default styles. These styles will be loaded automatically when loaded in QGIS. It's following the default OSM mapping from ImpOSM.

make import_styles
make remove_styles
make backup_styles

SQL Trigger, functions, views...

You can add PostGIS functions, triggers, materialized views into an SQL file called post-pbf-import.sql. It will be imported automatically in the database.

Build and run

Now build the docker images needed to run the application:

docker-compose build
docker-compose up 

In production, you should daemonize the services when bringing them up:

docker-compose up -d

You can check the timestamp of your database by reading the file : settings/timestamp.txt or you can use :

make timestamp

Display

In the makefile, you can switch to another docker compose project. The other one includes QGIS Server. When it's running, you should be able to open, on the host(not in docker), the index.html file and see OSM and QGIS Server showing PostGIS tables. The webpage is using Leaflet.

If you want to tweak the QGIS Project, you need to add a host in your in /etc/hosts:

127.0.0.1       db

Because in the docker-compose file, the link is made with the PostGIS database using the alias db.

In the background

architecture

Docker OSM Update

This docker image, when run will regularly fetch any new diff file for all the changes that have happened in the world over the update interval.

You can also specify a custom url for fetching the diff if you wish to retrieve regional diffs rather than the global one.

You can specify a polygonal area for the diff so that it will only apply features from the diff that fall within that area. For example providing a polygon of the borders of Malawi will result in only Malawi features being extracted from the diff.

Note: the diff retrieved and options specified here are not related to the initial base map used - so for example if your initial base map is for Malawi and you specify a diff area in Botswana, updated features in Botswana will be applied to your base map which only includes features from Malawi. For this reason, take care to ensure that your diff area coincides with the region covered by your original base map.

Once the diff has been downloaded, it is placed into /home/import_queue where it will be picked up by the long running imposm3 container, which will apply the diff to the database.

You should have 3 folders : osm_pbf, import_queue, import_done

Put a state file in base-pbf like this one : http://download.openstreetmap.fr/extracts/africa/south_africa.state.txt

docker build -t osmupdate .
docker run -v $('pwd')import-queue/:/home/import-queue -v $('pwd')base-pbf/:/home/base-pbf -v $('pwd')import-done/:/home/import-done -d osmupdate

With -e, you can add some settings :

 - MAX_DAYS = 100, the maximum time range to assemble a cumulated changefile.
 - DIFF = sporadic, osmupdate uses a combination of minutely, hourly and daily changefiles. This value can be minute, hour, day or sporadic.
 - MAX_MERGE = 7, argument to determine the maximum number of parallely processed changefiles.
 - COMPRESSION_LEVEL = 1, define level for gzip compression. values between 1 (low compression but fast) and 9 (high compression but slow)
 - BASE_URL = http://planet.openstreetmap.org/replication/, change the URL to use a custom URL to fetch regional file updates.
 - IMPORT_QUEUE = import_queue
 - IMPORT_DONE = import_done
 - OSM_PBF = osm_pbf
 - TIME = 120, seconds between two executions of the script

If you are using docker-compose, you can use these settings within the docker-compose.yml file.

Docker ImpOSM3

This image will take care of doing the initial load for the selected region (e.g. planet, or a country such as Malawi) into your database. It will then apply, at a regular interval (default is 2 minutes), any diff that arrives in the /home/import_queue folder to the postgis OSM database. The diffs are fetched by a separate container (see osm_update container).

The container will look for an OSM file (.pbf) and its state file (.state.txt) in BASE_PBF.

With -e, you can add some settings :

 - TIME = 120, seconds between 2 executions of the script
 - POSTGRES_USER = docker, default user
 - POSTGRES_PASS = docker, default password
 - POSTGRES_HOST = db
 - POSTGRES_PORT = 5432
 - SETTINGS = settings, folder for settings (with *.json and *.sql)
 - CACHE = cache, folder for caching
 - BASE_PBF = base_pbf, folder the OSM file
 - IMPORT_DONE = import_done, folder for diff which has been imported
 - IMPORT_QUEUE = import_queue, folder for diff which hasn't been imported yet
 - SRID = 4326, it can be 3857
 - OPTIMIZE = false, check (Imposm)[http://imposm.org/docs/imposm3/latest/tutorial.html#optimize]
 - DBSCHEMA_PRODUCTION = public, check (Imposm)[http://imposm.org/docs/imposm3/latest/tutorial.html#deploy-production-tables]
 - DBSCHEMA_IMPORT = import, check (Imposm)[http://imposm.org/docs/imposm3/latest/tutorial.html#deploy-production-tables]
 - DBSCHEMA_BACKUP = backup, check (Imposm)[http://imposm.org/docs/imposm3/latest/tutorial.html#deploy-production-tables]

You can adjust these preferences in the docker-compose.yml file provided in this repository.

PostGIS

For environment variables associated with docker-postgis refer to docker postgis repository

Support

If you require more substantial assistance from kartoza (because our work and interaction on docker-osm is pro bono), please consider taking out a Support Level Agreeement

Credits

This application was designed and implemented by:

With some important design ideas provided by Ariel Nunez ([email protected]).

Parts of this project are built on the existing work of others.

July 2015

More Repositories

1

docker-postgis

Dockerfile for postgis
Shell
648
star
2

docker-geoserver

A docker recipe for GeoServer
Shell
610
star
3

docker-pg-backup

A cron job that will back up databases running in a docker postgres container
Shell
450
star
4

docker-qgis-desktop

A docker project that will run your QGIS desktop app inside a docker container
Shell
96
star
5

docker-qgis-server

A dockerfile that contains a running QGIS server
QML
69
star
6

docker-mapproxy

A docker recipe for http://mapproxy.org/
Shell
62
star
7

QGIS-Legend-Patches

A collection of patches to use in your legends in QGIS!
Python
49
star
8

osgs

A rich, integrated, and opinionated GIS Stack with a focus on configurability and ease of use, built from Open Source Components
Makefile
40
star
9

leaflet-wms-legend

A simple leaflet WMS legend widget
JavaScript
37
star
10

docker-mapserver

Mapserver in Docker
HTML
37
star
11

prj.app

A django app for creating visual changelogs for software releases
Python
30
star
12

fbf-project

Project data and resources for WB Forecast Based Financing work
TSQL
23
star
13

docker-tilemill

A docker project for tilemill
Shell
21
star
14

docker-ssh

A simple docker container that runs ssh
Shell
20
star
15

kartoza-rancher-catalogue

This is our catalogue of Rancher recipes
19
star
16

osm-reporter

osm-reporter
JavaScript
19
star
17

awesome-geodata

A curated list of awesome geospatial data sources and services
19
star
18

maps.kartoza.com

Maps and web site for http://maps.kartoza.com
Python
18
star
19

docker-helpers

Helper commands for docker because typing long docker commands is boring...
Shell
15
star
20

django-bims

JavaScript
12
star
21

charts

Kartoza Helm charts for Kubernetes
Smarty
11
star
22

geocontext

A django app to retrieve context for spatial feature
Python
9
star
23

QGISTrainingWorkshop

This is a hands on workshop for QGIS, InaSAFE and OSM
QML
9
star
24

docker-qgis-orchestration

Orchestration scripts for QGIS docker services
9
star
25

docker-mezzanine

A docker project for mezzanine (http://mezzanine.jupo.org/)
JavaScript
9
star
26

geonode_qgis_server

Django app to make geonode work with QGIS Server
Python
9
star
27

SpeciesExplorer

A QGIS (3 or greater) plugin for quickly retrieving species occurrence data from GBIF.
Python
9
star
28

docker-django

A django ready docker container with nginx and uwsgi for serving up your site
Shell
8
star
29

docker-geogig

A docker container for using geogig (formerly known as geogit)
Shell
7
star
30

otf-project

Python
7
star
31

geosafe

InaSAFE package for Geonode
Python
7
star
32

docker-tao-web

Docker appliance for the tao examination platform (see http://taotesting.com/)
Shell
6
star
33

stream_feature_extractor

A QGIS plugin to extract stream features (wells, sinks, confluences etc.) from a stream network
QML
6
star
34

topostyle

publish and style South African 1:50000 topographical map vector data from NGI
QML
6
star
35

TheKartozaHandbook

Organisational Handbook and Technical Docs Repository for Kartoza. Here is where we highlight the procedures, principles and processes related to Development, DevOps, and GIS in line with the organisation's best practices
Nix
6
star
36

django-wms-client

A django application that provides generic WMS client support.
Python
5
star
37

docker-sftp-backup

Docker project to back up your data to an sftp server using rotating backup system
Python
5
star
38

docker-geosafe

Geosafe and GeoNode_QGIS-server deployment in docker
Python
5
star
39

flask_user_map

A simple flask for creating user community maps
JavaScript
5
star
40

IGRAC-GGIS

HTML
4
star
41

ckanext-dalrrd-emc-dcpr

Electronic Metadata Catalog for South Africa's Department of Agriculture, Land Reform and Rural Development
Python
4
star
42

QGISReportsWorkshop

Workshop presented to the Swiss QGIS User group March 2022
Python
4
star
43

SAEOSS-Portal

The SAEOSS Portal has been proposed as a system of software components functioning together as the national central earth observation geospatial repository, with a view to metadata and open geospatial API standards compliance as well as user impact maximization
CSS
4
star
44

parcel_plugin

QML
3
star
45

docker-geonode

A docker project for geonode
Python
3
star
46

docker-osm-examples

And directory for examples of docker-osm usage
QML
2
star
47

trail-mapper-ios

Mobile app for mapping trails and trail conditions
Swift
2
star
48

docker-django-base

A base docker image for django projects.
Shell
2
star
49

RandomDEMGenerator

An experiment to create random DEMS
Python
2
star
50

IGRAC-Mobile

TypeScript
2
star
51

sg-diagram-downloader

A tool for QGIS that will download SG (South African Surveyor General) diagrams
Python
2
star
52

docker-tilestream

A docker project for tilestream
Shell
2
star
53

geodata-mart

Geoprocessing as a Service
JavaScript
2
star
54

IGRAC-WellAndMonitoringDatabase

A PostgreSQL schema implementing the groundwater interchange schema defined in GWML2
JavaScript
2
star
55

django-training

Training couse materials for django
HTML
2
star
56

feti

Further Education and Training Institute Website
PLpgSQL
2
star
57

miniSASS

miniSASS website for GroundTruth
JavaScript
2
star
58

docker-tegola-maputnik

A demonstrator project showing how to run tegola vector tile server and maputnik tile style editor in docker.
Shell
2
star
59

qgis_dataset_qa_workbench

A QGIS3 plugin for assisting in dataset Quality Assurance workflows
Python
2
star
60

watchkeeper

A security alerts platform for iMMAP
Python
1
star
61

QGISCheatSheet

Our handy guide for QGIS!
1
star
62

trail-mapper-django

A django app for the Kartoza trail mapper app
CSS
1
star
63

LEDET_BIMS

Limpopo Biodiversity Information Management System
PLpgSQL
1
star
64

timesheet-project

Python
1
star
65

least-cost-electrification-somalia

Global Electrification Platform for Global
HTML
1
star
66

node-red-flows

Example flows using node red
1
star
67

Woolpert

Repo for the Woolpert project
JavaScript
1
star
68

rir-dashboard

An open platform for risk informed response planning.
JavaScript
1
star
69

geoserver-deploy

Example deployment of geoserver and postgis using docker and fig
1
star
70

kobo-docker-builder

Build script compilation for Kobotoolbox
Shell
1
star
71

utilities

miscelleneous scripts
1
star
72

clean-cooking-platform

JavaScript
1
star
73

internship-program

Internship program repository containing all the course materials and assignment submissions
1
star
74

qgis-server-monitor

An iOS app to monitor if QGIS servers are online
Swift
1
star
75

GeoContextQGISPlugin

A QGIS Plugin for the GeoContext API
Python
1
star
76

kartoza-docker-wordpress

The wordpress site powering kartoza.com, in docker
Makefile
1
star
77

ingc_geonode_theme

INGC Geonode Theme
CSS
1
star
78

docker-metacat

A docker project to set up KNB Metacat and dependencies
Shell
1
star
79

qgis-chat-plugin

A QGIS plugin for chatting on Gitter
Python
1
star
80

docker-qgis-base

A base repo upon which docker-qgis-desktop and docker-qgis-server are built
1
star
81

osm-cartography

Our collaborative work to provide an awesome QGIS cartography for OSM
QML
1
star
82

etherpad

Docker project to provide ether pad - an online document collaboration tool
1
star
83

osm-africa

An Africa project for tilemill derived from https://github.com/mapbox/osm-bright
1
star
84

freshwaterbiodiversity.org

HTML
1
star
85

django-react-base

A boilerplate project for quickly setting up a Django backend with a React frontend
Python
1
star
86

tilemaker-workflows

Internal repo for working with global OSM tiles and tilemaker
Lua
1
star
87

jakarta-flood-maps

A web based flood mapping application for jakarta
Python
1
star
88

InWARDS-Dashboard-Desktop

An application written in Electron.js for visualising stream flow conditions.
Vue
1
star