Code Monkey home page Code Monkey logo

planetiler-openmaptiles's Introduction

Planetiler OpenMapTiles Profile

This OpenMapTiles profile for Planetiler is based on OpenMapTiles.

How to run

Using pre-built docker image:

docker run -v "$(pwd)/data":/data openmaptiles/planetiler-openmaptiles:latest --force --download --area=monaco

Or to build from source, after installing Java 21+:

# Build the project (use mvnw.cmd on windows):
./mvnw clean package
# Then run:
java -jar target/*with-deps.jar --force --download --area=monaco

See Planetiler README.md for more description of the available options.

Differences from OpenMapTiles

  • Road name abbreviations are not implemented yet in the transportation_name layer
  • brunnel tag is excluded from transportation_name layer to avoid breaking apart long transportation_name lines, to revert this behavior set --transportation-name-brunnel=true
  • rank field on mountain_peak linestrings only has 3 levels (1: has wikipedia page and name, 2: has name, 3: no name or wikipedia page or name)
  • Some line and polygon tolerances are different, can be tweaked with --simplify-tolerance parameter
  • For bigger bays whose label points show above Z9, centerline is used for Z9+

Customizing

If you want to exclude layers or only include certain layers, then run the project with --exclude-layers=poi,housenumber,... or --only-layers=water,transportation,... command-line arguments.

If you want to customize existing layers in OpenMapTiles, then fork this repo, find the appropriate class from the layers package, and make a change to where it processes output features.

Example adding an attribute to a built-in layer

For example to copy over the name attribute from OpenStreetMap elements to the building layer, modify Building.java:

@@ -166,6 +166,7 @@ public class Building implements
         .setAttrWithMinzoom(Fields.RENDER_MIN_HEIGHT, renderMinHeight, 14)
         .setAttrWithMinzoom(Fields.COLOUR, color, 14)
         .setAttrWithMinzoom(Fields.HIDE_3D, hide3d, 14)
+        .setAttrWithMinzoom("name", element.source().getTag("name"), 14)
         .setSortKey(renderHeight);
       if (mergeZ13Buildings) {
         feature

If you want to generate a mbtiles file with OpenMapTiles base layers plus some extra ones then fork this repo and:

  1. Create a new class that implements the Layer interface in the addons package and make the public String name() method return the ID of the new layer.
  2. Make the new class implement interfaces from OpenMapTilesProfile to register handlers for elements from input sources. For example implement OpenMapTilesProfile.OsmAllProcessor to handle every OSM element from processAllOsm method. See the built-in layers for examples.
  3. Create a new instance of that class from the ExtraLayers class.
Custom layer example

This layer would add a power layer to OpenMapTiles output with power lines:

package org.openmaptiles.addons;

import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.reader.SourceFeature;
import org.openmaptiles.Layer;
import org.openmaptiles.OpenMapTilesProfile;

public class Power implements Layer, OpenMapTilesProfile.OsmAllProcessor {

  private static final String LAYER_NAME = "power";

  @Override
  public String name() {
    return LAYER_NAME;
  }

  @Override
  public void processAllOsm(SourceFeature feature, FeatureCollector features) {
    if (feature.canBeLine() && feature.hasTag("power", "line")) {
      features.line("power")
          .setBufferPixels(4)
          .setMinZoom(6)
          .setAttr("class", "line");
    }
  }
}

If you think your custom layer or change to a built-in layer might be useful to others, consider opening a pull request to contribute it back to this repo. Any change that diverges from what is produced by https://github.com/openmaptiles/openmaptiles should be disabled by default, and enabled through a command-line argument that users can opt-into. For example, see how the building layer exposes a building_merge_z13 command-line argument to disable merging nearby buildings at z13.

Code Layout

Generate.java generates code in the generated package from an OpenMapTiles tag in GitHub:

  • OpenMapTilesSchema contains an interface for each layer with constants for the name, attributes, and allowed values for each tag in that layer
  • Tables contains a record for each table that OpenMapTiles imposm3 configuration generates (along with the tag-filtering expression) so layers can listen on instances of those records instead of doing the tag filtering and parsing themselves

The layers package contains a port of the SQL logic to generate each layer from OpenMapTiles. Layers define how source features (or parsed imposm3 table rows) map to vector tile features, and logic for post-processing tile geometries.

OpenMapTilesProfile dispatches source features to layer handlers and merges the results.

OpenMapTilesMain is the main driver that registers source data and output location.

Regenerating Code

To run Generate.java, use scripts/regenerate-openmaptiles.sh script with the OpenMapTiles release tag:

./scripts/regenerate-openmaptiles.sh v3.15

Then follow the instructions it prints for reformatting generated code.

If you want to regenerate from a different repository than the default openmaptiles, you can specify the url like this:

./scripts/regenerate-openmaptiles.sh v3.15 https://raw.githubusercontent.com/openmaptiles/openmaptiles/

License

All code in this repository is under the BSD license and the cartography decisions encoded in the schema and SQL are licensed under CC-BY.

Products or services using maps derived from OpenMapTiles schema need to visibly credit "OpenMapTiles.org" or reference "OpenMapTiles" with a link to https://openmaptiles.org/. Exceptions to attribution requirement can be granted on request.

For a browsable electronic map based on OpenMapTiles and OpenStreetMap data, the credit should appear in the corner of the map. For example:

© OpenMapTiles © OpenStreetMap contributors

For printed and static maps a similar attribution should be made in a textual description near the image, in the same fashion as if you cite a photograph.

planetiler-openmaptiles's People

Contributors

bbilger avatar boldtrn avatar cboone avatar dependabot[bot] avatar frodrigo avatar lazaa32 avatar msbarry avatar phanecak-maptiler avatar zelonewolf avatar zstadler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

planetiler-openmaptiles's Issues

Document how to add features to a built-in layer

The customizing section of the README.md has an example for adding an attribute to a built-in layer.

Please add an example of adding features to a built-in layer. For example, how to add historic=memorial OSM features to the poi layer in addition to the historic=monument features it already includes.

Error on way 1155021504

Error on a single element when running over the planet:

0:19:36 ERR [osm_pass2:process] - Error processing OSM Way 1155021504
java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because the return value of "java.util.Map.get(Object)" is null
        at org.openmaptiles.layers.Transportation.getMinzoom(Transportation.java:412)
        at org.openmaptiles.layers.Transportation.process(Transportation.java:350)
        at org.openmaptiles.OpenMapTilesProfile.lambda$new$6(OpenMapTilesProfile.java:138)
        at com.onthegomap.planetiler.ForwardingProfile.processFeature(ForwardingProfile.java:116)
        at com.onthegomap.planetiler.reader.osm.OsmReader.render(OsmReader.java:467)
        at com.onthegomap.planetiler.reader.osm.OsmReader.lambda$pass2$6(OsmReader.java:359)
        at com.onthegomap.planetiler.worker.WorkerPipeline$Builder.lambda$addWorker$0(WorkerPipeline.java:252)
        at com.onthegomap.planetiler.worker.Worker.lambda$new$0(Worker.java:41)
        at com.onthegomap.planetiler.worker.Worker.lambda$new$1(Worker.java:68)
        at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)

Element IDs do not match those generated by OpenMapTiles (SQL)

OpenMapTiles (SQL) is generating tiles where features from OSM has an ID set based on original running through a formula(s) so at the end user is able to determine based on ID whether the source feature is node, way or relation (see openmaptiles/openmaptiles#1587 and for example https://github.com/openmaptiles/openmaptiles/blob/master/layers/poi/poi.sql#L51). planetiler-openmaptiles is using just plain OSM ID hence there is no way to determine type of the origin OSM feature.

Fix is a work in progress with two options:

  • Same as in OpenMapTiles (e.g. roughly *10): onthegomap/planetiler#826
    • This PR should fix this issue.
  • Differently than in OpenMapTiles (e.g. roughly *3): onthegomap/planetiler#827
    • This PR will make planetiler-openmaptiles (still) behave differently than OpenMapTiles.

See also:

Missing Dockerfile

The Dockerfile to rebuild the image is missing in this repository.

It will help rebuilding a custom fork or for dev setup.

Lake IDs at low zooms

As part of onthegomap/planetiler#227, I added lake OSM IDs but only for lakes from OSM data (z6 and above). Merging with natural earth data is a bit tricky because we process all of natural earth first, then all of openstreetmap.

A few options for how to get OSM IDs on low-zoom lakes:

  • store all of the natural earth lakes features in-memory in water profile, add additional info to them while processing OSM elements, then write them out after OSM is finished (like we do with the boundary layer)
  • Use OSM lakes at lower zoom-levels instead of natural earth. We could add VW simplification with options like effective/weighted area to planetiler to produce a similar visual effect that natural earth gets with mapshaper
  • Extract OSM IDs as part of wikidata pre-processing, then go from wikidata ID to OSM ID when processing natural earth elements

Originally posted by @msbarry in onthegomap/planetiler#227 (comment)
Transferred from onthegomap/planetiler#231

Configurable concurrency limit

Currently, the limit on simultaneous concurrencies (route_N attributes in the transportation_name layer), is six. However, we've identified cases as large as eight in ZeLonewolf/openstreetmap-americana#894.

Instead, planetiler-openmaptiles should have a configurable limit on route concurrencies, so a style author can determine the longest shield snake length that makes cartographic sense to render.

Z4 boundaries from OSM should not include adm0_l/admin0_r

Describe the bug
adm0_{l,r} tags show up on regular boundaries at z5 but the demo shows them at z4 on maritime boundaries derived from OSM data and not natural earth.

To Reproduce
Steps to reproduce the behavior:

  1. Generate a world map with basemap profile including Z4
  2. Inspect the generated tiles

Expected behavior
Boundary lines have adm0_{l,r} tags starting zt z5, not z4

Screenshots
image

Environment (please complete the following information):
n/a

Additional context
n/a

Transferred from onthegomap/planetiler#11

Disable line-merging for transportation linestrings with oneway tag

This planetiler profile currently merges transportation linestrings with the same tags, but this causes issues because it might reverse a linestring but not the oneway tag. The medium-term fix is to improve the feature merge API in planetiler to be more flexible so you can specify here that it needs to flip the oneway tag when a linestring is reversed, but as a short term workaround we should disable line merging for features that have a oneway tag on them.

onthegomap/planetiler#296

Specify zoom levels

Thank you for this great tool.

Is there a way to specify (via command line or in code), that I only want to generate tiles for a specific zoom range? I.e. if I want to start at z4, and only generate up to z12? I don't see this as an option anywhere? Perhaps I am misunderstanding or missing something in the docs?

hide3d flag is not set to "outline" buildings

I'm not entirely sure how it's supposed to work..

  • Is the outline relation automatically set by OSM backend? I don't have any evidence to believe that
  • Does this profile assume that outline relation is always defined? Almost never the case
  • Logic is just not implemented yet to automatically discover outline relations? See my comment

I did double-check multiple buildings that consist of parts and are missing hide3d flag (I've never seen the flag on any of the buildings in tens of hours of working/exploring output) - requirements are met: building parts are all inside the building (or share outer-wall nodes) and the entire building is covered by parts. So I can only assume that current implementation requires manually set relations in OMS to apply hide3d flag.

// Building.java:process
Boolean hide3d = null;
var relations = element.source().relationInfo(BuildingRelationInfo.class);
for (var relation : relations) {
  if ("outline".equals(relation.role())) {
    hide3d = true;
    break;
  }
}

OMT v3.13.1

Update this repo to OMT v3.13.1 and make a release.

Move regenerate-openmaptiles script from planetiler repo

We should copy this script over so you can run it in this repo to update the code that gets generated from openmaptiles yaml files:

https://github.com/onthegomap/planetiler/blob/232834e73523f018e2659e9ee3c1575826908686/scripts/regenerate-openmaptiles.sh#L1-L20

There's probably also a github action you want to copy to make sure that regenerate works fine on each commit:

https://github.com/onthegomap/planetiler/blob/232834e73523f018e2659e9ee3c1575826908686/.github/workflows/maven.yml#L63-L78

Support POV admin0 NE boundaries

Natural Earth provides "POV" country boundary files. A "POV" boundary includes national boundaries as recognized by various countries. For example, a mapmaker building a map for a Chinese audience would want to display different boundaries than that for an Indian consumer.

https://www.naturalearthdata.com/downloads/10m-cultural-vectors/

I propose that planetiler have a command-line option which can select from one of the available POV files as a drop-in replacement for the standard 10m country boundary file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.