diff --git a/vtm-json/src/org/oscim/tiling/source/geojson/MapzenGeojsonTileSource.java b/vtm-json/src/org/oscim/tiling/source/geojson/MapzenGeojsonTileSource.java index 8c4cb276..d50a8f79 100644 --- a/vtm-json/src/org/oscim/tiling/source/geojson/MapzenGeojsonTileSource.java +++ b/vtm-json/src/org/oscim/tiling/source/geojson/MapzenGeojsonTileSource.java @@ -1,5 +1,6 @@ /* * Copyright 2017 devemux86 + * Copyright 2017 Gustl22 * * This program is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free Software @@ -17,6 +18,7 @@ package org.oscim.tiling.source.geojson; import org.oscim.core.MapElement; import org.oscim.core.Tag; import org.oscim.tiling.source.UrlTileSource; +import org.oscim.utils.math.MathUtils; import java.util.LinkedHashMap; import java.util.Map; @@ -105,5 +107,18 @@ public class MapzenGeojsonTileSource extends GeojsonTileSource { if (!hasName && fallbackName != null) mapElement.tags.add(new Tag(Tag.KEY_NAME, fallbackName, false)); + + // Calculate height of building parts + if (!properties.containsKey(Tag.KEY_HEIGHT)) { + if (properties.containsKey(Tag.KEY_VOLUME) && properties.containsKey(Tag.KEY_AREA)) { + Object volume = properties.get(Tag.KEY_VOLUME); + String volumeStr = (volume instanceof String) ? (String) volume : String.valueOf(volume); + Object area = properties.get(Tag.KEY_AREA); + String areaStr = (area instanceof String) ? (String) area : String.valueOf(area); + float height = Float.parseFloat(volumeStr) / Float.parseFloat(areaStr); + String heightStr = String.valueOf(MathUtils.round2(height)); + mapElement.tags.add(new Tag(Tag.KEY_HEIGHT, heightStr, false)); + } + } } } diff --git a/vtm-themes/resources/assets/vtm/default.xml b/vtm-themes/resources/assets/vtm/default.xml index 59bd32aa..eb7fbf8a 100644 --- a/vtm-themes/resources/assets/vtm/default.xml +++ b/vtm-themes/resources/assets/vtm/default.xml @@ -560,13 +560,25 @@ --> - - - - + + + + + + + + + - - + + + + + + + + + diff --git a/vtm-themes/resources/assets/vtm/mapzen.xml b/vtm-themes/resources/assets/vtm/mapzen.xml index d0c6bc27..f092501c 100644 --- a/vtm-themes/resources/assets/vtm/mapzen.xml +++ b/vtm-themes/resources/assets/vtm/mapzen.xml @@ -557,13 +557,25 @@ --> - - - - + + + + + + + + + - - + + + + + + + + + diff --git a/vtm-themes/resources/assets/vtm/openmaptiles.xml b/vtm-themes/resources/assets/vtm/openmaptiles.xml index 14dffac9..4644f7eb 100644 --- a/vtm-themes/resources/assets/vtm/openmaptiles.xml +++ b/vtm-themes/resources/assets/vtm/openmaptiles.xml @@ -556,13 +556,25 @@ --> - - - - + + + + + + + + + - - + + + + + + + + + diff --git a/vtm/src/org/oscim/core/Tag.java b/vtm/src/org/oscim/core/Tag.java index 62ad590b..ba4a67b9 100644 --- a/vtm/src/org/oscim/core/Tag.java +++ b/vtm/src/org/oscim/core/Tag.java @@ -1,7 +1,8 @@ /* * Copyright 2010, 2011, 2012 mapsforge.org * Copyright 2013 Hannes Janetzek - * Copyright 2016 devemux86 + * Copyright 2016-2017 devemux86 + * Copyright 2017 Gustl22 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -46,11 +47,14 @@ public class Tag { public static final String KEY_ELE = "ele"; public static final String KEY_AMENITY = "amenity"; + public static final String KEY_AREA = "area"; public static final String KEY_BUILDING = "building"; + public static final String KEY_BUILDING_LEVELS = "building:levels"; public static final String KEY_HIGHWAY = "highway"; public static final String KEY_LANDUSE = "landuse"; public static final String KEY_HEIGHT = "height"; public static final String KEY_MIN_HEIGHT = "min_height"; + public static final String KEY_VOLUME = "volume"; public static final String VALUE_YES = "yes"; public static final String VALUE_NO = "no"; diff --git a/vtm/src/org/oscim/layers/tile/buildings/BuildingLayer.java b/vtm/src/org/oscim/layers/tile/buildings/BuildingLayer.java index 3c3bbfc2..402ba257 100644 --- a/vtm/src/org/oscim/layers/tile/buildings/BuildingLayer.java +++ b/vtm/src/org/oscim/layers/tile/buildings/BuildingLayer.java @@ -2,6 +2,7 @@ * Copyright 2013 Hannes Janetzek * Copyright 2016-2017 devemux86 * Copyright 2016 Robin Boldt + * Copyright 2017 Gustl22 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -74,18 +75,24 @@ public class BuildingLayer extends Layer implements TileLoaderThemeHook { ExtrusionStyle extrusion = (ExtrusionStyle) style.current(); - int height = 0; - int minHeight = 0; + int height = 0; // cm + int minHeight = 0; // cm String v = element.tags.getValue(Tag.KEY_HEIGHT); if (v != null) - height = (int) Float.parseFloat(v); + height = (int) (Float.parseFloat(v) * 100); + else { + // FIXME load from theme or decode tags to generalize level/height tags + if ((v = element.tags.getValue(Tag.KEY_BUILDING_LEVELS)) != null) + height = (int) (Float.parseFloat(v) * 280); // 2.8m level height + } v = element.tags.getValue(Tag.KEY_MIN_HEIGHT); if (v != null) - minHeight = (int) Float.parseFloat(v); + minHeight = (int) (Float.parseFloat(v) * 100); if (height == 0) + // FIXME ignore buildings containing building parts height = extrusion.defaultHeight * 100; ExtrusionBuckets ebs = get(tile); diff --git a/vtm/src/org/oscim/tiling/source/mvt/TileDecoder.java b/vtm/src/org/oscim/tiling/source/mvt/TileDecoder.java index 6ab2df29..356fb9fc 100644 --- a/vtm/src/org/oscim/tiling/source/mvt/TileDecoder.java +++ b/vtm/src/org/oscim/tiling/source/mvt/TileDecoder.java @@ -1,6 +1,7 @@ /* * Copyright 2013 Hannes Janetzek - * Copyright 2016 devemux86 + * Copyright 2016-2017 devemux86 + * Copyright 2017 Gustl22 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -23,6 +24,7 @@ import org.oscim.core.Tag; import org.oscim.core.Tile; import org.oscim.tiling.ITileDataSink; import org.oscim.tiling.source.PbfDecoder; +import org.oscim.utils.math.MathUtils; import org.oscim.utils.pool.Inlist; import org.oscim.utils.pool.Pool; import org.slf4j.Logger; @@ -250,6 +252,17 @@ public class TileDecoder extends PbfDecoder { if (!hasName && fallbackName != null) f.elem.tags.add(new Tag(Tag.KEY_NAME, fallbackName, false)); + // Calculate height of building parts + if (!f.elem.tags.containsKey(Tag.KEY_HEIGHT)) { + if (f.elem.tags.containsKey(Tag.KEY_VOLUME) + && f.elem.tags.containsKey(Tag.KEY_AREA)) { + float volume = Float.parseFloat(f.elem.tags.getValue(Tag.KEY_VOLUME)); + float area = Float.parseFloat(f.elem.tags.getValue(Tag.KEY_AREA)); + String heightStr = String.valueOf(MathUtils.round2(volume / area)); + f.elem.tags.add(new Tag(Tag.KEY_HEIGHT, heightStr, false)); + } + } + // FIXME extract layer tag here f.elem.setLayer(5); mMapDataCallback.process(f.elem); diff --git a/vtm/src/org/oscim/tiling/source/oscimap4/TileDecoder.java b/vtm/src/org/oscim/tiling/source/oscimap4/TileDecoder.java index 436aa4ce..11adc365 100644 --- a/vtm/src/org/oscim/tiling/source/oscimap4/TileDecoder.java +++ b/vtm/src/org/oscim/tiling/source/oscimap4/TileDecoder.java @@ -1,6 +1,7 @@ /* * Copyright 2013 Hannes Janetzek - * Copyright 2016 devemux86 + * Copyright 2016-2017 devemux86 + * Copyright 2017 Gustl22 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -24,6 +25,7 @@ import org.oscim.core.TagSet; import org.oscim.core.Tile; import org.oscim.tiling.ITileDataSink; import org.oscim.tiling.source.PbfDecoder; +import org.oscim.utils.math.MathUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -220,13 +222,15 @@ public class TileDecoder extends PbfDecoder { // FIXME filter out all variable tags // might depend on theme though if (Tag.KEY_NAME.equals(key) - || Tag.KEY_HEIGHT.equals(key) - || Tag.KEY_MIN_HEIGHT.equals(key) || Tag.KEY_HOUSE_NUMBER.equals(key) || Tag.KEY_REF.equals(key) || Tag.KEY_ELE.equals(key)) tag = new Tag(key, val, false); - else + else if (Tag.KEY_HEIGHT.equals(key) + || Tag.KEY_MIN_HEIGHT.equals(key)) { + // Reformat values to established meters in OSM + tag = new Tag(key, String.valueOf(MathUtils.round2(Float.valueOf(val) / 100)), false); + } else tag = new Tag(key, val, false, true); mTileTags.add(tag); diff --git a/vtm/src/org/oscim/utils/math/MathUtils.java b/vtm/src/org/oscim/utils/math/MathUtils.java index c50b450d..a7f4576f 100644 --- a/vtm/src/org/oscim/utils/math/MathUtils.java +++ b/vtm/src/org/oscim/utils/math/MathUtils.java @@ -295,6 +295,10 @@ public class MathUtils { return (int) (x + BIG_ENOUGH_ROUND) - BIG_ENOUGH_INT; } + public static float round2(float value) { + return Math.round(value * 100) / 100f; + } + /** * Returns the closest integer to the specified float. This method will only * properly round floats that are positive.