Skip to content
Snippets Groups Projects
Commit 8433bbe1 authored by lazarog98's avatar lazarog98
Browse files

Merge branch '10-split-overlappiing-segments' into 'main'

Resolve "Split overlappiing segments"

Closes #10

See merge request !28
parents 56f9d22d 4f5e40f6
No related branches found
No related tags found
1 merge request!28Resolve "Split overlappiing segments"
...@@ -41,7 +41,7 @@ public class OSMParser { ...@@ -41,7 +41,7 @@ public class OSMParser {
if (OSMJsonUtils.isWay(dto)) { if (OSMJsonUtils.isWay(dto)) {
OSMJsonWayDto wayDto = (OSMJsonWayDto) dto; OSMJsonWayDto wayDto = (OSMJsonWayDto) dto;
if (SegmentUtils.isSegmentDrivable(wayDto)) { if (SegmentUtils.isSegmentDrivable(wayDto)) {
SegmentUtils.markEndNodes(wayDto); SegmentUtils.noteNodeOccurrences(wayDto);
} }
} }
} }
...@@ -72,6 +72,11 @@ public class OSMParser { ...@@ -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) { private void createSegment(OSMJsonWayDto dto, ArrayList<Long> geometry) {
long osmId = dto.getOsmId(); long osmId = dto.getOsmId();
ArrayList<Coordinates> line = null; ArrayList<Coordinates> line = null;
......
...@@ -12,7 +12,8 @@ import static de.fuberlin.navigator.protos.map_builder.RoadCategory.*; ...@@ -12,7 +12,8 @@ import static de.fuberlin.navigator.protos.map_builder.RoadCategory.*;
public class SegmentUtils { public class SegmentUtils {
// this is a hash-map to allow us to check if a node is a start/end node in linear time // this is a hash-map to allow us to check if a node is a start/end node in linear time
private SegmentUtils() {} 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( private static final List<String> drivableRoads = Arrays.asList(
"motorway", "motorway",
"trunk", "trunk",
...@@ -85,35 +86,39 @@ public class SegmentUtils { ...@@ -85,35 +86,39 @@ public class SegmentUtils {
return SegmentUtils.speedMap.get(roadCategory); return SegmentUtils.speedMap.get(roadCategory);
} }
public static void markEndNodes(OSMJsonWayDto element) { public static void noteNodeOccurrences(OSMJsonWayDto element) {
long[] nodes = element.getNodes(); long[] nodes = element.getNodes();
long segmentId = element.getOsmId();
long startNodeId = nodes[0]; for (long nodeId : nodes) {
long endNodeId = nodes[nodes.length - 1]; 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); int nodeIdOccurrences = nodeOccurrenceCount.get(nodeId);
SegmentUtils.endNodes.put(endNodeId, true); nodeOccurrenceCount.put(nodeId, nodeIdOccurrences + 1);
} }
public static boolean isNodeAnEndNode(long osmId) { public static boolean isNodeContainedInMultipleSegments(long osmId) {
return SegmentUtils.endNodes.containsKey(osmId); return nodeOccurrenceCount.containsKey(osmId) && nodeOccurrenceCount.get(osmId) > 1;
} }
public static ArrayList<ArrayList<Long>> splitGeometry(long[] nodes) { public static ArrayList<ArrayList<Long>> splitGeometry(long[] nodes) {
ArrayList<ArrayList<Long>> geometry = new ArrayList<>(); ArrayList<ArrayList<Long>> geometry = new ArrayList<>();
int from = -1; int from = 0;
for (int i = 0; i < nodes.length; i++) { for (int i = 0; i < nodes.length; i++) {
long nodeId = nodes[i]; long nodeId = nodes[i];
if (isNodeAnEndNode(nodeId)) { // extract node IDs only if the node occurs multiple times and is NOT an end-node
if (from == -1) { if ((isNodeContainedInMultipleSegments(nodeId) && i != 0)
from = i; || i == (nodes.length - 1)) {
}
else {
// extract node ids // extract node ids
ArrayList<Long> geometryNodeIds = extractIdsFromTo(nodes, from, i); ArrayList<Long> geometryNodeIds = extractIdsFromTo(nodes, from, i);
geometry.add(geometryNodeIds); geometry.add(geometryNodeIds);
...@@ -125,7 +130,6 @@ public class SegmentUtils { ...@@ -125,7 +130,6 @@ public class SegmentUtils {
from = i; from = i;
} }
} }
}
return geometry; return geometry;
} }
......
...@@ -17,10 +17,10 @@ public class Config { ...@@ -17,10 +17,10 @@ public class Config {
/** /**
* Bounding box, default small box inside Cottbus * Bounding box, default small box inside Cottbus
*/ */
public static float BOUNDING_BOX_MIN_LAT = 51.765120241998865f; public static float BOUNDING_BOX_MIN_LAT = 51.754092326645475f;
public static float BOUNDING_BOX_MIN_LON = 14.32669617537409f; public static float BOUNDING_BOX_MIN_LON = 14.300615062713623f;
public static float BOUNDING_BOX_MAX_LAT = 51.77116774623326f; public static float BOUNDING_BOX_MAX_LAT = 51.766591637718435f;
public static float BOUNDING_BOX_MAX_LON = 14.330334220133722f; public static float BOUNDING_BOX_MAX_LON = 14.314413070678711f;
public static void load() { public static void load() {
//The config is used for running the application in a Docker container //The config is used for running the application in a Docker container
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment