コード例 #1
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;
  }
コード例 #2
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;
  }
コード例 #3
0
ファイル: GraphHopper.java プロジェクト: rchampa/graphhopper
 /** For testing */
 GraphHopper(GraphStorage g) {
   this();
   this.graph = g;
   initIndex();
 }