Skip to content

Instantly share code, notes, and snippets.

@wipfli
Last active August 9, 2022 17:58
Show Gist options
  • Save wipfli/02ba9081b26c3a0cfae054e5c5402fe7 to your computer and use it in GitHub Desktop.
Save wipfli/02ba9081b26c3a0cfae054e5c5402fe7 to your computer and use it in GitHub Desktop.

Adding tracktype to OpenMapTiles with planetiler

OpenMapTiles v3.14 does not include the tracktype tag. This gist shows how to add it with planetiler.

Step 1: OpenMapTiles

Fork OpenMapTiles, create a tracktype branch, add the following lines (see https://github.com/wipfli/openmaptiles/commit/b6f74e70e66a0007a21b94e0eea5c3505f91f7f6):

To layers/transportation/mapping.yaml:

 expressway_field: &expressway
   key: expressway
   name: expressway
   type: bool
+tracktype_field: &tracktype
+  key: tracktype
+  name: tracktype
+  type: string
...
     - *expressway
+    - *tracktype

To layers/transportation/transportation.yaml:

     surface:
       description: |
           Values of [`surface`](https://wiki.openstreetmap.org/wiki/Key:surface) tag devided into 2 groups `paved` (paved, asphalt, cobblestone, concrete, concrete:lanes, concrete:plates, metal, paving_stones, sett, unhewn_cobblestone, wood) and `unpaved` (unpaved, compacted, dirt, earth, fine_gravel, grass, grass_paver, gravel, gravel_turf, ground, ice, mud, pebblestone, salt, sand, snow, woodchips).
       values:
       - paved
       - unpaved
+    tracktype:
+      description: |
+          Original value of the [`tracktype`](http://wiki.openstreetmap.org/wiki/Key:tracktype) tag.

Step 2: Planetiler

Fork planetiler.

Point the automatic java code generation to your OpenMapTiles fork (see https://github.com/wipfli/planetiler/commit/f720f60a9a16f457a54cbcf17253dca5563db4de).

Edit in planetiler-basemap/src/main/java/com/onthegomap/planetiler/basemap/Generate.java:

-    String base = "https://raw.githubusercontent.com/openmaptiles/openmaptiles/" + tag + "/";
+    String base = "https://raw.githubusercontent.com/wipfli/openmaptiles/tracktype/";

Regenerate the OpenMapTiles java code from your updated OpenMapTiles yaml files:

scripts/regenerate-openmaptiles.sh

Add tracktype to planetiler-basemap/src/main/java/com/onthegomap/planetiler/basemap/layers/Transportation.java:

         .setAttrWithMinzoom(Fields.ONEWAY, nullIfInt(element.isOneway(), 0), 12)
         .setAttrWithMinzoom(Fields.SURFACE, surface(element.surface()), 12)
+        .setAttrWithMinzoom(Fields.TRACKTYPE, nullIfEmpty(element.tracktype()), 12)
         .setMinPixelSize(0) // merge during post-processing, then limit by size

Compile planetier:

./mvnw clean package

Run planetiler:

java -jar planetiler-dist/target/*with-deps.jar --force=true --area=switzerland

Inspect tiles:

sudo docker run --rm -it -v "$(pwd)/data":/data -p 8080:8080 maptiler/tileserver-gl -p 8080
@grinapo
Copy link

grinapo commented Aug 8, 2022

Thanks for the update, @grinapo. Probably this is now horribly outdated.

No, it is not. Only require small updates, I tried to list them all.

(For example it was not clear first that I need to clone openmaptiles since the update mechnaism require a git url [I dislike git and microsoft® github ;))], but planetiler can be used simply locally. I haven't checked whether Generate.java actually needs to be patched now. But I am now almost at the point where my output works! ;-))

Do you think I should delete this gist or what is the way to go here?

Definietely not! This is a great short summary how to do it, and it works (with the little adjustments here and there). I have found no similarly simple and well-formed guide in the topic, so this gist is pure gold, despite the tooth marks. ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment