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

Refactor to use OpenMapTiles schema #46

Merged
merged 2 commits into from
Apr 15, 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
13 changes: 7 additions & 6 deletions vector/src/main/java/lt/lrv/basemap/layers/AerodromeLabel.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package lt.lrv.basemap.layers;

import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.ForwardingProfile;
import com.onthegomap.planetiler.reader.SourceFeature;
import lt.lrv.basemap.constants.Layer;
import lt.lrv.basemap.constants.Source;
import lt.lrv.basemap.openmaptiles.OpenMapTilesSchema;
import lt.lrv.basemap.utils.LanguageUtils;

import java.util.Arrays;
import java.util.List;

public class AerodromeLabel implements ForwardingProfile.FeatureProcessor {
public class AerodromeLabel implements OpenMapTilesSchema.AerodromeLabel {

// Some airports have multiple features and this leads to duplicated names. Use this to filter out them
static final List<String> IGNORED_TOP_IDS = Arrays.asList(
Expand Down Expand Up @@ -38,12 +38,13 @@ public void processFeature(SourceFeature sf, FeatureCollector features) {
var clazz = isInternational ? "international" : "regional";


features.centroid("aerodrome_label")
features.centroid(this.name())
.setBufferPixels(BUFFER_SIZE)
.setMinZoom(isInternational ? 8 : 10)
.putAttrs(LanguageUtils.getNames(sf.tags()))
.setAttr("iata", iata)
.setAttr("icao", icao)
.setAttr("class", clazz);
.setAttr(Fields.IATA, iata)
.setAttr(Fields.ICAO, icao)
.setAttr(Fields.CLASS, clazz);
}
}

Expand Down
15 changes: 8 additions & 7 deletions vector/src/main/java/lt/lrv/basemap/layers/Aeroway.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
package lt.lrv.basemap.layers;

import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.ForwardingProfile;
import com.onthegomap.planetiler.reader.SourceFeature;
import lt.lrv.basemap.constants.Layer;
import lt.lrv.basemap.constants.Source;
import lt.lrv.basemap.openmaptiles.OpenMapTilesSchema;

public class Aeroway implements ForwardingProfile.FeatureProcessor {
public class Aeroway implements OpenMapTilesSchema.Aeroway {

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
if (sf.getSource().equals(Source.GRPK) && sf.getSourceLayer().startsWith(Layer.GRPK_PLOTAI_PREFIX) && sf.canBePolygon()) {
var code = sf.getString("GKODAS");

switch (code) {
case "va1" -> addFeature("aerodrome", features);
case "va11" -> addFeature("runway", features);
case "va12" -> addFeature("helipad", features);
case "va1" -> addFeature(FieldValues.CLASS_AERODROME, features);
case "va11" -> addFeature(FieldValues.CLASS_RUNWAY, features);
case "va12" -> addFeature(FieldValues.CLASS_HELIPAD, features);
}
}
}


public void addFeature(String clazz, FeatureCollector features) {
features.polygon("aeroway")
.setAttr("class", clazz)
features.polygon(this.name())
.setBufferPixels(BUFFER_SIZE)
.setAttr(Fields.CLASS, clazz)
.setMinZoom(10)
.setMinPixelSize(2);
}
Expand Down
15 changes: 6 additions & 9 deletions vector/src/main/java/lt/lrv/basemap/layers/Boundary.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import com.onthegomap.planetiler.reader.SourceFeature;
import lt.lrv.basemap.constants.Layer;
import lt.lrv.basemap.constants.Source;
import lt.lrv.basemap.openmaptiles.OpenMapTilesSchema;
import lt.lrv.basemap.utils.LanguageUtils;

import java.util.List;

public class Boundary implements ForwardingProfile.FeaturePostProcessor, ForwardingProfile.FeatureProcessor {
public class Boundary implements OpenMapTilesSchema.Boundary, ForwardingProfile.FeaturePostProcessor {

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
Expand All @@ -29,10 +30,11 @@ public void processFeature(SourceFeature sf, FeatureCollector features) {

void addBoundaryFeature(int adminLevel, SourceFeature sf, FeatureCollector features) {
features.line(this.name())
.setAttr("admin_level", adminLevel)
.setAttr("disputed", 0)
.setBufferPixels(BUFFER_SIZE)
.setAttr(Fields.ADMIN_LEVEL, adminLevel)
.setAttr(Fields.DISPUTED, 0)
// TODO determine if border is maritime or not
.setAttr("maritime", 0)
.setAttr(Fields.MARITIME, 0)
.putAttrs(LanguageUtils.getNames(sf.tags()));
}

Expand All @@ -49,9 +51,4 @@ public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> i
4
);
}

@Override
public String name() {
return "boundary";
}
}
10 changes: 3 additions & 7 deletions vector/src/main/java/lt/lrv/basemap/layers/Building.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
import com.onthegomap.planetiler.reader.SourceFeature;
import lt.lrv.basemap.constants.Layer;
import lt.lrv.basemap.constants.Source;
import lt.lrv.basemap.openmaptiles.OpenMapTilesSchema;

import java.util.List;

public class Building implements ForwardingProfile.FeaturePostProcessor, ForwardingProfile.FeatureProcessor {
public class Building implements OpenMapTilesSchema.Building, ForwardingProfile.FeaturePostProcessor {

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
if (sf.getSource().equals(Source.GRPK) && sf.getSourceLayer().equals(Layer.GRPK_PASTAT) && sf.canBePolygon()) {
features.polygon(this.name()).setMinZoom(11);
features.polygon(this.name()).setBufferPixels(BUFFER_SIZE).setMinZoom(11);
}
}

Expand All @@ -28,9 +29,4 @@ public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> i

return FeatureMerge.mergeNearbyPolygons(items, 3.125, 3.125, 0.5, 0.5);
}

@Override
public String name() {
return "building";
}
}
10 changes: 5 additions & 5 deletions vector/src/main/java/lt/lrv/basemap/layers/HouseNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@


import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.ForwardingProfile;
import com.onthegomap.planetiler.reader.SourceFeature;
import lt.lrv.basemap.constants.Source;
import lt.lrv.basemap.openmaptiles.OpenMapTilesSchema;

public class HouseNumber implements ForwardingProfile.FeatureProcessor {
public class HouseNumber implements OpenMapTilesSchema.Housenumber {

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
if (sf.getSource().equals(Source.AR) && sf.isPoint()) {
features.point("housenumber")
.setBufferPixels(8)
.setAttr("housenumber", sf.getTag("NR"))
features.point(this.name())
.setBufferPixels(BUFFER_SIZE)
.setAttr(Fields.HOUSENUMBER, sf.getTag("NR"))
.setMinZoom(14);
}
}
Expand Down
28 changes: 12 additions & 16 deletions vector/src/main/java/lt/lrv/basemap/layers/Landcover.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
import com.onthegomap.planetiler.util.ZoomFunction;
import lt.lrv.basemap.constants.Layer;
import lt.lrv.basemap.constants.Source;
import lt.lrv.basemap.openmaptiles.OpenMapTilesSchema;

import java.util.List;
import java.util.Map;

public class Landcover implements ForwardingProfile.FeaturePostProcessor, ForwardingProfile.FeatureProcessor {
public class Landcover implements OpenMapTilesSchema.Landcover, ForwardingProfile.FeaturePostProcessor {

public static final ZoomFunction<Number> MIN_PIXEL_SIZE_THRESHOLDS = ZoomFunction.fromMaxZoomThresholds(Map.of(
13, 8,
Expand All @@ -27,27 +28,27 @@ public void processFeature(SourceFeature sf, FeatureCollector features) {
var code = sf.getString("GKODAS");

switch (code) {
case "sd2" -> addPolygon("grass", "meadow", 10, features);
case "uur14" -> addPolygon("grass", "park", 8, features);
case "ms4" -> addPolygon("farmland", "orchard", 12, features);
case "hd6" -> addPolygon("wetland", "wetland", 8, features);
case "sd42" -> addPolygon("sand", "sand", 8, features);
case "ms0" -> addPolygon("wood", "forest", 5, features);
case "mj0", "sd15" -> addPolygon("wood", "forest", 10, features);
case "sd2" -> addPolygon(FieldValues.CLASS_GRASS, FieldValues.SUBCLASS_MEADOW, 10, features);
case "uur14" -> addPolygon(FieldValues.CLASS_GRASS, FieldValues.SUBCLASS_PARK, 8, features);
case "ms4" -> addPolygon(FieldValues.CLASS_FARMLAND, FieldValues.SUBCLASS_ORCHARD, 12, features);
case "hd6" -> addPolygon(FieldValues.CLASS_WETLAND, FieldValues.SUBCLASS_WETLAND, 8, features);
case "sd42" -> addPolygon(FieldValues.CLASS_SAND, FieldValues.SUBCLASS_SAND, 8, features);
case "ms0" -> addPolygon(FieldValues.CLASS_WOOD, FieldValues.SUBCLASS_FOREST, 5, features);
case "mj0", "sd15" -> addPolygon(FieldValues.CLASS_WOOD, FieldValues.SUBCLASS_FOREST, 10, features);
}
}
}


public void addPolygon(String clazz, String subclass, int minZoom, FeatureCollector features) {
features.polygon(this.name())
.setBufferPixels(4)
.setBufferPixels(BUFFER_SIZE)
.setMinPixelSizeOverrides(MIN_PIXEL_SIZE_THRESHOLDS)
// Optimization from Planetiler-OpenMapTiles
// default is 0.1, this helps reduce size of some heavy z5-10 tiles
.setPixelToleranceBelowZoom(10, 0.25)
.setAttr("class", clazz)
.setAttr("subclass", subclass)
.setAttr(Fields.CLASS, clazz)
.setAttr(Fields.SUBCLASS, subclass)
.setMinZoom(minZoom);
}

Expand All @@ -59,9 +60,4 @@ public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> i

return FeatureMerge.mergeNearbyPolygons(items, 3.125, 3.125, 0.5, 0.5);
}

@Override
public String name() {
return "landcover";
}
}
28 changes: 11 additions & 17 deletions vector/src/main/java/lt/lrv/basemap/layers/Landuse.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
import com.onthegomap.planetiler.util.ZoomFunction;
import lt.lrv.basemap.constants.Layer;
import lt.lrv.basemap.constants.Source;
import lt.lrv.basemap.openmaptiles.OpenMapTilesSchema;

import java.util.List;
import java.util.Map;

public class Landuse implements ForwardingProfile.FeaturePostProcessor, ForwardingProfile.FeatureProcessor {
public class Landuse implements OpenMapTilesSchema.Landuse, ForwardingProfile.FeaturePostProcessor {

private static final ZoomFunction<Number> MIN_PIXEL_SIZE_THRESHOLDS = ZoomFunction.fromMaxZoomThresholds(Map.of(
13, 4,
Expand All @@ -27,27 +28,25 @@ public void processFeature(SourceFeature sf, FeatureCollector features) {
var code = sf.getString("GKODAS");

switch (code) {
case "pu0" -> addPolygon("residential", "residential", 5, features);
case "pu3" -> addPolygon("industrial", "industrial", 5, features);
case "vp1" -> addPolygon("cemetery", "cemetery", 10, features);
case "ek0" -> addPolygon("quarry", "quarry", 10, features);
case "vg3" -> addPolygon("landfill", "landfill", 10, features);
case "vk1" -> addPolygon("stadium", "stadium", 10, features);
case "gt17", "gt18", "gt19" -> addPolygon("railway", "railway", 10, features);
case "pu0" -> addPolygon(FieldValues.CLASS_RESIDENTIAL, 5, features);
case "pu3" -> addPolygon(FieldValues.CLASS_INDUSTRIAL, 5, features);
case "vp1" -> addPolygon(FieldValues.CLASS_CEMETERY, 10, features);
case "ek0" -> addPolygon(FieldValues.CLASS_QUARRY, 10, features);
case "vk1" -> addPolygon(FieldValues.CLASS_STADIUM, 10, features);
case "gt17", "gt18", "gt19" -> addPolygon(FieldValues.CLASS_RAILWAY, 10, features);
}
}
}


public void addPolygon(String clazz, String subclass, int minZoom, FeatureCollector features) {
public void addPolygon(String clazz, int minZoom, FeatureCollector features) {
features.polygon(this.name())
.setBufferPixels(4)
.setBufferPixels(BUFFER_SIZE)
.setMinPixelSizeOverrides(MIN_PIXEL_SIZE_THRESHOLDS)
// Optimization from Planetiler-OpenMapTiles
// default is 0.1, this helps reduce size of some heavy z5-10 tiles
.setPixelToleranceBelowZoom(10, 0.25)
.setAttr("class", clazz)
.setAttr("subclass", subclass)
.setAttr(Fields.CLASS, clazz)
.setMinZoom(minZoom);
}

Expand All @@ -59,9 +58,4 @@ public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> i

return FeatureMerge.mergeNearbyPolygons(items, 3.125, 3.125, 0.5, 0.5);
}

@Override
public String name() {
return "landuse";
}
}
4 changes: 2 additions & 2 deletions vector/src/main/java/lt/lrv/basemap/layers/MountainPeak.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package lt.lrv.basemap.layers;

import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.ForwardingProfile;
import com.onthegomap.planetiler.reader.SourceFeature;
import lt.lrv.basemap.openmaptiles.OpenMapTilesSchema;

public class MountainPeak implements ForwardingProfile.FeatureProcessor {
public class MountainPeak implements OpenMapTilesSchema.MountainPeak {

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
Expand Down
16 changes: 8 additions & 8 deletions vector/src/main/java/lt/lrv/basemap/layers/POI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@


import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.ForwardingProfile;
import com.onthegomap.planetiler.reader.SourceFeature;
import lt.lrv.basemap.constants.Layer;
import lt.lrv.basemap.constants.Source;
import lt.lrv.basemap.openmaptiles.OpenMapTilesSchema;
import lt.lrv.basemap.utils.LanguageUtils;

import static com.google.common.base.Strings.emptyToNull;

public class POI implements ForwardingProfile.FeatureProcessor {
public class POI implements OpenMapTilesSchema.Poi {

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
Expand All @@ -23,20 +23,20 @@ public void processFeature(SourceFeature sf, FeatureCollector features) {
var code = sf.getString("GKODAS");

switch (code) {
case "uur14" -> addFeature("park", 5, sf, features);
case "uur14" -> addFeature(FieldValues.CLASS_PARK, 5, sf, features);
case "uvp1" -> addFeature("cemetery", 10, sf, features);
case "unk0" -> addFeature("unknown", 15, sf, features);
}
}
}

void addFeature(String clazz, int rank, SourceFeature sf, FeatureCollector features) {
features.point("poi")
.setBufferPixels(64)
features.point(this.name())
.setBufferPixels(BUFFER_SIZE)
.putAttrs(LanguageUtils.getNames(sf.tags()))
.setAttr("class", clazz)
.setAttr("rank", rank)
.setAttr("level", 0)
.setAttr(Fields.CLASS, clazz)
.setAttr(Fields.RANK, rank)
.setAttr(Fields.LEVEL, 0)
.setMinZoom(10)
.setPointLabelGridPixelSize(14, 64)
.setSortKey(rank);
Expand Down
13 changes: 5 additions & 8 deletions vector/src/main/java/lt/lrv/basemap/layers/Park.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
import com.onthegomap.planetiler.reader.SourceFeature;
import lt.lrv.basemap.constants.Layer;
import lt.lrv.basemap.constants.Source;
import lt.lrv.basemap.openmaptiles.OpenMapTilesSchema;

import java.util.List;

public class Park implements ForwardingProfile.FeaturePostProcessor, ForwardingProfile.FeatureProcessor {
public class Park implements OpenMapTilesSchema.Park, ForwardingProfile.FeaturePostProcessor {

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
if (sf.getSource().equals(Source.GRPK) && sf.getSourceLayer().equals(Layer.GRPK_VIETOV_P) && sf.canBePolygon()) {
var code = sf.getString("GKODAS");

if (code.equals("uur14")) {
features.polygon("park")
.setAttr("class", "nature_reserve")
features.polygon(this.name())
.setBufferPixels(BUFFER_SIZE)
.setAttr(Fields.CLASS, "nature_reserve")
.setMinZoom(12);
}
}
Expand All @@ -34,9 +36,4 @@ public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> i

return FeatureMerge.mergeNearbyPolygons(items, 3.125, 3.125, 0.5, 0.5);
}

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