NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I noticed that the recommended command to import data into the postgresql database from the tutorial here

https://switch2osm.org/manually-building-a-tile-server-16-04-2-lts/

is

osm2pgsql -d gis --create --slim -G --hstore --tag-transform-script ~/src/openstreetmap-carto/openstreetmap-carto.lua -C 2500 --number-processes 1 -S ~/src/openstreetmap-carto/openstreetmap-carto.style ~/data/azerbaijan-latest.osm.pbf

which lists the openstreetmap-carto style file. The recommended import command for OSM-Bright from

https://github.com/mapbox/osm-bright

is

osm2pgsql -c -G -U postgres_user -d postgis_database data.osm.pbf

My question is do I need to re-import the raw OSM data into the postgresql database everytime I want to change map styles and specify it during data import? The first tutorial specifies a style in the import command while the OSM-Bright tutorial does not. Thanks for any help.

asked 13 Sep '18, 22:25

coderunner's gravatar image

coderunner
416610
accept rate: 0%


Short answer: Yes. There is no need to reimport data.

A style file for osm2pgsql specifies aspects of how osm2pgsql converts OSM data into PostgreSQL tables, how much data is transferred from OSM xml into Postgres database. For example if a style does not display some kind of objects (powerlines, sidewalks etc) there is no much sense in keeping them in the rendering database. By constructing custom style you can filter what objects to include. More on this can be found here: https://wiki.openstreetmap.org/wiki/Osm2pgsql#Import_style

Now to compatibility of openstreetmap-carto.style for OSM-Bright. Though default style that comes with osm2pgsql imports more data comparing to openstreetmap-carto (you can take diff of these two styles to see what objects are filtered) OSM-Bright does not use these data. So you can safely use the OSM-Bright style on the same database you made for openstreetmap-carto style. You can look at layers that are used by OSM-bright in this file https://github.com/mapbox/osm-bright/blob/master/osm-bright/osm-bright.osm2pgsql.mml - look for SQL statements. This is how data is queried from Postgres to Mapnik for rendering.

permanent link

answered 18 Sep '18, 09:44

getmaps_io's gravatar image

getmaps_io
512
accept rate: 100%

1

Makes sense, thank you for the explanation of what's going on under the hood. That was very helpful.

(18 Sep '18, 16:30) coderunner

Probably yes. Rendering database is a special purpose database derivative and this can be very different for different styles.

One can make some mappings, but it needs some knowledge about SQL.

Quite simple solution (if you have enough of disc space) is to have more databases and just switch them - this is my rough script for this purpose (gis is default database, gis2 is the second one):

#!/bin/bash
sudo service postgresql restart
sudo -u postgres -H -- psql -c "alter database gis rename to temp;"
sudo -u postgres -H -- psql -c "alter database gis2 rename to gis;"
sudo -u postgres -H -- psql -c "alter database temp rename to gis2;"
permanent link

answered 13 Sep '18, 22:43

kocio's gravatar image

kocio
2.1k12341
accept rate: 20%

edited 14 Sep '18, 03:29

That is a good idea. Thank you.

(18 Sep '18, 16:30) coderunner

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×196
×165
×65
×24

question asked: 13 Sep '18, 22:25

question was seen: 5,316 times

last updated: 18 Sep '18, 16:30

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum