Example #1
0
  public void start(Injector injector) throws Exception {
    ResourceHandler resHandler = new ResourceHandler();
    resHandler.setDirectoriesListed(false);
    resHandler.setWelcomeFiles(new String[] {"index.html"});
    resHandler.setResourceBase(args.get("jetty.resourcebase", "./src/main/webapp"));

    server = new Server();
    // getSessionHandler and getSecurityHandler should always return null
    ServletContextHandler servHandler =
        new ServletContextHandler(
            ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);
    servHandler.setContextPath("/");

    servHandler.addServlet(new ServletHolder(new InvalidRequestServlet()), "/*");

    FilterHolder guiceFilter = new FilterHolder(injector.getInstance(GuiceFilter.class));
    servHandler.addFilter(guiceFilter, "/*", EnumSet.allOf(DispatcherType.class));

    SelectChannelConnector connector0 = new SelectChannelConnector();
    int httpPort = args.getInt("jetty.port", 8989);
    String host = args.get("jetty.host", "");
    connector0.setPort(httpPort);
    if (!host.isEmpty()) connector0.setHost(host);

    server.addConnector(connector0);

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] {resHandler, servHandler});
    server.setHandler(handlers);
    server.start();
    logger.info("Started server at HTTP " + host + ":" + httpPort);
  }
Example #2
0
 public static void main(String[] strs) throws Exception {
   CmdArgs args = CmdArgs.read(strs);
   GraphHopper hopper = new GraphHopper().init(args);
   hopper.importOrLoad();
   RoutingAlgorithmSpecialAreaTests tests = new RoutingAlgorithmSpecialAreaTests(hopper);
   if (args.getBool("graph.testIT", false)) {
     tests.start();
   }
 }
Example #3
0
  public static void main(String[] args) throws Exception {
    /*System.out.println("Inside GHServer...length of args = " + args.length);

    for(int i=0; i< args.length;i++)
    {
        System.out.println("Inside GHServer...where args[i] = " + args[i]);
    }

    System.out.println("Inside GHServer...where CmdArgs.read(args) = " + CmdArgs.read(args));*/

    new GHServer(CmdArgs.read(args)).start();
  }
Example #4
0
  @Override
  protected void configureServlets() {
    filter("*").through(HeadFilter.class);
    bind(HeadFilter.class).in(Singleton.class);

    filter("*").through(CORSFilter.class, params);
    bind(CORSFilter.class).in(Singleton.class);

    filter("*").through(IPFilter.class);
    bind(IPFilter.class)
        .toInstance(new IPFilter(args.get("jetty.whiteips", ""), args.get("jetty.blackips", "")));

    serve("/i18n*").with(I18NServlet.class);
    bind(I18NServlet.class).in(Singleton.class);

    serve("/info*").with(InfoServlet.class);
    bind(InfoServlet.class).in(Singleton.class);

    serve("/route*").with(GraphHopperServlet.class);
    bind(GraphHopperServlet.class).in(Singleton.class);

    serve("/nearest*").with(NearestServlet.class);
    bind(NearestServlet.class).in(Singleton.class);
  }
