use of com.graphhopper.reader.osm.OSMReader in project graphhopper by graphhopper.
the class GraphHopperGtfs method createOrLoad.
public static GraphHopperStorage createOrLoad(GHDirectory directory, EncodingManager encodingManager, PtFlagEncoder ptFlagEncoder, GtfsStorage gtfsStorage, boolean createWalkNetwork, Collection<String> gtfsFiles, Collection<String> osmFiles) {
GraphHopperStorage graphHopperStorage = new GraphHopperStorage(directory, encodingManager, false, gtfsStorage);
if (graphHopperStorage.loadExisting()) {
return graphHopperStorage;
} else {
graphHopperStorage.create(1000);
for (String osmFile : osmFiles) {
OSMReader osmReader = new OSMReader(graphHopperStorage);
osmReader.setFile(new File(osmFile));
osmReader.setCreateStorage(false);
try {
osmReader.readGraph();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
int id = 0;
for (String gtfsFile : gtfsFiles) {
try {
((GtfsStorage) graphHopperStorage.getExtension()).loadGtfsFromFile("gtfs_" + id++, new ZipFile(gtfsFile));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
if (createWalkNetwork) {
FakeWalkNetworkBuilder.buildWalkNetwork(((GtfsStorage) graphHopperStorage.getExtension()).getGtfsFeeds().values(), graphHopperStorage, ptFlagEncoder, Helper.DIST_EARTH);
}
LocationIndex walkNetworkIndex;
if (graphHopperStorage.getNodes() > 0) {
walkNetworkIndex = new LocationIndexTree(graphHopperStorage, new RAMDirectory()).prepareIndex();
} else {
walkNetworkIndex = new EmptyLocationIndex();
}
for (int i = 0; i < id; i++) {
new GtfsReader("gtfs_" + i, graphHopperStorage, gtfsStorage, ptFlagEncoder, walkNetworkIndex).readGraph();
}
// This currently needs to happen as the last step, since we cannot add new nodes after this step.
// This means that disconnected parts of the transit network are removed as well.
// If we don't want that, we need to think of something.
new PrepareRoutingSubnetworks(graphHopperStorage, Collections.singletonList(ptFlagEncoder)).doWork();
graphHopperStorage.flush();
return graphHopperStorage;
}
}
Aggregations