Merge pull request #1219 from Larry0ua/master
Use building entrance as a building location (handy for routing)
This commit is contained in:
commit
1b28e276c3
2 changed files with 67 additions and 13 deletions
|
@ -1,23 +1,18 @@
|
||||||
package net.osmand.osm.edit;
|
package net.osmand.osm.edit;
|
||||||
|
|
||||||
import java.util.Collection;
|
import net.osmand.data.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import net.osmand.data.Amenity;
|
|
||||||
import net.osmand.data.AmenityType;
|
|
||||||
import net.osmand.data.Building;
|
|
||||||
import net.osmand.data.City;
|
|
||||||
import net.osmand.data.City.CityType;
|
import net.osmand.data.City.CityType;
|
||||||
import net.osmand.data.LatLon;
|
|
||||||
import net.osmand.data.MapObject;
|
|
||||||
import net.osmand.data.TransportStop;
|
|
||||||
import net.osmand.osm.MapPoiTypes;
|
import net.osmand.osm.MapPoiTypes;
|
||||||
import net.osmand.osm.MapRenderingTypes;
|
import net.osmand.osm.MapRenderingTypes;
|
||||||
import net.osmand.osm.PoiCategory;
|
import net.osmand.osm.PoiCategory;
|
||||||
import net.osmand.osm.edit.OSMSettings.OSMTagKey;
|
import net.osmand.osm.edit.OSMSettings.OSMTagKey;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class EntityParser {
|
public class EntityParser {
|
||||||
|
|
||||||
public static void parseMapObject(MapObject mo, Entity e) {
|
public static void parseMapObject(MapObject mo, Entity e) {
|
||||||
|
@ -35,7 +30,13 @@ public class EntityParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mo.getLocation() == null) {
|
if (mo.getLocation() == null) {
|
||||||
LatLon l = OsmMapUtils.getCenter(e);
|
LatLon l = null;
|
||||||
|
if (mo instanceof Building) {
|
||||||
|
l = findOnlyOneEntrance(e);
|
||||||
|
}
|
||||||
|
if (l == null) {
|
||||||
|
l = OsmMapUtils.getCenter(e);
|
||||||
|
}
|
||||||
if (l != null) {
|
if (l != null) {
|
||||||
mo.setLocation(l.getLatitude(), l.getLongitude());
|
mo.setLocation(l.getLatitude(), l.getLongitude());
|
||||||
}
|
}
|
||||||
|
@ -48,6 +49,58 @@ public class EntityParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the LatLon of a main entrance point. Main entrance here is the only entrance with value 'main'. If there is
|
||||||
|
* no main entrances, but there is only one entrance of any kind in given building, it is returned.
|
||||||
|
*
|
||||||
|
* @param e building entity
|
||||||
|
* @return main entrance point location or {@code null} if no entrance found or more than one entrance
|
||||||
|
*/
|
||||||
|
private static LatLon findOnlyOneEntrance(Entity e) {
|
||||||
|
if (e instanceof Node) {
|
||||||
|
return e.getLatLon();
|
||||||
|
}
|
||||||
|
List<Node> nodes = null;
|
||||||
|
if (e instanceof Way) {
|
||||||
|
nodes = ((Way) e).getNodes();
|
||||||
|
} else if (e instanceof Relation) {
|
||||||
|
nodes = new ArrayList<>();
|
||||||
|
for (Entity member : ((Relation) e).getMembers(null)) {
|
||||||
|
if (member instanceof Way) {
|
||||||
|
nodes.addAll(((Way) member).getNodes());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nodes != null) {
|
||||||
|
int entrancesCount = 0;
|
||||||
|
Node mainEntrance = null;
|
||||||
|
Node lastEntrance = null;
|
||||||
|
|
||||||
|
for (Node node : nodes) {
|
||||||
|
String entrance = node.getTag(OSMTagKey.ENTRANCE);
|
||||||
|
if (entrance != null && !"no".equals(entrance)) {
|
||||||
|
if ("main".equals(entrance)) {
|
||||||
|
// main entrance should be only one
|
||||||
|
if (mainEntrance != null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
mainEntrance = node;
|
||||||
|
}
|
||||||
|
entrancesCount++;
|
||||||
|
lastEntrance = node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mainEntrance != null) {
|
||||||
|
return mainEntrance.getLatLon();
|
||||||
|
}
|
||||||
|
if (entrancesCount == 1) {
|
||||||
|
return lastEntrance.getLatLon();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private static void setNameFromRef(MapObject mo, Entity e) {
|
private static void setNameFromRef(MapObject mo, Entity e) {
|
||||||
String ref = e.getTag(OSMTagKey.REF);
|
String ref = e.getTag(OSMTagKey.REF);
|
||||||
if(ref != null){
|
if(ref != null){
|
||||||
|
|
|
@ -73,7 +73,8 @@ public class OSMSettings {
|
||||||
WIKIPEDIA("wikipedia"), //$NON-NLS-1$
|
WIKIPEDIA("wikipedia"), //$NON-NLS-1$
|
||||||
|
|
||||||
ADMIN_LEVEL("admin_level"), //$NON-NLS-1$
|
ADMIN_LEVEL("admin_level"), //$NON-NLS-1$
|
||||||
PUBLIC_TRANSPORT("public_transport") //$NON-NLS-1$
|
PUBLIC_TRANSPORT("public_transport"), //$NON-NLS-1$
|
||||||
|
ENTRANCE("entrance"), //$NON-NLS-1$
|
||||||
;
|
;
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
Loading…
Reference in a new issue