This is a guide to the source code - useful if you'd like to contribute to the Export Tool, deploy the project on your own server, or re-use parts of the project.
api/ is a Django web application that manages creating, viewing and searching exports, storing feature selections, scheduling jobs, and user accounts via openstreetmap.org OAuth.
ui/ is a React + ES6 frontend that communicates with the Django API. It handles localization of the user interface, the OpenLayers-based map UI, and the Tag Tree feature selection wizard. (For historical reasons, it also includes some Django views to facilitate logging in with OSM credentials.)
- Python 3.6 or later,
virtualenv,pip - PostgreSQL 10+ and PostGIS
- Recommend Postgres.app which includes PostGIS.
- GDAL/OGR
- Recommend at least version 2.4 - newer versions available in
ubuntugisPPAs or Homebrew on Mac
- Recommend at least version 2.4 - newer versions available in
- RabbitMQ, a message queue
- Node.js and Yarn
The Export Tool queries an instance of the Overpass API for source data. Overpass:
- can efficiently perform spatial queries over large quantities of OSM data, including members of ways and relations.
- has built-in facilities to ingest minute diffs from OpenStreetMap.org.
- can create lossless PBF-format exports, which are necessary for some file formats such as OSMand and Garmin .IMG mobile device maps.
Instructions on installing Overpass are available at https://github.com/drolbr/Overpass-API . Alternatively, Overpass can be run via Docker - see ops/docker-overpass-api.
- The export tool is configured with an Overpass URL via the environment variable
OVERPASS_API_URL. This can be a public Overpass instance, a remote instance you manage yourself, or a local instance on your own computer. Public instances may have strict rate limits, so please use them lightly. - To set up a local Overpass instance, start with a .pbf file. This can be the full planet .pbf from http://planet.openstreetmap.org or a region, e.g. pbfs available from http://download.geofabrik.de/ .
- Optionally, configure Overpass to update itself minutely.
git clone https://github.com/hotosm/osm-export-tool.git
cd osm-export-tool
virtualenv venv # creates a new environment in venv/
source venv/bin/activate # activate the virtualenv
pip install -r requirements-dev.txt- PostgreSQL should be running and listening on the default port, 5432, with the shell user having administrative permissions.
- RabbitMQ should be running and listening on the default port, 5672.
Create and populate a PostgreSQL database named exports:
createdb exports
psql exports -c "create extension postgis;"
psql exports -c "create extension hstore;"
python manage.py migrate
cd ui/
yarn install
yarn run dist # for production
yarn start # will watch for changes and re-compile as necessaryDEBUG=True python manage.py runserver
# in a different shell
DEBUG=True DJANGO_SETTINGS_MODULE=core.settings.project dramatiq tasks.task_runners -p 1direnv is a useful tool for managing environment variables using a .env file.
You should now be able to navigate to http://localhost:8000 and log in via OSM. With DJANGO_ENV set to development, emails will not be sent, but the email body will appear in your console from runserver. Navigate to this link to verify your account. Creating an export will use the public Overpass API. Successful job creations will write the exports to the filesystem to the export_downloads directory, a sibling of the osm-export-tool2 checkout - since the NGINX file server is not running in development, download links won't be valid.
See core/settings/project.py for environment variables to configure other optional runtime dependencies.
Creating .IMG files require the mkgmap and splitter tools.
http://www.mkgmap.org.uk/download/mkgmap.html
http://www.mkgmap.org.uk/download/splitter.html
For details and download links to the OSMAnd Map Creator utilities, see http://wiki.openstreetmap.org/wiki/OsmAndMapCreator
Most of these environment variables have reasonable default settings.
-
EXPORT_STAGING_ROOTpath to a directory for staging export jobs -
EXPORT_DOWNLOAD_ROOT'path to a directory for storing export downloads -
EXPORT_MEDIA_ROOTmap this url in your webserver toEXPORT_DOWNLOAD_ROOTto serve the exported files -
OSMAND_MAP_CREATOR_DIRpath to the directory where OsmAndMapCreator is installed -
GARMIN_CONFIG,GARMIN_MKGMAPabsolute paths to garmin JARs -
OVERPASS_API_URLurl of Overpass api endpoint -
RAW_DATA_API_URLurl of Raw data api endpoint -
DATABASE_URLDatabase URL. Defaults topostgres:///exports -
DEBUGWhether to enable debug mode. Defaults toFalse(production). -
DJANGO_ENVDjango environment. Set todevelopmentto enable development tools and email logging to the console. -
EMAIL_HOST_USERSMTP username. -
EMAIL_HOST_PASSWORDSMTP password. -
EMAIL_USE_TLSWhether to use TLS when sending mail. Optional. -
HOSTNAMEPublicly-addressable hostname. Defaults toexport.hotosm.org -
USE_X_FORWARDED_HOST- Whether Django is running behind a proxy. Defaults toFalse
(This section is TBD, as we're currently figuring out workflows for FormatJS JSON strings used by react-intl.)
To work with Transifex, you need to create ~/.transifexrc, and modify its access privileges:
chmod 600 ~/.transifexrc
Example .transifexrc file:
[https://www.transifex.com]
hostname = https://www.transifex.com
password = my_super_password
token =
username = my_transifex_usernameTo update source language (English) for Django templates run:
python manage.py makemessages -l enTo update the source language for JavaScript files run:
python manage.py makemessages -d djangojs -l enthen, push the new source files to the Transifex service, it will overwrite the current source files
tx push -sWhen adding a new language, its resource file does not exist in the project, but it's ok as it will be automatically created when pulling new translations from the service. To add a local mapping:
tx set -r osm-export-tool2.master -l hr locales/hr/LC_MESSAGES/django.poor for JavaScript files:
tx set -r osm-export-tool2.djangojs -l hr locales/hr/LC_MESSAGES/djangojs.poOnce there are some translation updates, pull the latest changes for mapped resources.
For a specific language(s):
tx pull -l fr,hrFor all languages:
tx pullFinally, compile language files:
python manage.py compilemessages
To fetch updated translations for the JavaScript front-end, run:
cd ui/
yarn run tx:pullTo push updated strings to Transifex, run:
cd ui/
# build the app (to extract new strings)
yarn run pack
yarn run tx:pushIf / when UI translations pass the 5% complete threshold (defined in ui/.tx/config as minimum_perc), new JSON files will appear in ui/app/i18n/locales. To enable these translations for use, add react-intl locale data to ui/app/app.js (for date/number formatting) and add options to ui/app/components/LocaleSelector.js.