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
Branches
No related tags found
1 merge request!28Resolve "Split overlappiing segments"
......@@ -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;
......
......@@ -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;
}
}
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment