Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move tileset version into Basemap.java [#59] #178

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

24 changes: 10 additions & 14 deletions tiles/src/main/java/com/protomaps/basemap/Basemap.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
import com.protomaps.basemap.layers.Transit;
import com.protomaps.basemap.layers.Water;
import java.nio.file.Path;
import org.locationtech.jts.geom.Envelope;


public class Basemap extends ForwardingProfile {

public Basemap(Envelope earthWaterBounds, NaturalEarthDb naturalEarthDb, QrankDb qrankDb) {
public Basemap(NaturalEarthDb naturalEarthDb, QrankDb qrankDb) {

var admin = new Boundaries();
registerHandler(admin);
Expand Down Expand Up @@ -69,29 +68,33 @@ public Basemap(Envelope earthWaterBounds, NaturalEarthDb naturalEarthDb, QrankDb
registerHandler(transit);
registerSourceHandler("osm", transit);

var water = new Water(earthWaterBounds);
var water = new Water();
registerHandler(water);
registerSourceHandler("osm", water);
registerSourceHandler("osm_water", water::processPreparedOsm);
registerSourceHandler("ne", water::processNe);

var earth = new Earth(earthWaterBounds);
var earth = new Earth();
registerHandler(earth);
registerSourceHandler("osm_land", earth::processPreparedOsm);
registerSourceHandler("ne", earth::processNe);

}

@Override
public String name() {
return "Basemap";
return "Protomaps Basemap";
}

@Override
public String description() {
return "Basemap layers derived from OpenStreetMap and Natural Earth";
}

@Override
public String version() {
return "3.0.0-pre1";
}

@Override
public boolean isOverlay() {
return false;
Expand All @@ -114,19 +117,12 @@ static void run(Arguments args) throws Exception {
Path dataDir = Path.of("data");
Path sourcesDir = dataDir.resolve("sources");

// Limit the output of prepared OSM earth/water to a bounding box.
// Used in combination with the `--bounds` argument to generate a complete planet based on NE at low zooms,
// and a complete high-zoom tileset without having to tile earth/water outside the bbox.
Envelope earthWaterBounds = args.bounds("osm-earth-water-bounds", "spatial bbox of osm earth+water");

Path nePath = sourcesDir.resolve("natural_earth_vector.sqlite.zip");
String neUrl = "https://naciscdn.org/naturalearth/packages/natural_earth_vector.sqlite.zip";

String area = args.getString("area", "geofabrik area to download", "monaco");

var planetiler = Planetiler.create(args)
// (nvkelso 20230817) Order of operations matters here so all NE places can be added to RTree indexes
// before OSM uses them for data joins
.addNaturalEarthSource("ne", nePath, neUrl)
.addOsmSource("osm", Path.of("data", "sources", area + ".osm.pbf"), "geofabrik:" + area)
.addShapefileSource("osm_water", sourcesDir.resolve("water-polygons-split-3857.zip"),
Expand All @@ -141,7 +137,7 @@ static void run(Arguments args) throws Exception {
var naturalEarthDb = NaturalEarthDb.fromSqlite(nePath, tmpDir);
var qrankDb = QrankDb.fromCsv(sourcesDir.resolve("qrank.csv.gz"));

planetiler.setProfile(new Basemap(earthWaterBounds, naturalEarthDb, qrankDb)).setOutput(Path.of(area + ".pmtiles"))
planetiler.setProfile(new Basemap(naturalEarthDb, qrankDb)).setOutput(Path.of(area + ".pmtiles"))
.run();
}
}

This file was deleted.

20 changes: 4 additions & 16 deletions tiles/src/main/java/com/protomaps/basemap/layers/Earth.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
package com.protomaps.basemap.layers;

import static com.protomaps.basemap.feature.SpatialFilter.withinBounds;

import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.FeatureMerge;
import com.onthegomap.planetiler.ForwardingProfile;
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.geo.GeometryException;
import com.onthegomap.planetiler.reader.SourceFeature;
import java.util.List;
import org.locationtech.jts.geom.Envelope;

public class Earth implements ForwardingProfile.FeaturePostProcessor {

private final Envelope bounds;

public Earth(Envelope bounds) {
this.bounds = bounds;
}

@Override
public String name() {
return "earth";
}

public void processPreparedOsm(SourceFeature sf, FeatureCollector features) {
if (withinBounds(this.bounds, sf)) {
features.polygon(this.name())
.setAttr("pmap:kind", "earth")
.setZoomRange(6, 15).setBufferPixels(8);
}
public void processPreparedOsm(SourceFeature ignoredSf, FeatureCollector features) {
features.polygon(this.name())
.setAttr("pmap:kind", "earth")
.setZoomRange(6, 15).setBufferPixels(8);
}

public void processNe(SourceFeature sf, FeatureCollector features) {
Expand Down
19 changes: 4 additions & 15 deletions tiles/src/main/java/com/protomaps/basemap/layers/Water.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.protomaps.basemap.layers;

import static com.protomaps.basemap.feature.SpatialFilter.withinBounds;

import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.FeatureMerge;
import com.onthegomap.planetiler.ForwardingProfile;
Expand All @@ -11,27 +9,18 @@
import com.onthegomap.planetiler.util.Parse;
import com.protomaps.basemap.postprocess.Area;
import java.util.List;
import org.locationtech.jts.geom.Envelope;

public class Water implements ForwardingProfile.FeatureProcessor, ForwardingProfile.FeaturePostProcessor {

private final Envelope bounds;

public Water(Envelope bounds) {
this.bounds = bounds;
}

@Override
public String name() {
return "water";
}

public void processPreparedOsm(SourceFeature sf, FeatureCollector features) {
if (withinBounds(this.bounds, sf)) {
features.polygon(this.name())
.setAttr("pmap:kind", "water")
.setZoomRange(6, 15).setBufferPixels(8);
}
public void processPreparedOsm(SourceFeature ignoredSf, FeatureCollector features) {
features.polygon(this.name())
.setAttr("pmap:kind", "water")
.setZoomRange(6, 15).setBufferPixels(8);
}

public void processNe(SourceFeature sf, FeatureCollector features) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract class LayerTest {
List.of(new NaturalEarthDb.NeAdmin1StateProvince("California", "US-CA", "Q2", 5.0, 8.0)),
List.of(new NaturalEarthDb.NePopulatedPlace("San Francisco", "Q3", 9.0, 2))
);
final Basemap profile = new Basemap(null, naturalEarthDb, null);
final Basemap profile = new Basemap(naturalEarthDb, null);

static void assertFeatures(int zoom, List<Map<String, Object>> expected, Iterable<FeatureCollector.Feature> actual) {
var expectedList = expected.stream().toList();
Expand Down
Loading