Search in sources :

Example 1 with InMemConstructionIndex

use of com.graphhopper.storage.index.InMemConstructionIndex in project graphhopper by graphhopper.

the class GraphHopperGtfs method importPublicTransit.

@Override
protected void importPublicTransit() {
    ptGraph = new PtGraph(getGraphHopperStorage().getDirectory(), 100);
    gtfsStorage = new GtfsStorage(getGraphHopperStorage().getDirectory());
    LineIntIndex stopIndex = new LineIntIndex(new BBox(-180.0, 180.0, -90.0, 90.0), getGraphHopperStorage().getDirectory(), "stop_index");
    if (getGtfsStorage().loadExisting()) {
        ptGraph.loadExisting();
        stopIndex.loadExisting();
    } else {
        ensureWriteAccess();
        getGtfsStorage().create();
        ptGraph.create(100);
        InMemConstructionIndex indexBuilder = new InMemConstructionIndex(IndexStructureInfo.create(new BBox(-180.0, 180.0, -90.0, 90.0), 300));
        try {
            int idx = 0;
            List<String> gtfsFiles = ghConfig.has("gtfs.file") ? Arrays.asList(ghConfig.getString("gtfs.file", "").split(",")) : Collections.emptyList();
            for (String gtfsFile : gtfsFiles) {
                getGtfsStorage().loadGtfsFromZipFileOrDirectory("gtfs_" + idx++, new File(gtfsFile));
            }
            getGtfsStorage().postInit();
            Map<String, Transfers> allTransfers = new HashMap<>();
            HashMap<String, GtfsReader> allReaders = new HashMap<>();
            getGtfsStorage().getGtfsFeeds().forEach((id, gtfsFeed) -> {
                Transfers transfers = new Transfers(gtfsFeed);
                allTransfers.put(id, transfers);
                GtfsReader gtfsReader = new GtfsReader(id, getGraphHopperStorage(), ptGraph, ptGraph, getGtfsStorage(), getLocationIndex(), transfers, indexBuilder);
                gtfsReader.connectStopsToStreetNetwork();
                LOGGER.info("Building transit graph for feed {}", gtfsFeed.feedId);
                gtfsReader.buildPtNetwork();
                allReaders.put(id, gtfsReader);
            });
            interpolateTransfers(allReaders, allTransfers);
        } catch (Exception e) {
            throw new RuntimeException("Error while constructing transit network. Is your GTFS file valid? Please check log for possible causes.", e);
        }
        ptGraph.flush();
        stopIndex.store(indexBuilder);
        stopIndex.flush();
    }
    gtfsStorage.setStopIndex(stopIndex);
    gtfsStorage.setPtGraph(ptGraph);
}
Also used : LineIntIndex(com.graphhopper.storage.index.LineIntIndex) InMemConstructionIndex(com.graphhopper.storage.index.InMemConstructionIndex) BBox(com.graphhopper.util.shapes.BBox) File(java.io.File)

Aggregations

InMemConstructionIndex (com.graphhopper.storage.index.InMemConstructionIndex)1 LineIntIndex (com.graphhopper.storage.index.LineIntIndex)1 BBox (com.graphhopper.util.shapes.BBox)1 File (java.io.File)1