本文整理汇总了Java中com.graphhopper.util.shapes.GHPoint类的典型用法代码示例。如果您正苦于以下问题:Java GHPoint类的具体用法?Java GHPoint怎么用?Java GHPoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GHPoint类属于com.graphhopper.util.shapes包,在下文中一共展示了GHPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: route
import com.graphhopper.util.shapes.GHPoint; //导入依赖的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: value
import com.graphhopper.util.shapes.GHPoint; //导入依赖的package包/类
@Override
public OptionalDouble value(LocalDateTime time, GHPoint start,
GHPoint place, TimeRange<LocalDateTime> limits,
long minWalkingTime) {
Optional<PathWrapper> path = routingHelper
.route(start, place, time, weightingType).get();
if (path.isPresent()) {
long timeWalk = Math.max(path.get().getTime() - minWalkingTime, 0);
lastWalkingTime = timeWalk;
if (time.plus(timeWalk, ChronoUnit.MILLIS)
.compareTo(limits.getTo()) <= 0) {
// return getThermalComfort().value(time);
return OptionalDouble.of(path.get().getRouteWeight());
}
}
return OptionalDouble.empty();
}
示例3: mapMatchingTest
import com.graphhopper.util.shapes.GHPoint; //导入依赖的package包/类
@Test
public void mapMatchingTest() {
GraphHopperStorage graph = hopper.getGraphHopperStorage();
LocationIndexMatch locationIndex = new LocationIndexMatch(graph,
(LocationIndexTree) hopper.getLocationIndex());
MapMatching mapMatching = new MapMatching(graph, locationIndex,
encoder.getEncoder(EncodingManager.CAR));
mapMatching.setSeparatedSearchDistance(30);
// printOverview(graph, hopper.getLocationIndex(), 51.358735, 12.360574,
// 500);
List<GPXEntry> inputGPXEntries = createRandomGPXEntries(new GHPoint(
51.358735, 12.360574), new GHPoint(51.358594, 12.360032));
MatchResult mr = mapMatching.doWork(inputGPXEntries);
}
示例4: testDistantPoints
import com.graphhopper.util.shapes.GHPoint; //导入依赖的package包/类
/**
* This test is to check behavior over large separated routes: it should
* work if the user sets the maxVisitedNodes large enough. Input path:
* https://graphhopper.com/maps/?point=51.23%2C12.18&point=51.45%2C12.59&layer=Lyrk
*/
@Test
public void testDistantPoints() {
// OK with 1000 visited nodes:
MapMatching mapMatching = new MapMatching(hopper, algoOptions);
List<GPXEntry> inputGPXEntries = createRandomGPXEntries(
new GHPoint(51.23, 12.18),
new GHPoint(51.45, 12.59));
MatchResult mr = mapMatching.doWork(inputGPXEntries);
assertEquals(57650, mr.getMatchLength(), 1);
assertEquals(2747796, mr.getMatchMillis(), 1);
// not OK when we only allow a small number of visited nodes:
AlgorithmOptions opts = AlgorithmOptions.start(algoOptions).maxVisitedNodes(1).build();
mapMatching = new MapMatching(hopper, opts);
try {
mr = mapMatching.doWork(inputGPXEntries);
fail("Expected sequence to be broken due to maxVisitedNodes being too small");
} catch (RuntimeException e) {
assertTrue(e.getMessage().startsWith("Sequence is broken for submitted track"));
}
}
示例5: calculateMatrixOneByOne
import com.graphhopper.util.shapes.GHPoint; //导入依赖的package包/类
public MatrixResult calculateMatrixOneByOne(GHPoint[] points) {
int n = points.length;
MatrixResult ret = new MatrixResult(n);
for (int fromIndex = 0; fromIndex < n; fromIndex++) {
// Loop over TO in reverse order so the first A-B we process doesn't have the same
// location for FROM and TO - this makes it quicker to debug as the first call is no longer a 'dummy' one.
for (int toIndex = n - 1; toIndex >= 0; toIndex--) {
GHPoint from = points[fromIndex];
GHPoint to = points[toIndex];
GHResponse rsp = getResponse(from, to);
if (rsp == null) {
continue;
}
ret.setDistanceMetres(fromIndex, toIndex, rsp.getDistance());
ret.setTimeMilliseconds(fromIndex, toIndex, rsp.getTime());
}
}
return ret;
}
示例6: ExamplePointsData
import com.graphhopper.util.shapes.GHPoint; //导入依赖的package包/类
ExamplePointsData(int n){
Random r = new Random(123);
points = new GHPoint[n];
// get source points
GHPoint[] src = createPoints();
for(int i =0 ; i< n ; i++){
if(i< src.length){
points[i] = src[i];
}else{
int index = r.nextInt(src.length);
GHPoint srcPnt = src[index];
points[i] = new GHPoint(srcPnt.lat + 0.001*r.nextDouble() - 0.0005, srcPnt.lon+ 0.001*r.nextDouble() - 0.0005);
}
}
}
示例7: calculateJTSRouteGeom
import com.graphhopper.util.shapes.GHPoint; //导入依赖的package包/类
public static Geometry calculateJTSRouteGeom(CHMatrixGeneration cmg,LatLong from, LatLong to) {
GHResponse rsp = cmg.getResponse(new GHPoint(from.getLatitude(), from.getLongitude()), new GHPoint(to.getLatitude(), to.getLongitude()));
if (rsp==null || rsp.hasErrors()) {
return null;
}
PointList pointList = rsp.getPoints();
int n = pointList.size();
if (n < 2) {
return null;
}
Coordinate[] coords = new Coordinate[n];
for (int i = 0; i < n; i++) {
coords[i] = new Coordinate(pointList.getLongitude(i), pointList.getLatitude(i));
}
GeometryFactory factory = new GeometryFactory();
Geometry geometry = factory.createLineString(coords);
return geometry;
}
示例8: getNewCarRoute
import com.graphhopper.util.shapes.GHPoint; //导入依赖的package包/类
private Route getNewCarRoute(Location from, Location to){
GHResponse rsp = queryGH(from, to);
if(rsp.hasErrors()) return null;
Route route = new Route();
// points, distance in meters and time in millis of the full path
PointList pointList = rsp.getBest().getPoints();
Iterator<GHPoint3D> pIterator = pointList.iterator();
if (!pIterator.hasNext()) return null;
GHPoint prevPoint = pIterator.next();
double remainder = 0;
Location loc = null;
while (pIterator.hasNext()){
GHPoint nextPoint = pIterator.next();
double length = getLength(prevPoint, nextPoint);
if (length == 0){
prevPoint = nextPoint;
continue;
}
long i = 0;
for (; i * cellSize + remainder < length ; i++) {
loc = getIntermediateLoc(prevPoint, nextPoint, length, i * cellSize + remainder);
if (!from.equals(loc)) {
route.addPoint(loc);
}
}
remainder = i * cellSize + remainder - length;
prevPoint = nextPoint;
}
if (!to.equals(loc)) { route.addPoint(to); }
return route;
}
示例9: doMapMatching
import com.graphhopper.util.shapes.GHPoint; //导入依赖的package包/类
public List<GPXEntry> doMapMatching(List<GPXEntry> gpxUnmatched) {
List<GPXEntry> gpxMatched = new ArrayList<GPXEntry>();
MapMatching mapMatching = new MapMatching(hopper, opts);
mapMatching.setMeasurementErrorSigma(50);
// perform map matching, return null if it fails
MatchResult mr = null;
try {
mr = mapMatching.doWork(gpxUnmatched);
}
catch (Exception ex) {
//System.out.println("MapMatching error: " + ex.getMessage());
return null;
}
// get points of matched track
Path path = mapMatching.calcPath(mr);
PointList points = path.calcPoints();
if (points != null && !points.isEmpty()) {
for (GHPoint pt : points) {
// set elevation and time to zero for now
gpxMatched.add(new FCDEntry(pt.lat, pt.lon, 0.0, 0, 0));
}
}
return gpxMatched;
}
示例10: RoutingRequest
import com.graphhopper.util.shapes.GHPoint; //导入依赖的package包/类
protected RoutingRequest(GHPoint start, GHPoint destination,
WeightingType weightingType, LocalDateTime time,
String routingAlgorithm, String encodingManager, Locale locale) {
this.start = start;
this.destination = destination;
this.weightingType = weightingType;
this.time = time;
this.routingAlgorithm = routingAlgorithm;
this.encodingManager = encodingManager;
this.locale = locale;
}
示例11: RoutingRequestBuilder
import com.graphhopper.util.shapes.GHPoint; //导入依赖的package包/类
protected RoutingRequestBuilder(GHPoint start, GHPoint destination,
WeightingType weightingType, LocalDateTime time,
String routingAlgorithm, String encodingManager, Locale locale) {
this(start, destination, weightingType, time);
this.routingAlgorithm = routingAlgorithm;
this.encodingManager = encodingManager;
this.locale = locale;
}
示例12: routePathShortest
import com.graphhopper.util.shapes.GHPoint; //导入依赖的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));
}
示例13: toJsonArray
import com.graphhopper.util.shapes.GHPoint; //导入依赖的package包/类
/**
* Serializes the {@link PointList} as JsonArray of Points, e.g.
* [[49.0118083, 8.4251357], [49.0126868, 8.4065707]].
*
* @param points
* @return
*/
public static JsonArray toJsonArray(PointList points) {
JsonArrayBuilder builder = Json.createArrayBuilder();
for (GHPoint point : points) {
builder.add(toJsonArray(point));
}
return builder.build();
}
示例14: parseGHPoint
import com.graphhopper.util.shapes.GHPoint; //导入依赖的package包/类
/**
* Parses a geo coordinate string of the form 'lat,lon' (e.g.
* '49.0118083,8.4251357') where the decimal latitude and longitude values
* are separated by a comma (','). The latitude value must be in range [-90,
* 90] and the longitude value in range [-180, 180].
*
* @param pointStr
* the string to parse, e.g. '49.0118083,8.4251357'
* @return a {@link GHPoint} instance
*
*/
public static Result<GHPoint, ParserException> parseGHPoint(
String pointStr) {
String[] components = pointStr.trim().split(",");
if (components.length != 2)
return Result
.errorOf(new ParserException("wrong number of arguments"));
double lat;
double lon;
try {
lat = Double.parseDouble(components[0]);
lon = Double.parseDouble(components[1]);
} catch (NumberFormatException e) {
return Result.errorOf(
new ParserException("failed to parse coordinate", e));
}
if (lat < -90 || lat > 90)
return Result.errorOf(new ParserException(
"latitude value is not in range [-90, 90]"));
if (lon < -180 || lon > 180)
return Result.errorOf(new ParserException(
"longitude value is not in range [-180, 180]"));
return Result.okayOf(new GHPoint(lat, lon));
}
示例15: calculatePath
import com.graphhopper.util.shapes.GHPoint; //导入依赖的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;
}