diff --git a/docker-compose.yaml b/docker-compose.yaml index c519a9a20e0c8bee02d301c7a5835dcc25e01b6b..6a81f72401703a11b800cb1894eff2eefb7d7a17 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -6,23 +6,28 @@ services: volumes: - road-network:/data/road_network - metrics:/data/metrics + - config:/data/configuration restart: on-failure ports: - 8080:8080 metric-builder: build: ../metric-builder/metricbuilder image: metric-builder:latest + restart: on-failure volumes: - road-network:/data/road_network - metrics:/data/metrics + - config:/data/configuration restart: on-failure map-builder: build: ../map-data-parser/mapbuilder image: map-builder:latest volumes: - road-network:/data/road_network + - config:/data/configuration restart: on-failure volumes: road-network: - metrics: \ No newline at end of file + metrics: + config: \ No newline at end of file diff --git a/routing-server/src/main/java/de/fuberlin/navigator/routingserver/utility/ApplyShortestPath.java b/routing-server/src/main/java/de/fuberlin/navigator/routingserver/utility/ApplyShortestPath.java index a259c2f392cb9e292b5fe468adfe40ecf63851ee..110a018aae89d37963835174aaef479252af428a 100644 --- a/routing-server/src/main/java/de/fuberlin/navigator/routingserver/utility/ApplyShortestPath.java +++ b/routing-server/src/main/java/de/fuberlin/navigator/routingserver/utility/ApplyShortestPath.java @@ -6,8 +6,6 @@ import java.util.HashSet; import java.util.List; import java.util.Random; import java.util.Set; -import java.util.Map.Entry; - import de.fuberlin.navigator.routingserver.model.*; import org.jgrapht.graph.SimpleDirectedWeightedGraph; import org.jgrapht.GraphPath; @@ -49,15 +47,15 @@ public class ApplyShortestPath { // find the shortest path GraphPath<Long, ExtendedEdge> path = getShortestPathInTime(routingRequest); - List<Point> coordinateList = covertToCoordinates(path.getVertexList()); + List<Point> coordinateList = covertToCoordinates(path); // duration of path in minutes int duration = calculateDuration(path); // length of path in meters - double length = calculateLength(path); + int length = calculateLength(path); - System.out.println("List of Point: "+Arrays.deepToString(coordinateList.toArray())); + System.out.println("List of Coordinates: "+Arrays.deepToString(coordinateList.toArray())); System.out.println("duration: " + duration + " min"); System.out.println("length of path: " + length + " meter"); } @@ -85,9 +83,9 @@ public class ApplyShortestPath { //in minutes int duration = calculateDuration(path); //in meters - int distance = (int) calculateLength(path); + int distance = calculateLength(path); - return RoutingResponse.of(covertToCoordinates(path.getVertexList()), distance, duration, daysAfterToday); + return RoutingResponse.of(covertToCoordinates(path), distance, duration, daysAfterToday); } private static GraphPath<Long, ExtendedEdge> getShortestPathInTime(RoutingRequest routingRequest){ @@ -224,36 +222,18 @@ public class ApplyShortestPath { } } - private static long CoordinatesToID(Point Point){ - // map Point of start and end point to node ID - - double lat = Point.getLat(); - double lon = Point.getLon(); - double epsilon = 0.0001; // 14m difference - - for (Entry<Long, Coordinates> node : mapper.getNodeMap().entrySet()) { - if (Math.abs(lat-node.getValue().getLat()) < epsilon) { - if (Math.abs(lon-node.getValue().getLon()) < epsilon) { - return (long) node.getKey(); - } - } - } - System.out.println("No start or end point found!"); - return 0; - } - - private static double calculateLength(GraphPath<Long, ExtendedEdge> path){ + private static int calculateLength(GraphPath<Long, ExtendedEdge> path){ double length = 0; for (ExtendedEdge edge : path.getEdgeList()) { // filtering out the newly generated edges because length cannot be accessed - if(roadnetwork.getSegmentsMap().get((long)edge.getId()) == null) continue; + if(roadnetwork.getSegmentsMap().get(edge.getId()) == null) continue; - double edgeLen = roadnetwork.getSegmentsMap().get((long)edge.getId()).getLength(); + double edgeLen = roadnetwork.getSegmentsMap().get(edge.getId()).getLength(); length += edgeLen; } - return length; + return (int)length; } private static int calculateDuration(GraphPath<Long, ExtendedEdge> path){ @@ -262,15 +242,38 @@ public class ApplyShortestPath { return durationMin; } - - private static List<Point> covertToCoordinates(List<Long> vertexList){ - // convert path consisting of node ids into path of Coordinates + private static List<Point> covertToCoordinates(GraphPath<Long, ExtendedEdge> path){ + // convert path into path of Coordinates List<Point> coordinateList = new ArrayList<>(); - for (Long nodeId : vertexList) { - double lat = mapper.getNodeMap().get(nodeId).getLat(); - double lon = mapper.getNodeMap().get(nodeId).getLon(); - coordinateList.add(new Point(lat, lon)); + + // add coordinates of generated start node + Long startNodeID = path.getStartVertex(); + double lat = mapper.getNodeMap().get(startNodeID).getLat(); + double lon = mapper.getNodeMap().get(startNodeID).getLon(); + coordinateList.add(new Point(lat, lon)); + + // add coordinates of edges + int index = 0; + for (ExtendedEdge edge : path.getEdgeList()) { + // filter out generated first and last edge, which have no geometryList + if (index == 0 || index == path.getEdgeList().size()-1) { + index ++; + continue; + } + + Segment segment = roadnetwork.getSegmentsMap().get(edge.getId()); + List<Coordinates> geometryList= segment.getGeometryList(); + for(Coordinates coordinates : geometryList){ + coordinateList.add(new Point(coordinates.getLat(), coordinates.getLon())); + } + index ++; } + + // add coordinates of generated end node + Long endNodeID = path.getEndVertex(); + lat = mapper.getNodeMap().get(endNodeID).getLat(); + lon = mapper.getNodeMap().get(endNodeID).getLon(); + coordinateList.add(new Point(lat, lon)); return coordinateList; } diff --git a/routing-server/src/main/java/de/fuberlin/navigator/routingserver/utility/Config.java b/routing-server/src/main/java/de/fuberlin/navigator/routingserver/utility/Config.java index 15d12673715bbe01edf5e9e61e148dcd8c2202d4..a825e6e6cb219cdf10c8a380fb0329839d95c596 100644 --- a/routing-server/src/main/java/de/fuberlin/navigator/routingserver/utility/Config.java +++ b/routing-server/src/main/java/de/fuberlin/navigator/routingserver/utility/Config.java @@ -22,6 +22,14 @@ public class Config { */ public static String METRICS_INPUT_PATH = "routing-server/src/main/resources/metrics.proto"; + /** + * 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 void load() { //The config is used for running the application in a Docker container String configFilePath = "/data/configuration/config.properties"; @@ -29,8 +37,13 @@ public class Config { try (FileInputStream is = new FileInputStream(configFilePath)){ props.load(is); - ROAD_NETWORK_INPUT_PATH = props.getProperty("ROAD_NETWORK_INPUT_PATH", ROAD_NETWORK_INPUT_PATH); - METRICS_INPUT_PATH = props.getProperty("METRICS_INPUT_PATH", METRICS_INPUT_PATH); + ROAD_NETWORK_INPUT_PATH = props.getProperty("ROUTING_SERVICE_ROAD_NETWORK_INPUT_PATH", ROAD_NETWORK_INPUT_PATH); + METRICS_INPUT_PATH = props.getProperty("ROUTING_SERVICE_METRICS_INPUT_PATH", METRICS_INPUT_PATH); + + BOUNDING_BOX_MIN_LAT = Float.parseFloat(props.getProperty("BOUNDING_BOX_MIN_LAT", String.valueOf(BOUNDING_BOX_MIN_LAT))); + BOUNDING_BOX_MIN_LON = Float.parseFloat(props.getProperty("BOUNDING_BOX_MIN_LON", String.valueOf(BOUNDING_BOX_MIN_LON))); + BOUNDING_BOX_MAX_LAT = Float.parseFloat(props.getProperty("BOUNDING_BOX_MAX_LAT", String.valueOf(BOUNDING_BOX_MAX_LAT))); + BOUNDING_BOX_MAX_LON = Float.parseFloat(props.getProperty("BOUNDING_BOX_MAX_LON", String.valueOf(BOUNDING_BOX_MAX_LON))); System.out.println("Config loaded."); } catch (FileNotFoundException e) { // Either way the Docker image was build wrong or this is not diff --git a/routing-server/src/main/java/de/fuberlin/navigator/routingserver/utility/MapMatcher.java b/routing-server/src/main/java/de/fuberlin/navigator/routingserver/utility/MapMatcher.java index 347d369c78593c8f63657c10eb45e25a9246dbd3..56bcce7424638b59faacc32edd529178451f5bd5 100644 --- a/routing-server/src/main/java/de/fuberlin/navigator/routingserver/utility/MapMatcher.java +++ b/routing-server/src/main/java/de/fuberlin/navigator/routingserver/utility/MapMatcher.java @@ -22,6 +22,8 @@ import de.fuberlin.navigator.protos.map_builder.RoadNetwork; import de.fuberlin.navigator.protos.map_builder.Segment; import de.fuberlin.navigator.routingserver.model.MatchedPoint; +import static de.fuberlin.navigator.routingserver.utility.Config.*; + public class MapMatcher { private static final String NOMINATIM_ENDPOINT = "https://nominatim.openstreetmap.org/search?"; @@ -45,7 +47,12 @@ public class MapMatcher { if (coordinate == null) { return AddressMatchingResponse.addressNotFound(); } - //TODO check if address is in our road network + + if (coordinate.getLat() < BOUNDING_BOX_MIN_LAT || coordinate.getLat() > BOUNDING_BOX_MAX_LAT + || coordinate.getLon() < BOUNDING_BOX_MIN_LON || coordinate.getLon() > BOUNDING_BOX_MAX_LON) { + //coordinate is not in our road network + return AddressMatchingResponse.addressNotInRoadNetwork(); + } return AddressMatchingResponse.of(coordinate); } @@ -88,29 +95,6 @@ public class MapMatcher { return new Point(latitude, longitude); } - public static String getAddress(Double lat, Double lon) throws IOException { - - String requestUrl = NOMINATIM_ENDPOINT + "q=" + lat + "," + lon + "&" + FORMAT_PARAM; - - // Send the request and parse the response - URL url = new URL(requestUrl); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - InputStream responseStream = connection.getInputStream(); - - String responseString = new String(responseStream.readAllBytes(), StandardCharsets.UTF_8); - - // Removing first and last character - // because response is in [] - responseString = responseString.substring(1, responseString.length() - 1); - - // Extract the address/ display name from the response - JSONObject responseJson = new JSONObject(responseString); - - return responseJson.getString("display_name"); - - } - /* * Function which returns the object or set of objects, * which is the start point diff --git a/routing-server/src/main/resources/config.properties b/routing-server/src/main/resources/config.properties index 9205da2100204b9b4f90b970c56c9a874fb73099..eb941c343331ad10262b5702c31f255f0d54a64f 100644 --- a/routing-server/src/main/resources/config.properties +++ b/routing-server/src/main/resources/config.properties @@ -1,3 +1,18 @@ # Standard config for Docker -ROAD_NETWORK_INPUT_PATH = /data/road_network/roadnetwork.proto -METRICS_INPUT_PATH = /data/metrics/metrics.proto \ No newline at end of file +# Bounding box around Central + South Brandenburg (about 1.2GB in size) +BOUNDING_BOX_MIN_LAT = 50.92993593954551 +BOUNDING_BOX_MIN_LON = 11.333053381241731 +BOUNDING_BOX_MAX_LAT = 52.788831211664586 +BOUNDING_BOX_MAX_LON = 14.714574575766516 + +# Routing service specific +ROUTING_SERVICE_ROAD_NETWORK_INPUT_PATH = /data/road_network/roadnetwork.proto +ROUTING_SERVICE_METRICS_INPUT_PATH = /data/metrics/metrics.proto + +# Map builder specific +MAP_BUILDER_ROAD_NETWORK_OUTPUT_PATH = /data/road_network/roadnetwork.proto + +# Metric builder specific +METRIC_BUILDER_ROAD_NETWORK_INPUT_PATH = /data/road_network/roadnetwork.proto +METRIC_BUILDER_METRICS_OUTPUT_PATH = /data/metrics/metrics.proto +METRIC_BUILDER_WEATHER_GRID_CELL_DISTANCE = 0.25