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

add daylight landcover to tileset [#154] #228

Merged
merged 9 commits into from
Apr 6, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Tiles v3.5.0
------
- Add Daylight Landcover from zooms 0-7. [#154]

Tiles v3.4.1
------
- Improve boundaries generalization [#200]
Expand Down
11 changes: 9 additions & 2 deletions tiles/src/main/java/com/protomaps/basemap/Basemap.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.protomaps.basemap.layers.Boundaries;
import com.protomaps.basemap.layers.Buildings;
import com.protomaps.basemap.layers.Earth;
import com.protomaps.basemap.layers.Landcover;
import com.protomaps.basemap.layers.Landuse;
import com.protomaps.basemap.layers.Natural;
import com.protomaps.basemap.layers.PhysicalLine;
Expand Down Expand Up @@ -37,6 +38,10 @@ public Basemap(NaturalEarthDb naturalEarthDb, QrankDb qrankDb) {
registerHandler(landuse);
registerSourceHandler("osm", landuse);

var landcover = new Landcover();
registerHandler(landcover);
registerSourceHandler("landcover", landcover::processLandcover);

var natural = new Natural();
registerHandler(natural);
registerSourceHandler("osm", natural);
Expand Down Expand Up @@ -91,7 +96,7 @@ public String description() {

@Override
public String version() {
return "3.4.1";
return "3.5.0";
}

@Override
Expand Down Expand Up @@ -127,7 +132,9 @@ static void run(Arguments args) throws Exception {
.addShapefileSource("osm_water", sourcesDir.resolve("water-polygons-split-3857.zip"),
"https://osmdata.openstreetmap.de/download/water-polygons-split-3857.zip")
.addShapefileSource("osm_land", sourcesDir.resolve("land-polygons-split-3857.zip"),
"https://osmdata.openstreetmap.de/download/land-polygons-split-3857.zip");
"https://osmdata.openstreetmap.de/download/land-polygons-split-3857.zip")
.addGeoPackageSource("landcover", sourcesDir.resolve("daylight-landcover.gpkg"),
"https://r2-public.protomaps.com/datasets/daylight-landcover.gpkg");

// Downloader.create(planetiler.config()).add("ne", neUrl, nePath)
// .add("qrank", "https://qrank.wmcloud.org/download/qrank.csv.gz", sourcesDir.resolve("qrank.csv.gz")).run();
Expand Down
36 changes: 36 additions & 0 deletions tiles/src/main/java/com/protomaps/basemap/layers/Landcover.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.protomaps.basemap.layers;

import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.ForwardingProfile;
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.geo.GeometryException;
import com.onthegomap.planetiler.reader.SourceFeature;
import com.protomaps.basemap.feature.FeatureId;
import java.util.List;
import java.util.Map;

public class Landcover implements ForwardingProfile.FeaturePostProcessor {

static final Map<String, String> kindMapping = Map.of("urban", "urban_area", "crop", "farmland", "grass", "grassland",
"trees", "forest", "snow", "glacier", "shrub", "scrub", "barren", "barren");

public void processLandcover(SourceFeature sf, FeatureCollector features) {
String kind = kindMapping.getOrDefault(sf.getString("class"), "unknown");

features.polygon(this.name())
.setId(FeatureId.create(sf))
.setAttr("pmap:kind", kind)
.setZoomRange(0, 7)
.setMinPixelSize(0.0);
}

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

@Override
public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> items) throws GeometryException {
return items;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.protomaps.basemap.layers;

import static com.onthegomap.planetiler.TestUtils.newPolygon;

import com.onthegomap.planetiler.reader.SimpleFeature;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

class LandcoverTest extends LayerTest {

@ParameterizedTest
@CsvSource(value = {
"urban,urban_area",
"crop,farmland",
"grass,grassland",
"trees,forest",
"snow,glacier",
"shrub,scrub",
"barren,barren"
})
void simple(String daylightClassString, String expectedString) {
assertFeatures(7,
List.of(Map.of("pmap:kind", expectedString)),
process(SimpleFeature.create(
newPolygon(0, 0, 0, 1, 1, 1, 0, 0),
new HashMap<>(Map.of("class", daylightClassString)),
"landcover",
null,
0
)));
}
}
Loading