Example #5
0
  public GraphHopper init(CmdArgs args) throws IOException {
    if (!Helper.isEmpty(args.get("config", ""))) {
      CmdArgs tmp = CmdArgs.readFromConfig(args.get("config", ""), "graphhopper.config");
      // command line configuration overwrites the ones in the config file
      tmp.merge(args);
      args = tmp;
    }

    String tmpOsmFile = args.get("osmreader.osm", "");
    if (!Helper.isEmpty(tmpOsmFile)) osmFile = tmpOsmFile;

    String graphHopperFolder = args.get("graph.location", "");
    if (Helper.isEmpty(graphHopperFolder) && Helper.isEmpty(ghLocation)) {
      if (Helper.isEmpty(osmFile))
        throw new IllegalArgumentException("You need to specify an OSM file.");

      graphHopperFolder = Helper.pruneFileEnd(osmFile) + "-gh";
    }

    // graph
    setGraphHopperLocation(graphHopperFolder);
    expectedCapacity = args.getLong("graph.expectedCapacity", expectedCapacity);
    defaultSegmentSize = args.getInt("graph.dataaccess.segmentSize", defaultSegmentSize);
    String dataAccess = args.get("graph.dataaccess", "RAM_STORE").toUpperCase();
    if (dataAccess.contains("MMAP")) {
      setMemoryMapped();
    } else {
      if (dataAccess.contains("SAVE") || dataAccess.contains("INMEMORY"))
        throw new IllegalStateException(
            "configuration names for dataAccess changed. Use eg. RAM or RAM_STORE");

      if (dataAccess.contains("RAM_STORE")) setInMemory(true, true);
      else setInMemory(true, false);
    }

    if (dataAccess.contains("SYNC")) dataAccessType = new DAType(dataAccessType, true);

    sortGraph = args.getBool("graph.doSort", sortGraph);
    removeZipped = args.getBool("graph.removeZipped", removeZipped);

    // prepare
    doPrepare = args.getBool("prepare.doPrepare", doPrepare);
    String chShortcuts = args.get("prepare.chShortcuts", "no");
    boolean levelGraph =
        "true".equals(chShortcuts)
            || "fastest".equals(chShortcuts)
            || "shortest".equals(chShortcuts);
    if (levelGraph) setCHShortcuts(true, !"shortest".equals(chShortcuts));

    if (args.has("prepare.updates.periodic"))
      periodicUpdates = args.getInt("prepare.updates.periodic", periodicUpdates);

    if (args.has("prepare.updates.lazy"))
      lazyUpdates = args.getInt("prepare.updates.lazy", lazyUpdates);

    if (args.has("prepare.updates.neighbor"))
      neighborUpdates = args.getInt("prepare.updates.neighbor", neighborUpdates);

    // routing
    defaultAlgorithm = args.get("routing.defaultAlgorithm", defaultAlgorithm);

    // osm import
    wayPointMaxDistance = args.getDouble("osmreader.wayPointMaxDistance", wayPointMaxDistance);
    String type = args.get("osmreader.acceptWay", "CAR");
    encodingManager = new EncodingManager(type);
    workerThreads = args.getInt("osmreader.workerThreads", workerThreads);
    enableInstructions = args.getBool("osmreader.instructions", enableInstructions);

    // index
    preciseIndexResolution = args.getInt("index.highResolution", preciseIndexResolution);
    return this;
  }
  private void start(CmdArgs args) {
    String action = args.get("action", "").toLowerCase();
    args.put("graph.location", "./graph-cache");
    if (action.equals("import")) {
      String vehicle = args.get("vehicle", "car").toLowerCase();
      args.put("graph.flagEncoders", vehicle);
      args.put("osmreader.osm", args.get("datasource", ""));

      // standard should be to remove disconnected islands
      args.put("prepare.minNetworkSize", 200);
      args.put("prepare.minOneWayNetworkSize", 200);
      GraphHopper hopper = new GraphHopper().init(args);
      hopper.setCHEnable(false);
      hopper.importOrLoad();

    } else if (action.equals("match")) {
      GraphHopper hopper = new GraphHopper().init(args);
      hopper.setCHEnable(false);
      logger.info("loading graph from cache");
      hopper.load("./graph-cache");
      FlagEncoder firstEncoder = hopper.getEncodingManager().fetchEdgeEncoders().get(0);
      GraphHopperStorage graph = hopper.getGraphHopperStorage();

      int gpxAccuracy = args.getInt("gpxAccuracy", 15);
      String instructions = args.get("instructions", "");
      logger.info("Setup lookup index. Accuracy filter is at " + gpxAccuracy + "m");
      LocationIndexMatch locationIndex =
          new LocationIndexMatch(graph, (LocationIndexTree) hopper.getLocationIndex(), gpxAccuracy);
      MapMatching mapMatching = new MapMatching(graph, locationIndex, firstEncoder);
      mapMatching.setSeparatedSearchDistance(args.getInt("separatedSearchDistance", 500));
      mapMatching.setMaxNodesToVisit(args.getInt("maxNodesToVisit", 1000));
      mapMatching.setForceRepair(args.getBool("forceRepair", false));

      // do the actual matching, get the GPX entries from a file or via stream
      String gpxLocation = args.get("gpx", "");
      File[] files = getFiles(gpxLocation);

      logger.info("Now processing " + files.length + " files");
      StopWatch importSW = new StopWatch();
      StopWatch matchSW = new StopWatch();

      Translation tr = new TranslationMap().doImport().get(instructions);

      for (File gpxFile : files) {
        try {
          importSW.start();
          List<GPXEntry> inputGPXEntries =
              new GPXFile().doImport(gpxFile.getAbsolutePath()).getEntries();
          importSW.stop();
          matchSW.start();
          MatchResult mr = mapMatching.doWork(inputGPXEntries);
          matchSW.stop();
          System.out.println(gpxFile);
          System.out.println(
              "\tmatches:\t"
                  + mr.getEdgeMatches().size()
                  + ", gps entries:"
                  + inputGPXEntries.size());
          System.out.println(
              "\tgpx length:\t"
                  + (float) mr.getGpxEntriesLength()
                  + " vs "
                  + (float) mr.getMatchLength());
          System.out.println(
              "\tgpx time:\t"
                  + mr.getGpxEntriesMillis() / 1000f
                  + " vs "
                  + mr.getMatchMillis() / 1000f);

          String outFile = gpxFile.getAbsolutePath() + ".res.gpx";
          System.out.println("\texport results to:" + outFile);

          InstructionList il;
          if (instructions.isEmpty()) {
            il = new InstructionList(null);
          } else {
            AltResponse matchGHRsp = new AltResponse();
            Path path = mapMatching.calcPath(mr);
            new PathMerger().doWork(matchGHRsp, Collections.singletonList(path), tr);
            il = matchGHRsp.getInstructions();
          }

          new GPXFile(mr, il).doExport(outFile);
        } catch (Exception ex) {
          importSW.stop();
          matchSW.stop();
          logger.error("Problem with file " + gpxFile + " Error: " + ex.getMessage());
        }
      }
      System.out.println(
          "gps import took:" + importSW.getSeconds() + "s, match took: " + matchSW.getSeconds());

    } else if (action.equals("getbounds")) {
      String gpxLocation = args.get("gpx", "");
      File[] files = getFiles(gpxLocation);
      BBox bbox = BBox.createInverse(false);
      for (File gpxFile : files) {
        List<GPXEntry> inputGPXEntries =
            new GPXFile().doImport(gpxFile.getAbsolutePath()).getEntries();
        for (GPXEntry entry : inputGPXEntries) {
          if (entry.getLat() < bbox.minLat) {
            bbox.minLat = entry.getLat();
          }
          if (entry.getLat() > bbox.maxLat) {
            bbox.maxLat = entry.getLat();
          }
          if (entry.getLon() < bbox.minLon) {
            bbox.minLon = entry.getLon();
          }
          if (entry.getLon() > bbox.maxLon) {
            bbox.maxLon = entry.getLon();
          }
        }
      }

      System.out.println("max bounds: " + bbox);

      // show download only for small areas
      if (bbox.maxLat - bbox.minLat < 0.1 && bbox.maxLon - bbox.minLon < 0.1) {
        double delta = 0.01;
        System.out.println(
            "Get small areas via\n"
                + "wget -O extract.osm 'http://overpass-api.de/api/map?bbox="
                + (bbox.minLon - delta)
                + ","
                + (bbox.minLat - delta)
                + ","
                + (bbox.maxLon + delta)
                + ","
                + (bbox.maxLat + delta)
                + "'");
      }
    } else {
      System.out.println(
          "Usage: Do an import once, then do the matching\n"
              + "./map-matching action=import datasource=your.pbf\n"
              + "./map-matching action=match gpx=your.gpx\n"
              + "./map-matching action=match gpx=.*gpx\n\n"
              + "Or start in-built matching web service\n"
              + "./map-matching action=start-server\n\n");
    }
  }
 public static void main(String[] args) {
   new MapMatchingMain().start(CmdArgs.read(args));
 }