public static int getIdOf(Graph g, double latitude, double longitude) {
   int s = g.getNodes();
   NodeAccess na = g.getNodeAccess();
   for (int i = 0; i < s; i++) {
     if (Math.abs(na.getLatitude(i) - latitude) < 1e-4
         && Math.abs(na.getLongitude(i) - longitude) < 1e-4) {
       return i;
     }
   }
   return -1;
 }
Exemplo n.º 2
0
  void queryIndex(Graph g, LocationIndex idx, double lat, double lon, double expectedDist) {
    QueryResult res = idx.findClosest(lat, lon, EdgeFilter.ALL_EDGES);
    if (!res.isValid()) {
      errors.add("node not found for " + lat + "," + lon);
      return;
    }

    GHPoint found = res.getSnappedPoint();
    double dist = distCalc.calcDist(lat, lon, found.lat, found.lon);
    if (Math.abs(dist - expectedDist) > .1) {
      errors.add(
          "queried lat,lon="
              + (float) lat
              + ","
              + (float) lon
              + " (found: "
              + (float) found.lat
              + ","
              + (float) found.lon
              + ")"
              + "\n   expected distance:"
              + expectedDist
              + ", but was:"
              + dist);
    }
  }
 public boolean containsLatitude(Graph g, EdgeIterator iter, double latitude) {
   NodeAccess na = g.getNodeAccess();
   while (iter.next()) {
     if (Math.abs(na.getLatitude(iter.getAdjNode()) - latitude) < 1e-4) return true;
   }
   return false;
 }
Exemplo n.º 4
0
  public TestAlgoCollector assertDistance(
      AlgoHelperEntry algoEntry, List<QueryResult> queryList, OneRun oneRun) {
    List<Path> altPaths = new ArrayList<Path>();
    QueryGraph queryGraph = new QueryGraph(algoEntry.getQueryGraph());
    queryGraph.lookup(queryList);
    AlgorithmOptions opts = algoEntry.opts;
    FlagEncoder encoder = opts.getFlagEncoder();
    if (encoder.supports(TurnWeighting.class))
      algoEntry.setAlgorithmOptions(
          AlgorithmOptions.start(opts)
              .weighting(
                  new TurnWeighting(
                      opts.getWeighting(),
                      opts.getFlagEncoder(),
                      (TurnCostExtension) queryGraph.getExtension()))
              .build());

    for (int i = 0; i < queryList.size() - 1; i++) {
      RoutingAlgorithm algo = algoEntry.createAlgo(queryGraph);
      Path path =
          algo.calcPath(queryList.get(i).getClosestNode(), queryList.get(i + 1).getClosestNode());
      // System.out.println(path.calcInstructions().createGPX("temp", 0, "GMT"));
      altPaths.add(path);
    }

    PathMerger pathMerger =
        new PathMerger().setCalcPoints(true).setSimplifyResponse(false).setEnableInstructions(true);
    AltResponse rsp = new AltResponse();
    pathMerger.doWork(rsp, altPaths, trMap.getWithFallBack(Locale.US));

    if (rsp.hasErrors()) {
      errors.add(
          algoEntry
              + " response contains errors. Expected distance: "
              + rsp.getDistance()
              + ", expected points: "
              + oneRun
              + ". "
              + queryList
              + ", errors:"
              + rsp.getErrors());
      return this;
    }

    PointList pointList = rsp.getPoints();
    double tmpDist = pointList.calcDistance(distCalc);
    if (Math.abs(rsp.getDistance() - tmpDist) > 2) {
      errors.add(
          algoEntry
              + " path.getDistance was  "
              + rsp.getDistance()
              + "\t pointList.calcDistance was "
              + tmpDist
              + "\t (expected points "
              + oneRun.getLocs()
              + ", expected distance "
              + oneRun.getDistance()
              + ") "
              + queryList);
    }

    if (Math.abs(rsp.getDistance() - oneRun.getDistance()) > 2) {
      errors.add(
          algoEntry
              + " returns path not matching the expected distance of "
              + oneRun.getDistance()
              + "\t Returned was "
              + rsp.getDistance()
              + "\t (expected points "
              + oneRun.getLocs()
              + ", was "
              + pointList.getSize()
              + ") "
              + queryList);
    }

    // There are real world instances where A-B-C is identical to A-C (in meter precision).
    if (Math.abs(pointList.getSize() - oneRun.getLocs()) > 1) {
      errors.add(
          algoEntry
              + " returns path not matching the expected points of "
              + oneRun.getLocs()
              + "\t Returned was "
              + pointList.getSize()
              + "\t (expected distance "
              + oneRun.getDistance()
              + ", was "
              + rsp.getDistance()
              + ") "
              + queryList);
    }
    return this;
  }