Support of extrusions in BuildingLayer on Mapzen maps (#419)

+ Tag add "levels"
+ BuildingLayer: support extrusions with height and levels, string unit in meters
+ Support height for Mapzen building_parts
+ Support of building parts in default theme and mapzen
This commit is contained in:
Gustl22 2017-10-02 15:21:42 +02:00 committed by Emux
parent 233f0c4f7e
commit fa658bd1f0
9 changed files with 111 additions and 28 deletions

View File

@ -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));
}
}
}
}

View File

@ -560,13 +560,25 @@
</m> -->
<!-- building -->
<m k="building">
<m zoom-min="14">
<m closed="yes">
<area fade="14" use="building" />
<m k="building|building:part">
<m k="building">
<m zoom-min="14">
<m closed="yes">
<area fade="14" use="building" />
</m>
<m closed="no">
<line fade="14" use="building" />
</m>
</m>
<m closed="no">
<line fade="14" use="building" />
</m>
<m k="building:part">
<m zoom-min="16">
<m closed="yes">
<area fade="16" use="building" />
</m>
<m closed="no">
<line fade="16" use="building" />
</m>
</m>
</m>
<m zoom-min="17">

View File

@ -557,13 +557,25 @@
</m> -->
<!-- building -->
<m k="kind" v="building">
<m zoom-min="14">
<m closed="yes">
<area fade="14" use="building" />
<m k="kind" v="building|building_part">
<m v="building">
<m zoom-min="14">
<m closed="yes">
<area fade="14" use="building" />
</m>
<m closed="no">
<line fade="14" use="building" />
</m>
</m>
<m closed="no">
<line fade="14" use="building" />
</m>
<m v="building_part">
<m zoom-min="16">
<m closed="yes">
<area fade="16" use="building" />
</m>
<m closed="no">
<line fade="16" use="building" />
</m>
</m>
</m>
<m zoom-min="17">

View File

@ -556,13 +556,25 @@
</m> -->
<!-- building -->
<m k="building">
<m zoom-min="14">
<m closed="yes">
<area fade="14" use="building" />
<m k="building|building:part">
<m k="building">
<m zoom-min="14">
<m closed="yes">
<area fade="14" use="building" />
</m>
<m closed="no">
<line fade="14" use="building" />
</m>
</m>
<m closed="no">
<line fade="14" use="building" />
</m>
<m k="building:part">
<m zoom-min="16">
<m closed="yes">
<area fade="16" use="building" />
</m>
<m closed="no">
<line fade="16" use="building" />
</m>
</m>
</m>
<m zoom-min="17">

View File

@ -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";

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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.