Skip to content
Snippets Groups Projects

Roadnetwork map matching

Merged lazarog98 requested to merge roadnetwork_map_matching into main
12 files
+ 323
224
Compare changes
  • Side-by-side
  • Inline
Files
12
package de.fuberlin.navigator.routingserver.controller;
package de.fuberlin.navigator.routingserver.controller;
 
import java.io.IOException;
 
import java.util.List;
 
 
import org.springframework.beans.factory.annotation.Autowired;
 
import org.springframework.http.MediaType;
 
import org.springframework.web.bind.annotation.PostMapping;
 
import org.springframework.web.bind.annotation.RequestBody;
 
import org.springframework.web.bind.annotation.RequestMethod;
 
import org.springframework.web.bind.annotation.RestController;
 
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
 
 
import de.fuberlin.navigator.protos.map_builder.Coordinates;
import de.fuberlin.navigator.routingserver.model.AdressRequest;
import de.fuberlin.navigator.routingserver.model.AdressRequest;
import de.fuberlin.navigator.routingserver.model.Coordinates;
import de.fuberlin.navigator.routingserver.model.Point;
import de.fuberlin.navigator.routingserver.model.RoutingRequest;
import de.fuberlin.navigator.routingserver.model.RoutingRequest;
import de.fuberlin.navigator.routingserver.utility.ApplyShortestPath;
import de.fuberlin.navigator.routingserver.utility.ApplyShortestPath;
import de.fuberlin.navigator.routingserver.utility.MapMatcher;
import de.fuberlin.navigator.routingserver.utility.MapMatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
@RestController
@RestController
public class RoutingController {
public class RoutingController {
@Autowired
@Autowired
private ObjectMapper mapper;
private ObjectMapper mapper;
/**
/**
* Method is a dummy for now. Answers with a list of coordinates, where each
* Method is a dummy for now. Answers with a list of coordinates, where each
* coordinate is a list of two elements
* coordinate is a list of two elements
* @return JSON of list of coordinates
*
*/
* @return JSON of list of coordinates
@PostMapping(value = "/route",
*/
consumes = MediaType.APPLICATION_JSON_VALUE,
@PostMapping(value = "/route", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
produces = MediaType.APPLICATION_JSON_VALUE)
public ArrayNode route(@RequestBody RoutingRequest routingRequest) {
public ArrayNode route(@RequestBody RoutingRequest routingRequest) {
log("/route", RequestMethod.POST, MediaType.APPLICATION_JSON, routingRequest);
log("/route", RequestMethod.POST, MediaType.APPLICATION_JSON, routingRequest);
// route generation
//route generation
List<Point> path = ApplyShortestPath.getShortestPath(routingRequest);
List<Coordinates> path = ApplyShortestPath.getShortestPath(routingRequest);
ArrayNode arrayNode = mapper.createArrayNode();
ArrayNode arrayNode = mapper.createArrayNode();
for (Point coordinate : path) {
for (Coordinates coordinate : path) {
arrayNode.add(
arrayNode.add(
mapper.createArrayNode()
mapper.createArrayNode()
.add(coordinate.getLat())
.add(coordinate.getLat())
.add(coordinate.getLon()));
.add(coordinate.getLon())
}
);
/*
 
* arrayNode.add(
 
* mapper.createArrayNode()
 
* .add(50.34565)
 
* .add(8.14056)
 
* );
 
* arrayNode.add(
 
* mapper.createArrayNode()
 
* .add(50.34551)
 
* .add(8.13901)
 
* );
 
* arrayNode.add(
 
* mapper.createArrayNode()
 
* .add(50.34551)
 
* .add(8.13901)
 
* );
 
*/
 
 
return arrayNode;
}
}
/*arrayNode.add(
mapper.createArrayNode()
.add(50.34565)
.add(8.14056)
);
arrayNode.add(
mapper.createArrayNode()
.add(50.34551)
.add(8.13901)
);
arrayNode.add(
mapper.createArrayNode()
.add(50.34551)
.add(8.13901)
);*/
return arrayNode;
}
/**
/**
* Method is a dummy for now. Answers with a coordinate pair
* Method is a dummy for now. Answers with a coordinate pair
* @return JSON coordinate pair
*
* @throws IOException
* @return JSON coordinate pair
*/
* @throws IOException
@PostMapping(value = "/adressmatching",
*/
consumes = MediaType.APPLICATION_JSON_VALUE,
@PostMapping(value = "/adressmatching", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
produces = MediaType.APPLICATION_JSON_VALUE)
public ObjectNode adressmatching(@RequestBody AdressRequest adressRequest) throws IOException {
public ObjectNode adressmatching(@RequestBody AdressRequest adressRequest) throws IOException {
log("/adressmatching", RequestMethod.POST, MediaType.APPLICATION_JSON, adressRequest);
log("/adressmatching", RequestMethod.POST, MediaType.APPLICATION_JSON, adressRequest);
// resolve adress with map matching method
// resolve adress with map matching method
Coordinates coordinates = MapMatcher.getCoordinates(adressRequest.getAdress());
Coordinates coordinates = MapMatcher.getCoordinates(adressRequest.getAdress());
ObjectNode objectNode = mapper.createObjectNode();
objectNode.set("coordinates",
mapper.createObjectNode()
ObjectNode objectNode = mapper.createObjectNode();
.put("lat", coordinates.getLat())
objectNode.put("coordinates",
.put("lon", coordinates.getLon()));
mapper.createObjectNode()
objectNode.put("error_code", 0);
.put("lat",coordinates.getLat())
.put("lon",coordinates.getLon())
return objectNode;
);
}
objectNode.put("error_code", 0);
return objectNode;
}
private void log(String endpoint, RequestMethod method, MediaType type, Object requestBody) {
private void log(String endpoint, RequestMethod method, MediaType type, Object requestBody) {
System.out.println(String.format("""
System.out.println(String.format("""
Received the following request:
Received the following request:
Endpoint: %s
Endpoint: %s
Method: %s
Method: %s
Media type: %s
Media type: %s
Body: %s
Body: %s
""", endpoint, method, type, requestBody));
""", endpoint, method, type, requestBody));
}
}
}
}
Loading