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
@caspg
Copy link

caspg commented Mar 23, 2022

There is a typo in command for compiling the project ./mvnm -> ./mvnw

./mvnw clean package

@wipfli
Copy link
Author

wipfli commented Mar 23, 2022

Thanks!

@grinapo
Copy link

grinapo commented Aug 7, 2022

It seems now planetiler-basemap is exhcanged with planetiler-openmaptiles and same goes with basemap:

  • ./planetiler-openmaptiles/src/main/java/org/openmaptiles/Generate.java

And since it seems to be a submodule there are multiple hoops one have to jump through, since the submodule have to be forked, the new submodule have to be set, and only then can one modify Generate.java.

And similarly Transportation have moved over to:

  • ./planetiler-openmaptiles/src/main/java/org/openmaptiles/layers/Transportation.java

I guess regenerate is after:

  • cd planetiler-openmaptiles
    otherwise it fails.

Anyway, shouldn't the regenerate script called as

  • ./scripts/regenerate-openmaptiles.sh tracktype https://raw.githubusercontent.com/wipfli/openmaptiles/ ?
    (and possibly no need to patch Generate.java?)

Oh and better not call regenerate script anymore but manually `java -cp target/*-with-deps.jar org.openmaptiles.Generate -tag=tracktype -base-url="https://raw.githubusercontent.com/wiplfli/openmaptiles/"`` because if there was any error in the build then the generate code will be destroyed and cannot be recreated anymore (since regenerating it would require a clean build, I've been bitten by that). In fact it shall be copied to a safe place since any rebuild will clean it up.

@wipfli
Copy link
Author

wipfli commented Aug 7, 2022

Thanks for the update, @grinapo. Probably this is now horribly outdated. Do you think I should delete this gist or what is the way to go here?

@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