本文整理汇总了Java中com.graphhopper.GHRequest类的典型用法代码示例。如果您正苦于以下问题:Java GHRequest类的具体用法?Java GHRequest怎么用?Java GHRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GHRequest类属于com.graphhopper包,在下文中一共展示了GHRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: route
import com.graphhopper.GHRequest; //导入依赖的package包/类
/**
* Finds the optimal route between {@code from} and {@code to} at time
* {@code time} using the specified {@link WeightingType}.
*
* @param from
* the start
* @param to
* the destination
* @param time
* the start time
* @param weighting
* edge weighting to use
* @throws IllegalArgumentException
* if time is {@code null} and the weighting type is not
* {@link WeightingType.SHORTEST}
* @return the optimal route as a {@link PathWrapper} or the errors returned
* by GraphHopper
*/
public Result<PathWrapper, List<Throwable>> route(GHPoint from, GHPoint to,
LocalDateTime time, WeightingType weighting) {
if (time == null && weighting != WeightingType.SHORTEST)
throw new IllegalArgumentException(
"if time is null then the weighting type must be 'WeightingType.SHORTEST'");
GHRequest req = new GHRequest(from, to)
.setWeighting(weighting.toString()).setVehicle(encodingManager)
.setLocale(locale).setAlgorithm(routingAlgorithm);
GHResponse rsp;
if (time != null) {
rsp = hopper.route(req, time);
} else {
rsp = hopper.route(req);
}
if (rsp.hasErrors())
return Result.errorOf(rsp.getErrors());
else
return Result.okayOf(rsp.getBest());
}
示例2: calcRoute
import com.graphhopper.GHRequest; //导入依赖的package包/类
private void calcRoute() {
if(hopper == null) {
loadGraphHopper();
}
// simple configuration of the request object, see the GraphHopperServlet classs for more possibilities.
GHRequest req = new GHRequest(start.getLat(), start.getLon(), goal.getLat(), goal.getLon()).
setWeighting("fastest").
setVehicle("car").
setLocale(Locale.US);
GHResponse rsp = hopper.route(req);
// first check for errors
if(rsp.hasErrors()) {
throw new IllegalArgumentException("Could not calculate route. Check coordinates.", rsp.getErrors().get(0));
}
pathWrapper = rsp.getBest();
}
示例3: queryGH
import com.graphhopper.GHRequest; //导入依赖的package包/类
/**
* Requests a (car) route from GH.
* @param from starting location
* @param to destination
* @return the answer from GH
*/
private GHResponse queryGH(Location from, Location to){
GHRequest req = new GHRequest(from.getLat(), from.getLon(), to.getLat(), to.getLon())
.setWeighting("shortest")
.setVehicle("car");
return GraphHopperManager.getHopper().route(req);
}
示例4: RoutingResponse
import com.graphhopper.GHRequest; //导入依赖的package包/类
public RoutingResponse(RoutingRequest request, GHRequest ghRequest,
GHResponse ghResponse, List<Path> paths) {
this.request = request;
this.ghRequest = ghRequest;
this.ghResponse = ghResponse;
this.paths = paths;
}
示例5: routePaths
import com.graphhopper.GHRequest; //导入依赖的package包/类
/**
* Calculates the path from specified request visiting the specified
* locations.
*
* @param request
* @param time
* @return the {@link GHResponse} and a list of the found paths
*/
public Pair<GHResponse, List<Path>> routePaths(GHRequest request,
LocalDateTime time) {
// add the time to the weightingMap which is passed to the
// createWeighting method
request.getHints().put("time", time.toString());
return routePaths(request);
}
示例6: routePathShortest
import com.graphhopper.GHRequest; //导入依赖的package包/类
/**
* Finds the shortest route between {@code from} and {@code to}.
*
* @param from
* the start
* @param to
* the destination
* @return the shortest route as a {@link Path} or the errors returned by
* GraphHopper
*/
public Result<Path, List<Throwable>> routePathShortest(GHPoint from,
GHPoint to) {
GHRequest req = new GHRequest(from, to)
.setWeighting(WeightingType.SHORTEST.toString())
.setVehicle(encodingManager).setLocale(locale)
.setAlgorithm(routingAlgorithm);
Pair<GHResponse, List<Path>> rsp = hopper.routePaths(req);
if (rsp.getLeft().hasErrors())
return Result.errorOf(rsp.getLeft().getErrors());
else
return Result.okayOf(rsp.getRight().get(0));
}
示例7: calculatePath
import com.graphhopper.GHRequest; //导入依赖的package包/类
public GHResponse calculatePath( final List<GHPoint> points)
{
// StopWatch sw = new StopWatch().start();
GHRequest req = new GHRequest(points).
setAlgorithm(AlgorithmOptions.DIJKSTRA_BI);
req.getHints().
put("instructions", "true");
GHResponse resp = null;
if (hopper != null)
resp = hopper.route(req);
return resp;
}
示例8: doInBackground
import com.graphhopper.GHRequest; //导入依赖的package包/类
protected GHResponse doInBackground( List<GHPoint> ... points )
{
StopWatch sw = new StopWatch().start();
GHRequest req = new GHRequest(points[0]).
setAlgorithm(AlgorithmOptions.DIJKSTRA_BI);
req.getHints().
put("instructions", "false");
GHResponse resp = hopper.route(req);
time = sw.stop().getSeconds();
return resp;
}
示例9: fetchGhResponse
import com.graphhopper.GHRequest; //导入依赖的package包/类
private GHResponse fetchGhResponse(Location fromLocation, Location toLocation, GenerationDistanceType distanceType) {
GHRequest request = new GHRequest(fromLocation.getLatitude(), fromLocation.getLongitude(),
toLocation.getLatitude(), toLocation.getLongitude())
.setVehicle("car");
GraphHopper graphHopper = distanceType.isShortest() ? shortestGraphHopper : fastestGraphHopper;
GHResponse response = graphHopper.route(request);
if (response.hasErrors()) {
throw new IllegalStateException("GraphHopper gave " + response.getErrors().size()
+ " errors. First error chained.",
response.getErrors().get(0)
);
}
return response;
}
示例10: getResponse
import com.graphhopper.GHRequest; //导入依赖的package包/类
public GHResponse getResponse(GHPoint from, GHPoint to) {
// The flag encoder's toString method returns the vehicle type
GHRequest req = new GHRequest(from, to).setVehicle(flagEncoder.toString());
GHResponse rsp = hopper.route(req);
if (rsp.hasErrors()) {
return null;
}
return rsp;
}
示例11: loadInBackground
import com.graphhopper.GHRequest; //导入依赖的package包/类
@Override
public Result loadInBackground() {
LOGI(TAG, "#loadInBackground; mStartLocation = " + mStartLocation + "; mEndLocation = " + mEndLocation);
try {
final GraphHopper hopper = new GraphHopper().forMobile();
hopper.setInMemory();
final File mapsforgeFile = AbstractMap.instance().getMapsforgeFile(getContext());
hopper.setOSMFile(mapsforgeFile.getAbsolutePath());
hopper.setGraphHopperLocation(mapsforgeFile.getParent());
hopper.setEncodingManager(new EncodingManager("car"));
hopper.importOrLoad();
final GHRequest req =
new GHRequest(
mStartLocation.getLatitude(),
mStartLocation.getLongitude(),
mEndLocation.getLatitude(),
mEndLocation.getLongitude())
.setAlgorithm(Parameters.Algorithms.DIJKSTRA_BI);
req.getHints().
put(Parameters.Routing.INSTRUCTIONS, "false");
// GHResponse resp = hopper.route(req);
final GHResponse rsp = hopper.route(req);
if (rsp.hasErrors()) {
LOGW(TAG, "GHResponse contains errors!");
List<Throwable> errors = rsp.getErrors();
for (int i = 0; i < errors.size(); i++) {
LOGE(TAG, "Graphhopper error #" + i, errors.get(i));
}
return Result.INTERNAL_ERROR;
}
// if (!rsp.isFound()) {
// LOGW(TAG, "Graphhopper cannot find route!");
// return Result.NO_ROUTE;
// }
else {
PathWrapper paths = rsp.getBest();
final List<GeoPoint> geoPoints = new LinkedList<>();
final PointList points = paths.getPoints();
double lati, longi, alti;
for (int i = 0; i < points.getSize(); i++) {
lati = points.getLatitude(i);
longi = points.getLongitude(i);
alti = points.getElevation(i);
geoPoints.add(new GeoPoint(lati, longi, alti));
}
return new Result(geoPoints);
}
} catch (OutOfMemoryError e) {
LOGE(TAG, "Graphhoper OOM", e);
return Result.INTERNAL_ERROR;
}
}
示例12: getGhRequest
import com.graphhopper.GHRequest; //导入依赖的package包/类
public GHRequest getGhRequest() {
return ghRequest;
}
示例13: doRouting
import com.graphhopper.GHRequest; //导入依赖的package包/类
private Optional<RoutingResultRecord> doRouting(int recordId, int i,
WeightingType method, Node fromNode, Node toNode, GHPoint from,
GHPoint to, LocalDateTime time) {
if (method == WeightingType.SHORTEST) {
System.out.print("Shortest Path Routing... ");
} else if (method == WeightingType.TEMPERATURE) {
System.out.print("Minimum Temperature Routing... ");
} else if (method == WeightingType.HEAT_INDEX) {
System.out.print("Minimum Heat Index Routing... ");
} else if (method == WeightingType.HEAT_INDEX_WEIGHTED) {
System.out.print("Weighted Minimum Heat Index Routing... ");
} else {
throw new IllegalStateException(
"unsupported weighting method '" + method + "'");
}
StopWatch sw = new StopWatch();
sw.start();
GHRequest reqShortest = new GHRequest(from, to)
.setWeighting(method.toString())
.setVehicle(FlagEncoderFactory.FOOT).setLocale(Locale.GERMAN)
.setAlgorithm(routingAlgo);
Pair<GHResponse, List<Path>> resShortest = this.hopper
.routePaths(reqShortest, time);
sw.stop();
System.out.println("done (" + sw.getTime() + " ms)");
GHResponse rsp = resShortest.getLeft();
if (rsp.hasErrors()) {
logger.error("rsp " + method.toString() + " hasErros = "
+ rsp.getErrors());
logger.debug("Errors: ");
rsp.getErrors().forEach(Throwable::getMessage);
rsp.getErrors().forEach(Throwable::printStackTrace);
return Optional.empty();
}
PathWrapper pathWrapper = rsp.getBest();
Path path = resShortest.getRight().get(0);
double dist = pathWrapper.getDistance();
double costsTemp = routeCostsTemperature(path, time);
double costsHeatIndex = routeCostsHeatIndex(path, time);
Duration duration = Duration.ofMillis(pathWrapper.getTime());
System.out.println("\tDistance: " + dist + ", costsTemperature: "
+ costsTemp + ", costsHeatIndex: " + costsHeatIndex
+ ", Duration: " + Utils.formatDuration(duration));
return Optional.of(new RoutingResultRecord(recordId, i, time,
method.toString(), fromNode, toNode, dist, costsTemp,
costsHeatIndex, duration.toMillis(), pathWrapper.getPoints()));
}
示例14: loadInBackground
import com.graphhopper.GHRequest; //导入依赖的package包/类
@Override
public Result loadInBackground() {
LOGI(TAG, "#loadInBackground; mStartLocation = " + mStartLocation + "; mEndLocation = " + mEndLocation);
try {
final GraphHopper hopper = new GraphHopper().forMobile();
hopper.setInMemory(true);
final File mapsforgeFile = AbstractMap.instance().getMapsforgeFile(getContext());
hopper.setOSMFile(mapsforgeFile.getAbsolutePath());
hopper.setGraphHopperLocation(mapsforgeFile.getParent());
hopper.setEncodingManager(new EncodingManager("car"));
hopper.importOrLoad();
final GHRequest req =
new GHRequest(
mStartLocation.getLatitude(),
mStartLocation.getLongitude(),
mEndLocation.getLatitude(),
mEndLocation.getLongitude())
.setVehicle("car");
final GHResponse rsp = hopper.route(req);
if (rsp.hasErrors()) {
LOGW(TAG, "GHResponse contains errors!");
List<Throwable> errors = rsp.getErrors();
for (int i = 0; i < errors.size(); i++) {
LOGE(TAG, "Graphhopper error #" + i, errors.get(i));
}
return Result.INTERNAL_ERROR;
}
if (!rsp.isFound()) {
LOGW(TAG, "Graphhopper cannot find route!");
return Result.NO_ROUTE;
} else {
final List<GeoPoint> geoPoints = new LinkedList<>();
final PointList points = rsp.getPoints();
double lati, longi, alti;
for (int i = 0; i < points.getSize(); i++) {
lati = points.getLatitude(i);
longi = points.getLongitude(i);
alti = points.getElevation(i);
geoPoints.add(new GeoPoint(lati, longi, alti));
}
return new Result(geoPoints);
}
} catch (OutOfMemoryError e) {
LOGE(TAG, "Graphhoper OOM", e);
return Result.INTERNAL_ERROR;
}
}
示例15: createRandomGPXEntries
import com.graphhopper.GHRequest; //导入依赖的package包/类
private List<GPXEntry> createRandomGPXEntries(GHPoint start, GHPoint end) {
GHResponse ghr = hopper.route(new GHRequest(start, end)
.setWeighting("fastest"));
return hopper.getEdges(0);
}