From 596770aafaa9c92b59c9469c8cb92b012d1ad970 Mon Sep 17 00:00:00 2001 From: Michael Barry Date: Tue, 17 May 2022 20:23:11 -0400 Subject: [PATCH] Handle elevations in units besides meters (#226) --- .../basemap/layers/MountainPeak.java | 4 +-- .../planetiler/basemap/util/Utils.java | 6 ++-- .../basemap/layers/AerodromeLabelTest.java | 30 +++++++++++++++++++ .../basemap/layers/MountainPeakTest.java | 24 +++++++++++++++ 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/onthegomap/planetiler/basemap/layers/MountainPeak.java b/src/main/java/com/onthegomap/planetiler/basemap/layers/MountainPeak.java index 46f9340d81..e8b0671337 100644 --- a/src/main/java/com/onthegomap/planetiler/basemap/layers/MountainPeak.java +++ b/src/main/java/com/onthegomap/planetiler/basemap/layers/MountainPeak.java @@ -113,14 +113,14 @@ public void processNaturalEarth(String table, SourceFeature feature, FeatureColl @Override public void process(Tables.OsmPeakPoint element, FeatureCollector features) { - Integer meters = Parse.parseIntSubstring(element.ele()); + Double meters = Parse.meters(element.ele()); if (meters != null && Math.abs(meters) < 10_000) { var feature = features.point(LAYER_NAME) .setAttr(Fields.CLASS, element.source().getTag("natural")) .putAttrs(LanguageUtils.getNames(element.source().tags(), translations)) .putAttrs(elevationTags(meters)) .setSortKeyDescending( - meters + + meters.intValue() + (nullIfEmpty(element.wikipedia()) != null ? 10_000 : 0) + (nullIfEmpty(element.name()) != null ? 10_000 : 0) ) diff --git a/src/main/java/com/onthegomap/planetiler/basemap/util/Utils.java b/src/main/java/com/onthegomap/planetiler/basemap/util/Utils.java index 7c88695ac3..130815538b 100644 --- a/src/main/java/com/onthegomap/planetiler/basemap/util/Utils.java +++ b/src/main/java/com/onthegomap/planetiler/basemap/util/Utils.java @@ -49,9 +49,9 @@ public static boolean nullOrEmpty(Object a) { } /** Returns a map with {@code ele} (meters) and {ele_ft} attributes from an elevation in meters. */ - public static Map elevationTags(int meters) { + public static Map elevationTags(double meters) { return Map.of( - "ele", meters, + "ele", (int) Math.round(meters), "ele_ft", (int) Math.round(meters * 3.2808399) ); } @@ -61,7 +61,7 @@ public static Map elevationTags(int meters) { * meters} can be parsed as a valid number. */ public static Map elevationTags(String meters) { - Integer ele = Parse.parseIntSubstring(meters); + Double ele = Parse.meters(meters); return ele == null ? Map.of() : elevationTags(ele); } diff --git a/src/test/java/com/onthegomap/planetiler/basemap/layers/AerodromeLabelTest.java b/src/test/java/com/onthegomap/planetiler/basemap/layers/AerodromeLabelTest.java index 237b3f618a..5de48118b2 100644 --- a/src/test/java/com/onthegomap/planetiler/basemap/layers/AerodromeLabelTest.java +++ b/src/test/java/com/onthegomap/planetiler/basemap/layers/AerodromeLabelTest.java @@ -37,6 +37,36 @@ void testIntlWithIata() { )))); } + @Test + void testElevationFeet() { + assertFeatures(14, List.of(Map.of( + "ele", 100, + "ele_ft", 328 + )), process(pointFeature(Map.of( + "aeroway", "aerodrome", + "name", "osm name", + "ele", "328'", + "aerodrome", "international", + "iata", "123", + "icao", "1234" + )))); + } + + @Test + void testElevationFeetInches() { + assertFeatures(14, List.of(Map.of( + "ele", 100, + "ele_ft", 328 + )), process(pointFeature(Map.of( + "aeroway", "aerodrome", + "name", "osm name", + "ele", "328' 1\"", + "aerodrome", "international", + "iata", "123", + "icao", "1234" + )))); + } + @Test void testInternational() { assertFeatures(14, List.of(Map.of( diff --git a/src/test/java/com/onthegomap/planetiler/basemap/layers/MountainPeakTest.java b/src/test/java/com/onthegomap/planetiler/basemap/layers/MountainPeakTest.java index 5c8f216784..f121e78668 100644 --- a/src/test/java/com/onthegomap/planetiler/basemap/layers/MountainPeakTest.java +++ b/src/test/java/com/onthegomap/planetiler/basemap/layers/MountainPeakTest.java @@ -75,6 +75,30 @@ void testVolcano() { )))); } + @Test + void testElevationFeet() { + assertFeatures(14, List.of(Map.of( + "class", "volcano", + "ele", 30, + "ele_ft", 100 + )), process(pointFeature(Map.of( + "natural", "volcano", + "ele", "100'" + )))); + } + + @Test + void testElevationFeetInches() { + assertFeatures(14, List.of(Map.of( + "class", "volcano", + "ele", 31, + "ele_ft", 101 + )), process(pointFeature(Map.of( + "natural", "volcano", + "ele", "100' 11\"" + )))); + } + @Test void testSaddle() { assertFeatures(14, List.of(Map.of(