Handle elevations in units besides meters (#226)

This commit is contained in:
Michael Barry
2022-05-17 20:23:11 -04:00
committed by GitHub
parent a70a507e47
commit 596770aafa
4 changed files with 59 additions and 5 deletions

View File

@@ -113,14 +113,14 @@ public class MountainPeak implements
@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)
)

View File

@@ -49,9 +49,9 @@ public class Utils {
}
/** 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)
);
}
@@ -61,7 +61,7 @@ public class Utils {
* 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);
}