tilezen / vector-datasource

Tilezen vector tile service - OpenStreetMap data in several formats
https://www.nextzen.org/
Other
509 stars 120 forks source link

How to add another OSM file via osm2pgsql? #1536

Closed guyisra closed 6 years ago

guyisra commented 6 years ago
2018-06-17 16:39:00.371 IDT [2788] ERROR:  column "mz_label_placement" does not exist at character 2107

and in tileserver:

    raise DataFetchException(async_exceptions)
DataFetchException: column "mz_label_placement" does not exist
LINE 102:     mz_label_placement,
              ^
, column "mz_label_placement" does not exist
LINE 64:     mz_label_placement,
             ^
, column "mz_poi_min_zoom" does not exist
LINE 60:       WHEN mz_poi_min_zoom IS NOT NULL AND
                    ^
^C%

The osm files attempted are https://download.bbbike.org/osm/bbbike/NewYork/NewYork.osm.pbf and and http://download.geofabrik.de/europe/andorra-latest.osm.pbf

Loading each separately to a clean db works

Is there a different way to load new osm data to the db ?

ImreSamu commented 6 years ago

The osm files attempted are https://download.bbbike.org/osm/bbbike/NewYork/NewYork.osm.pbf and and http://download.geofabrik.de/europe/andorra-latest.osm.pbf

my best workaround is merging all osm input files into one.

but be sure :

for example - merging same geofabrik(180601) versions should work:

guyisra commented 6 years ago

Thanks Once this merged osm is in the DB, how would you update the db with new new information on a region?

zerebubuth commented 6 years ago

New data can be loaded into an existing Tilezen database using osm2pgsql's --append mode. Because the errors you're seeing are about missing column names, it looks like osm2pgsql was run in its default --create mode, which undid some of the schema changes from running ./perform-sql-updates.sh (and probably dropped any data that used to be in those tables anyway).

Append mode can be used to load additional data, although this is intended to be used with an osmChange file as input rather than a planet extract. One can turn a .osm.pbf into an osmChange file using osmium-tool although it might be quite slow for large files:

./osmium cat -f osc.gz -o output.osc.gz input.osm.pbf

It's also worth noting that append mode can be considerably slower than create mode, as osm2pgsql can't make use of certain optimisations when it knows it's loading into an empty table (e.g: COPY FROM).

There are a few extra things which need to be run when finishing off an "append". First, we keep a table of roads which need an extra update step to take account of relations they're part of, so one needs to run:

BEGIN;

UPDATE planet_osm_line
  SET mz_road_level = NULL
  WHERE osm_id IN (SELECT DISTINCT osm_id FROM mz_pending_path_major_route);

TRUNCATE mz_pending_path_major_route;

COMMIT;

We run this after osm2pgsql as part of our minutely update script (called :post_import in that script). Note that setting mz_road_level to null just forces the trigger to recalculate it post-update, now that any relations have been written or changed.

Having said all of that, just because one can use append mode doesn't mean that it's the most appropriate way in all circumstances. As noted, it can be much slower than a from-scratch load. My recommendations:

Hope that helps!