Skip to content
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
31 changes: 27 additions & 4 deletions tiles/src/main/java/com/protomaps/basemap/layers/Pois.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@
import com.protomaps.basemap.names.OsmNames;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

@SuppressWarnings("java:S1192")
public class Pois implements ForwardingProfile.LayerPostProcessor {

// Matches numeric metre values with an optional trailing "m" suffix, e.g. "569", "569.5", "569 m", or "569m".
private static final Pattern ELEVATION_PATTERN =
Pattern.compile("^([+-]?(?:\\d+(?:\\.\\d+)?|\\.\\d+))(?:\\s*m)?$");

private Map<String, int[][]> qrankGrading = Map.of(
"station", new int[][]{{10, 50000}, {12, 20000}, {13, 10000}},
"aerodrome", new int[][]{{10, 50000}, {12, 20000}, {13, 5000}, {14, 2500}},
Expand All @@ -46,6 +51,25 @@ public Pois(QrankDb qrankDb) {

public static final String LAYER_NAME = "pois";

static Integer parseElevation(String elevation) {
if (elevation == null) {
return null;
}

var matcher = ELEVATION_PATTERN.matcher(elevation.trim());
if (!matcher.matches()) {
return null;
}

var parsed = parseDoubleOrNull(matcher.group(1));
if (parsed == null) {
return null;
}

var rounded = Math.round(parsed);
return rounded >= Integer.MIN_VALUE && rounded <= Integer.MAX_VALUE ? (int) rounded : null;
}

private static final Expression WITH_OPERATOR_USFS = with("operator", "United States Forest Service",
"US Forest Service", "U.S. Forest Service", "USDA Forest Service", "United States Department of Agriculture",
"US National Forest Service", "United State Forest Service", "U.S. National Forest Service");
Expand Down Expand Up @@ -501,9 +525,7 @@ public void processOsm(SourceFeature sf, FeatureCollector features) {

// Assign outputFeature
if (hasNamedPolygon) {
outputFeature = features.pointOnSurface(this.name())
//.setAttr("area_debug", wayArea) // DEBUG
.setAttr("elevation", sf.getString("ele"));
outputFeature = features.pointOnSurface(this.name());
} else if (sf.isPoint()) {
outputFeature = features.point(this.name());
} else {
Expand All @@ -525,7 +547,8 @@ public void processOsm(SourceFeature sf, FeatureCollector features) {
.setZoomRange(Math.min(minZoom, 15), 15)
// Core OSM tags for different kinds of places
// Special airport only tag (to indicate if it's an airport with regular commercial flights)
.setAttr("iata", sf.getString("iata"));
.setAttr("iata", sf.getString("iata"))
.setAttr("elevation", parseElevation(sf.getString("ele")));

// Core Tilezen schema properties
if (!kindDetail.equals("pm:undefined"))
Expand Down
58 changes: 57 additions & 1 deletion tiles/src/test/java/com/protomaps/basemap/layers/PoisTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.protomaps.basemap.layers;

import static com.onthegomap.planetiler.TestUtils.*;
import static org.junit.jupiter.api.Assertions.assertFalse;

import com.onthegomap.planetiler.reader.SimpleFeature;
import java.util.HashMap;
Expand Down Expand Up @@ -197,6 +198,61 @@ void zoom_14_peak() {
)));
}

@Test
void peakElevation() {
assertFeatures(14,
List.of(Map.of("kind", "peak", "min_zoom", 14, "elevation", 569)),
process(SimpleFeature.create(
newPoint(1, 1),
new HashMap<>(Map.of("natural", "peak", "ele", "569")),
"osm", null, 0
)));
}

@Test
void peakElevationDecimal() {
assertFeatures(14,
List.of(Map.of("kind", "peak", "min_zoom", 14, "elevation", 570)),
process(SimpleFeature.create(
newPoint(1, 1),
new HashMap<>(Map.of("natural", "peak", "ele", "569.5")),
"osm", null, 0
)));
}

@Test
void peakElevationMeterSuffix() {
assertFeatures(14,
List.of(Map.of("kind", "peak", "min_zoom", 14, "elevation", 569)),
process(SimpleFeature.create(
newPoint(1, 1),
new HashMap<>(Map.of("natural", "peak", "ele", "569 m")),
"osm", null, 0
)));
}

@Test
void peakElevationMeterSuffixWithoutWhitespace() {
assertFeatures(14,
List.of(Map.of("kind", "peak", "min_zoom", 14, "elevation", 569)),
process(SimpleFeature.create(
newPoint(1, 1),
new HashMap<>(Map.of("natural", "peak", "ele", "569m")),
"osm", null, 0
)));
}

@Test
void peakElevationNonMeterUnitOmitted() {
var features = process(SimpleFeature.create(
newPoint(1, 1),
new HashMap<>(Map.of("natural", "peak", "ele", "569 ft")),
"osm", null, 0
));

assertFalse(toMap(features.iterator().next(), 14).containsKey("elevation"));
}

@Test
void zoom_14_golfCourse() {
assertFeatures(14,
Expand Down Expand Up @@ -629,7 +685,7 @@ void zoom_8_forest_largeArea() {
@Test
void zoom_12_tallBuilding_100mHeight() {
assertFeatures(12,
List.of(Map.of("kind", "office", "min_zoom", 12, "name", "Skyscraper", "elevation", "100")),
List.of(Map.of("kind", "office", "min_zoom", 12, "name", "Skyscraper", "elevation", 100)),
process(SimpleFeature.create(
AREA_12K_SQ_M,
new HashMap<>(Map.of(
Expand Down
Loading