Skip to content

Commit

Permalink
Handle elevations in units besides meters (onthegomap#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry authored May 18, 2022
1 parent a70a507 commit 596770a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> elevationTags(int meters) {
public static Map<String, Object> elevationTags(double meters) {
return Map.of(
"ele", meters,
"ele", (int) Math.round(meters),
"ele_ft", (int) Math.round(meters * 3.2808399)
);
}
Expand All @@ -61,7 +61,7 @@ public static Map<String, Object> elevationTags(int meters) {
* meters} can be parsed as a valid number.
*/
public static Map<String, Object> elevationTags(String meters) {
Integer ele = Parse.parseIntSubstring(meters);
Double ele = Parse.meters(meters);
return ele == null ? Map.of() : elevationTags(ele);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 596770a

Please sign in to comment.