Skip to content

Commit

Permalink
Fix build (#257)
Browse files Browse the repository at this point in the history
* Fix build
Since onthegomap/planetiler#914 the registerSourceHandler is called implicitly
* fix build: explicit source handling
* rename processFeature -> processOsm
  • Loading branch information
bdon authored Jun 13, 2024
1 parent a0131b7 commit d514014
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 52 deletions.
26 changes: 13 additions & 13 deletions tiles/src/main/java/com/protomaps/basemap/Basemap.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,54 +28,54 @@ public Basemap(NaturalEarthDb naturalEarthDb, QrankDb qrankDb) {

var admin = new Boundaries();
registerHandler(admin);
registerSourceHandler("osm", admin);
registerSourceHandler("osm", admin::processOsm);
registerSourceHandler("ne", admin::processNe);

var buildings = new Buildings();
registerHandler(buildings);
registerSourceHandler("osm", buildings);
registerSourceHandler("osm", buildings::processOsm);

var landuse = new Landuse();
registerHandler(landuse);
registerSourceHandler("osm", landuse);
registerSourceHandler("osm", landuse::processOsm);

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

var natural = new Natural();
registerHandler(natural);
registerSourceHandler("osm", natural);
registerSourceHandler("osm", natural::processOsm);

var physicalLine = new PhysicalLine();
registerHandler(physicalLine);
registerSourceHandler("osm", physicalLine);
registerSourceHandler("osm", physicalLine::processOsm);

var physicalPoint = new PhysicalPoint();
registerHandler(physicalPoint);
registerSourceHandler("osm", physicalPoint);
registerSourceHandler("osm", physicalPoint::processOsm);
registerSourceHandler("ne", physicalPoint::processNe);

var place = new Places(naturalEarthDb);
registerHandler(place);
registerSourceHandler("osm", place);
registerSourceHandler("osm", place::processOsm);
registerSourceHandler("ne", place::processNe);

var poi = new Pois(qrankDb);
registerHandler(poi);
registerSourceHandler("osm", poi);
registerSourceHandler("osm", poi::processOsm);

var roads = new Roads();
registerHandler(roads);
registerSourceHandler("osm", roads);
registerSourceHandler("osm", roads::processOsm);

var transit = new Transit();
registerHandler(transit);
registerSourceHandler("osm", transit);
registerSourceHandler("osm", transit::processOsm);

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

Expand Down Expand Up @@ -112,11 +112,11 @@ public String attribution() {
""".trim();
}

public static void main(String[] args) throws Exception {
public static void main(String[] args) {
run(Arguments.fromArgsOrConfigFile(args));
}

static void run(Arguments args) throws Exception {
static void run(Arguments args) {
args = args.orElse(Arguments.of("maxzoom", 15));

Path dataDir = Path.of("data");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.List;
import java.util.OptionalInt;

public class Boundaries implements ForwardingProfile.OsmRelationPreprocessor, ForwardingProfile.FeatureProcessor,
public class Boundaries implements ForwardingProfile.OsmRelationPreprocessor,
ForwardingProfile.FeaturePostProcessor {

@Override
Expand Down Expand Up @@ -170,8 +170,7 @@ public void processNe(SourceFeature sf, FeatureCollector features) {
}
}

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
public void processOsm(SourceFeature sf, FeatureCollector features) {
if (sf.canBeLine()) {
// Beware coastlines and coastal waters (eg with admin borders in large estuaries)
// like mouth of Columbia River between Oregon and Washington in USA
Expand Down
17 changes: 8 additions & 9 deletions tiles/src/main/java/com/protomaps/basemap/layers/Buildings.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.List;
import java.util.regex.Pattern;

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

static final String HEIGHT_KEY = "height";
static final String MIN_HEIGHT_KEY = "height";
Expand Down Expand Up @@ -58,8 +58,7 @@ static int quantizeVal(double val, int step) {
return (int) Math.round(val / step) * step;
}

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
public void processOsm(SourceFeature sf, FeatureCollector features) {
if (sf.canBePolygon() && ((sf.hasTag("building") && !sf.hasTag("building", "no")) ||
(sf.hasTag("building:part") && !sf.hasTag("building:part", "no")))) {

Expand Down Expand Up @@ -108,8 +107,8 @@ public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> i

// quantize height by zoom when less than max_zoom 15 to facilitate better feature merging
for (var item : items) {
if (item.attrs().containsKey(HEIGHT_KEY)) {
var height = (double) item.attrs().get(HEIGHT_KEY);
if (item.tags().containsKey(HEIGHT_KEY)) {
var height = (double) item.tags().get(HEIGHT_KEY);

// Protected against NULL values
if (height > 0) {
Expand All @@ -126,12 +125,12 @@ public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> i
height = quantizeVal(height, 5);
}

item.attrs().put(HEIGHT_KEY, height);
item.tags().put(HEIGHT_KEY, height);
}
}

if (item.attrs().containsKey(MIN_HEIGHT_KEY)) {
var minHeight = (double) item.attrs().get(MIN_HEIGHT_KEY);
if (item.tags().containsKey(MIN_HEIGHT_KEY)) {
var minHeight = (double) item.tags().get(MIN_HEIGHT_KEY);

// Protected against NULL values
if (minHeight > 0) {
Expand All @@ -147,7 +146,7 @@ public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> i
minHeight = quantizeVal(minHeight, 5);
}

item.attrs().put(MIN_HEIGHT_KEY, minHeight);
item.tags().put(MIN_HEIGHT_KEY, minHeight);
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions tiles/src/main/java/com/protomaps/basemap/layers/Landuse.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
import com.protomaps.basemap.postprocess.Area;
import java.util.List;

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

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
public void processOsm(SourceFeature sf, FeatureCollector features) {
if (sf.canBePolygon() && (sf.hasTag("aeroway", "aerodrome", "runway") ||
sf.hasTag("area:aeroway", "taxiway", "runway") ||
sf.hasTag("amenity", "hospital", "school", "kindergarten", "university", "college") ||
Expand Down
5 changes: 2 additions & 3 deletions tiles/src/main/java/com/protomaps/basemap/layers/Natural.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
import com.protomaps.basemap.postprocess.Area;
import java.util.List;

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

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

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
public void processOsm(SourceFeature sf, FeatureCollector features) {
if (sf.canBePolygon() &&
(sf.hasTag("natural", "wood", "glacier", "grass", "scrub", "sand", "wetland", "bare_rock") ||
sf.hasTag("landuse", "forest", "meadow", "grass"))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
import com.protomaps.basemap.names.OsmNames;
import java.util.List;

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

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

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
public void processOsm(SourceFeature sf, FeatureCollector features) {
if (sf.canBeLine() && !sf.canBePolygon() && (sf.hasTag("waterway") ||
sf.hasTag("natural", "cliff")) && (!sf.hasTag("waterway", "riverbank", "reservoir"))) {
int minZoom = 12;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.protomaps.basemap.names.OsmNames;
import java.util.List;

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

@Override
public String name() {
Expand Down Expand Up @@ -65,8 +65,7 @@ public void processNe(SourceFeature sf, FeatureCollector features) {
}
}

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
public void processOsm(SourceFeature sf, FeatureCollector features) {
if (sf.isPoint() && (sf.hasTag("place", "sea", "ocean") || sf.hasTag("natural", "peak"))) {

// TODO: rank based on ele
Expand Down
5 changes: 2 additions & 3 deletions tiles/src/main/java/com/protomaps/basemap/layers/Places.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

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

private NaturalEarthDb naturalEarthDb;

Expand Down Expand Up @@ -150,8 +150,7 @@ public void processNe(SourceFeature sf, FeatureCollector features) {
}
}

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
public void processOsm(SourceFeature sf, FeatureCollector features) {
if (sf.isPoint() && sf.hasTag("name") &&
(sf.hasTag("place", "suburb", "town", "village", "neighbourhood", "quarter", "city", "country", "state",
"province"))) {
Expand Down
5 changes: 2 additions & 3 deletions tiles/src/main/java/com/protomaps/basemap/layers/Pois.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.protomaps.basemap.names.OsmNames;
import java.util.List;

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

private QrankDb qrankDb;

Expand All @@ -31,8 +31,7 @@ public String name() {
Math.pow(GeoUtils.metersToPixelAtEquator(0, Math.sqrt(70_000)) / 256d, 2);
private static final double LOG2 = Math.log(2);

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
public void processOsm(SourceFeature sf, FeatureCollector features) {
if ((sf.isPoint() || sf.canBePolygon()) && (sf.hasTag("aeroway", "aerodrome") ||
sf.hasTag("amenity") ||
sf.hasTag("attraction") ||
Expand Down
5 changes: 2 additions & 3 deletions tiles/src/main/java/com/protomaps/basemap/layers/Roads.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import com.protomaps.basemap.names.OsmNames;
import java.util.*;

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

@Override
public String name() {
Expand All @@ -27,8 +27,7 @@ public String name() {

public record Shield(String text, String network) {}

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
public void processOsm(SourceFeature sf, FeatureCollector features) {
if (sf.canBeLine() && sf.hasTag("highway") &&
!(sf.hasTag("highway", "proposed", "abandoned", "razed", "demolished", "removed", "construction", "elevator"))) {
String kind = "other";
Expand Down
5 changes: 2 additions & 3 deletions tiles/src/main/java/com/protomaps/basemap/layers/Transit.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
import com.protomaps.basemap.names.OsmNames;
import java.util.List;

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

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

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
public void processOsm(SourceFeature sf, FeatureCollector features) {
// todo: exclude railway stations, levels
if (sf.canBeLine() && (sf.hasTag("railway") ||
sf.hasTag("aerialway", "cable_car") ||
Expand Down
5 changes: 2 additions & 3 deletions tiles/src/main/java/com/protomaps/basemap/layers/Water.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.onthegomap.planetiler.util.Parse;
import java.util.List;

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

@Override
public String name() {
Expand Down Expand Up @@ -78,8 +78,7 @@ public void processNe(SourceFeature sf, FeatureCollector features) {
}
}

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
public void processOsm(SourceFeature sf, FeatureCollector features) {
if (sf.canBePolygon() && (sf.hasTag("water") ||
sf.hasTag("waterway") ||
sf.hasTag("natural", "water") ||
Expand Down

0 comments on commit d514014

Please sign in to comment.