package com.onthegomap.planetiler.examples; import com.onthegomap.planetiler.FeatureCollector; import com.onthegomap.planetiler.Planetiler; import com.onthegomap.planetiler.Profile; import com.onthegomap.planetiler.config.Arguments; import com.onthegomap.planetiler.reader.SourceFeature; import com.onthegomap.planetiler.reader.osm.OsmElement; import com.onthegomap.planetiler.reader.osm.OsmSourceFeature; import java.nio.file.Path; /** * Generates tiles with a raw copy of OSM data in a single "osm" layer at one zoom level, similar to * OSM QA Tiles. *

* Nodes are mapped to points and ways are mapped to polygons or linestrings, and multipolygon relations are mapped to * polygons. Each output feature contains all key/value tags from the input feature, plus these extra attributes: *

*

* To run this example: *

    *
  1. build the examples: {@code mvn clean package}
  2. *
  3. then run this example: * {@code java -cp target/*-fatjar.jar com.onthegomap.planetiler.examples.OsmQaTiles --area=monaco --download}
  4. *
  5. then run the demo tileserver: {@code tileserver-gl-light data/output.mbtiles}
  6. *
  7. and view the output at localhost:8080
  8. *
*/ public class OsmQaTiles implements Profile { public static void main(String[] args) throws Exception { run(Arguments.fromArgsOrConfigFile(args)); } static void run(Arguments inArgs) throws Exception { int zoom = inArgs.getInteger("zoom", "zoom level to generate tiles at", 12); var args = inArgs.orElse(Arguments.of( "minzoom", zoom, "maxzoom", zoom, "tile_warning_size_mb", 100 )); String area = args.getString("area", "geofabrik area to download", "monaco"); Planetiler.create(args) .setProfile(new OsmQaTiles()) .addOsmSource("osm", Path.of("data", "sources", area + ".osm.pbf"), "planet".equalsIgnoreCase(area) ? "aws:latest" : ("geofabrik:" + area) ) .overwriteOutput(Path.of("data", "qa.mbtiles")) .run(); } @Override public void processFeature(SourceFeature sourceFeature, FeatureCollector features) { if (!sourceFeature.tags().isEmpty() && sourceFeature instanceof OsmSourceFeature osmFeature) { var feature = sourceFeature.canBePolygon() ? features.polygon("osm") : sourceFeature.canBeLine() ? features.line("osm") : sourceFeature.isPoint() ? features.point("osm") : null; if (feature != null) { var element = osmFeature.originalElement(); feature .setMinPixelSize(0) .setPixelTolerance(0) .setBufferPixels(0); for (var entry : sourceFeature.tags().entrySet()) { feature.setAttr(entry.getKey(), entry.getValue()); } feature .setAttr("@id", sourceFeature.id()) .setAttr("@type", element instanceof OsmElement.Node ? "node" : element instanceof OsmElement.Way ? "way" : element instanceof OsmElement.Relation ? "relation" : null ); var info = element.info(); if (info != null) { feature .setAttr("@version", info.version() == 0 ? null : info.version()) .setAttr("@timestamp", info.timestamp() == 0L ? null : info.timestamp()) .setAttr("@changeset", info.changeset() == 0L ? null : info.changeset()) .setAttr("@uid", info.userId() == 0 ? null : info.userId()) .setAttr("@user", info.user() == null || info.user().isBlank() ? null : info.user()); } } } } @Override public String name() { return "osm qa"; } @Override public String attribution() { return """ © OpenStreetMap contributors """.trim(); } }