Skip to content

Latest commit

 

History

History
234 lines (186 loc) · 7.45 KB

INSTALL.md

File metadata and controls

234 lines (186 loc) · 7.45 KB

Installation

Requirements

  • Node.js 14+
  • PostGIS
  • GDAL including python-gdal
  • imposm3

Get sources

git clone https://github.com/FreemapSlovakia/freemap-mapnik.git

Installing prerequisites

  1. Get OpenStreetMap data (eg. from Geofabrik)
  2. Create a postgis database (see below for details)
  3. Import OpenStreetMap data (see below for details)
  4. Get digital elevation data and import it to database (optional; see below for details)
  5. Change directory to project directory
  6. Run npm i
  7. Create config/development.json5 where you can override settings from config/default.json5 for your local environment
  8. Run npm run watch
  9. Open preview.html in your browser

Building

To build sources for production run:

npm i
npm run build

Importing OSM data to PostGIS

In following commands replace <you> with your username.

Prepare database

  1. sudo su - postgres (skip this on MacOS)
  2. createdb <you>
  3. createuser <you>
  4. psql <you>
  5. CREATE EXTENSION postgis;
  6. CREATE EXTENSION postgis_topology;
  7. GRANT CREATE ON DATABASE <you> TO <you>;
  8. ALTER USER <you> WITH PASSWORD '<your_password>';
  9. GRANT ALL ON SCHEMA public TO <you>;

Password encryption

Downgrade password_encryption in PostgreSQL to md5, changing all the passwords and using the md5 authentication method:

  1. In ``/etc/postgresql/16/main/pg_hba.conf(your PostgreSQL version may vary), find the linehost all all 127.0.0.1/32 scram-sha-256` and replace the ending directive by md5: `host all all 127.0.0.1/32 md5`
  2. In /etc/postgresql/16/main/postgresql.conf (your PostgreSQL version may vary), find the line password_encryption = scram-sha-256 and replace the value by md5.
  3. Restart the postgresql service:
systemctl restart [email protected]
  1. Check that the password of the dedicated user was actually converted to using md5:
su - postgres
$ psql -d freemap
psql (16.1 (Debian 16.1-1.pgdg120+1))

freemap=# select rolpassword from pg_authid where rolname = 'freemap';
             rolpassword             
-------------------------------------
 md5e1cd775xjhdsfjkhdjdjfhj

You'll notice the heading md5 caracters of the encoded password. In case this 3 caracters are missing, please reset the dedicated user's password:

ALTER USER freemap WITH PASSWORD 'somepassword';

Import OpenStreetMap to database

Import initial.sql to PostgreSQL.

You must have imposm3 installed. For instructions how to build it see https://github.com/omniscale/imposm3.

To import the data use following command (with correct pbf filename):

imposm import -connection postgis://<you>:<your_password>@localhost/<you> -mapping mapping.yaml -read slovakia-latest.osm.pbf -write

Then deploy the import to production:

imposm import -connection postgis://<you>:<your_password>@localhost/<you> -mapping mapping.yaml -deployproduction

Import additional.sql to PostgreSQL.

Peak isolations

See instructions to compute and import peak isolations to prioritize peaks with higher isolation. Skip this step if you want to omit this functionality.

Prepare coastlines

From https://osmdata.openstreetmap.de/data/land-polygons.html get simplified-land-polygons-complete-3857 and land-polygons-split-3857 and unpack it to project directory.

Setup imposm and freemap-mapnik services

In order to run both imposm and freemap-mapnik services, you'll find these two ready made files in the etc/systemd folder.

  • Copy these two files in the relevant directory of your system to allow these services to run independently of any user login, place them into the /etc/systemd/system folder.

  • Each of these two files must be edited and customized according to the installation folder, the relevant username, the database name and the login/password database account

  • Tell the system some things have changed: sudo systemctl daemon-reload

  • Enable and start imposm:

    systemctl enable imposm3
    systemctl start imposm3
  • Enable freemap-mapnik:

    systemctl enable freemap-mapnik
    systemctl start freemap-mapnik

Later on in this documentation will you find mentions of two 'versions' of the freemap-mapnik service:

  • freemap-mapnik-prerender which is used to pre-render tiles from zoom 1 to zoom 14 (if a tile is missing or OSM data has been changed)
  • freemap-mapnik-ondemand which renders tiles when requested by the user (from zoom 15 to 19) and missing.

Building Imposm on MacOS

brew install golang leveldb geos

and then execute the commands here

Contours and shaded relief

If you don't want to use hillshading and contours then set mapFeatures.contours and mapFeatures.shading in your config file to false. Otherwise follow instructions in SHADING_AND_CONTOURS.md.

Setting up minutely diff applying

Follow these steps also after database reimport, which is required if you've updated mapping.yaml:

  1. Download europe-latest.osm.pbf from Geofabrik
  2. Stop imposm service
    systemctl stop imposm3
  3. update and compile freemap-mapnik
    git pull && npm run build
  4. Import:
    imposm import -connection postgis://freemap:freemap@localhost/freemap -mapping mapping.yaml -read europe-latest.osm.pbf -diff -write -cachedir ./cache -diffdir ./diff -overwritecache -limitto limit-europe.geojson -limittocachebuffer 10000 -optimize
  5. Delete pbf file
    rm europe-latest.osm.pbf extract.pbf
  6. Stop prerendering
    systemctl stop freemap-mapnik-prerender
  7. Deploy the import to production:
    imposm import -connection postgis://freemap:freemap@localhost/freemap -mapping mapping.yaml -deployproduction
  8. Import additional.sql to PostgreSQL
  9. Update ./diff/last.state.txt to reflect timestamp and sequence number of the imported map. See https://planet.openstreetmap.org/replication/minute/ for finding sequence number.
  10. Start imposm and wait to catch it up
    systemctl start imposm3
  11. Now you can optionally stop imposm service to prevent it from interrupting prerendering. You can start it later after pre-rendering has been finished. You can also start it somewhere during pre-rendering to catch-up and stop again, to apply some recent updates.
  12. Delete content of ./expires directory
  13. Edit ./config/prerender.json5 and change rerenderOlderThanMs to current time plus a minute or more
  14. Stop ondemand rendering
    systemctl stop freemap-mapnik-ondemand
  15. Delete cached highzoom tiles and indexes
    cd ./tiles
    rm -rf 15 16 17 18 19
    cd ..
    find ./tiles/14 -name '*.index' -delete
  16. Start ondemand rendering
    systemctl start freemap-mapnik-ondemand
  17. Start prerendering
    systemctl start freemap-mapnik-prerender

Nginx as front tier

server {
    ...

    location /pdf {
      proxy_pass http://localhost:4000/pdf;
    }

    location / {
      rewrite ^(.*)$ $1.png break;
      root    /home/freemap/freemap-mapnik/tiles/;
      error_page 404 = @fallback;
    }

    location @fallback {
      proxy_pass http://localhost:4000;
      error_page 404 /40x.html;
    }

    ...
}