コード例 #1
0
 public BelgiumHubSuggester() {
   graphHopper = new GraphHopper().forServer();
   String osmPath = "local/osm/belgium-latest.osm.pbf";
   if (!new File(osmPath).exists()) {
     throw new IllegalStateException(
         "The osmPath ("
             + osmPath
             + ") does not exist.\n"
             + "Download the osm file from http://download.geofabrik.de/ first.");
   }
   graphHopper.setOSMFile(osmPath);
   graphHopper.setGraphHopperLocation("local/graphhopper");
   graphHopper.setEncodingManager(new EncodingManager(EncodingManager.CAR));
   graphHopper.importOrLoad();
   logger.info("GraphHopper loaded.");
 }
コード例 #2
0
ファイル: GraphHopper.java プロジェクト: rchampa/graphhopper
  private GraphHopper importOSM(String graphHopperLocation, String osmFileStr) {
    if (encodingManager == null)
      throw new IllegalStateException("No encodingManager was specified");

    setGraphHopperLocation(graphHopperLocation);
    try {
      importOSM(osmFileStr);
    } catch (IOException ex) {
      throw new RuntimeException("Cannot parse OSM file " + osmFileStr, ex);
    }
    postProcessing();
    cleanUp();
    optimize();
    prepare();
    flush();
    initIndex();
    return this;
  }
コード例 #3
0
ファイル: GraphHopper.java プロジェクト: rchampa/graphhopper
  /**
   * Opens or creates a graph. The specified args need a property 'graph' (a folder) and if no such
   * folder exist it'll create a graph from the provided osm file (property 'osm'). A property
   * 'size' is used to preinstantiate a datastructure/graph to avoid over-memory allocation or
   * reallocation (default is 5mio)
   *
   * <p>
   *
   * @param graphHopperFolder is the folder containing graphhopper files (which can be compressed
   *     too)
   */
  @Override
  public boolean load(String graphHopperFolder) {
    if (Helper.isEmpty(graphHopperFolder))
      throw new IllegalStateException("graphHopperLocation is not specified. call init before");

    if (graph != null) throw new IllegalStateException("graph is already loaded");

    if (graphHopperFolder.endsWith("-gh")) {
      // do nothing
    } else if (graphHopperFolder.endsWith(".osm") || graphHopperFolder.endsWith(".xml")) {
      throw new IllegalArgumentException("To import an osm file you need to use importOrLoad");
    } else if (graphHopperFolder.indexOf(".") < 0) {
      if (new File(graphHopperFolder + "-gh").exists()) graphHopperFolder += "-gh";
    } else {
      File compressed = new File(graphHopperFolder + ".ghz");
      if (compressed.exists() && !compressed.isDirectory()) {
        try {
          new Unzipper().unzip(compressed.getAbsolutePath(), graphHopperFolder, removeZipped);
        } catch (IOException ex) {
          throw new RuntimeException(
              "Couldn't extract file " + compressed.getAbsolutePath() + " to " + graphHopperFolder,
              ex);
        }
      }
    }
    setGraphHopperLocation(graphHopperFolder);

    GHDirectory dir = new GHDirectory(ghLocation, dataAccessType);
    if (chUsage) graph = new LevelGraphStorage(dir, encodingManager);
    else graph = new GraphStorage(dir, encodingManager);

    graph.setSegmentSize(defaultSegmentSize);
    if (!graph.loadExisting()) return false;

    postProcessing();
    initIndex();
    return true;
  }
コード例 #4
0
ファイル: GraphHopper.java プロジェクト: rchampa/graphhopper
  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;
  }