diff --git a/mapbuilder/src/main/java/map/builder/osm/OSMParser.java b/mapbuilder/src/main/java/map/builder/osm/OSMParser.java index b8bc958a985d8bc8e1277d8c0b9c84efaf76a7e6..98f0a71106dba8f48043d88b111f0ff43ca358b7 100644 --- a/mapbuilder/src/main/java/map/builder/osm/OSMParser.java +++ b/mapbuilder/src/main/java/map/builder/osm/OSMParser.java @@ -41,7 +41,7 @@ public class OSMParser { if (OSMJsonUtils.isWay(dto)) { OSMJsonWayDto wayDto = (OSMJsonWayDto) dto; if (SegmentUtils.isSegmentDrivable(wayDto)) { - SegmentUtils.markEndNodes(wayDto); + SegmentUtils.noteNodeOccurrences(wayDto); } } } @@ -72,6 +72,11 @@ public class OSMParser { } } + /** + * Creates a segment based on the OSM data, however, it ignores the original geometry, if the segment has been split + * @param dto + * @param geometry + */ private void createSegment(OSMJsonWayDto dto, ArrayList<Long> geometry) { long osmId = dto.getOsmId(); ArrayList<Coordinates> line = null; diff --git a/mapbuilder/src/main/java/map/builder/osm/SegmentUtils.java b/mapbuilder/src/main/java/map/builder/osm/SegmentUtils.java index 98ad594dd91291e0dc93e962f1faf1943aacdf99..8999772d7681213e8dd785ba2973d0781888bcf1 100644 --- a/mapbuilder/src/main/java/map/builder/osm/SegmentUtils.java +++ b/mapbuilder/src/main/java/map/builder/osm/SegmentUtils.java @@ -12,7 +12,8 @@ import static de.fuberlin.navigator.protos.map_builder.RoadCategory.*; public class SegmentUtils { // this is a hash-map to allow us to check if a node is a start/end node in linear time private SegmentUtils() {} - private static final HashMap<Long, Boolean> endNodes = new HashMap<>(); + // associated each node ID to the segment IDs of the segments that have this node in their geometry + private static final HashMap<Long, Integer> nodeOccurrenceCount = new HashMap<>(); private static final List<String> drivableRoads = Arrays.asList( "motorway", "trunk", @@ -85,45 +86,48 @@ public class SegmentUtils { return SegmentUtils.speedMap.get(roadCategory); } - public static void markEndNodes(OSMJsonWayDto element) { + public static void noteNodeOccurrences(OSMJsonWayDto element) { long[] nodes = element.getNodes(); + long segmentId = element.getOsmId(); - long startNodeId = nodes[0]; - long endNodeId = nodes[nodes.length - 1]; + for (long nodeId : nodes) { + addNodeToNodeMap(nodeId, segmentId); + } + } - System.out.println("marking " + startNodeId + " and " + endNodeId); + private static void addNodeToNodeMap(long nodeId, long segmentId) { + if (!nodeOccurrenceCount.containsKey(nodeId)) { + nodeOccurrenceCount.put(nodeId, 0); + } - SegmentUtils.endNodes.put(startNodeId, true); - SegmentUtils.endNodes.put(endNodeId, true); + int nodeIdOccurrences = nodeOccurrenceCount.get(nodeId); + nodeOccurrenceCount.put(nodeId, nodeIdOccurrences + 1); } - public static boolean isNodeAnEndNode(long osmId) { - return SegmentUtils.endNodes.containsKey(osmId); + public static boolean isNodeContainedInMultipleSegments(long osmId) { + return nodeOccurrenceCount.containsKey(osmId) && nodeOccurrenceCount.get(osmId) > 1; } public static ArrayList<ArrayList<Long>> splitGeometry(long[] nodes) { ArrayList<ArrayList<Long>> geometry = new ArrayList<>(); - int from = -1; + int from = 0; for (int i = 0; i < nodes.length; i++) { long nodeId = nodes[i]; - if (isNodeAnEndNode(nodeId)) { - if (from == -1) { - from = i; - } - else { - // extract node ids - ArrayList<Long> geometryNodeIds = extractIdsFromTo(nodes, from, i); - geometry.add(geometryNodeIds); - - if (from != 0) { - System.out.println("Splitting at position " + from + ", nodes:"); - } + // extract node IDs only if the node occurs multiple times and is NOT an end-node + if ((isNodeContainedInMultipleSegments(nodeId) && i != 0) + || i == (nodes.length - 1)) { + // extract node ids + ArrayList<Long> geometryNodeIds = extractIdsFromTo(nodes, from, i); + geometry.add(geometryNodeIds); - from = i; + if (from != 0) { + System.out.println("Splitting at position " + from + ", nodes:"); } + + from = i; } } diff --git a/mapbuilder/src/main/java/map/builder/utilities/Config.java b/mapbuilder/src/main/java/map/builder/utilities/Config.java index cf4bf3ba52ab2033dd06ac3475c81201578e513f..6174447353d6d1c10a05deede0d225e7d2ddf26c 100644 --- a/mapbuilder/src/main/java/map/builder/utilities/Config.java +++ b/mapbuilder/src/main/java/map/builder/utilities/Config.java @@ -17,10 +17,10 @@ public class Config { /** * Bounding box, default small box inside Cottbus */ - public static float BOUNDING_BOX_MIN_LAT = 51.765120241998865f; - public static float BOUNDING_BOX_MIN_LON = 14.32669617537409f; - public static float BOUNDING_BOX_MAX_LAT = 51.77116774623326f; - public static float BOUNDING_BOX_MAX_LON = 14.330334220133722f; + public static float BOUNDING_BOX_MIN_LAT = 51.754092326645475f; + public static float BOUNDING_BOX_MIN_LON = 14.300615062713623f; + public static float BOUNDING_BOX_MAX_LAT = 51.766591637718435f; + public static float BOUNDING_BOX_MAX_LON = 14.314413070678711f; public static void load() { //The config is used for running the application in a Docker container