Search in sources :

Example 1 with PrepareRoutingSubnetworks

use of com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks 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;
    }
}
Also used : PrepareRoutingSubnetworks(com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks) OSMReader(com.graphhopper.reader.osm.OSMReader) IOException(java.io.IOException) LocationIndex(com.graphhopper.storage.index.LocationIndex) GHPoint(com.graphhopper.util.shapes.GHPoint) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) ZipFile(java.util.zip.ZipFile) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 2 with PrepareRoutingSubnetworks

use of com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks in project graphhopper by graphhopper.

the class GraphHopper method cleanUp.

/**
 * Internal method to clean up the graph.
 */
protected void cleanUp() {
    int prevNodeCount = ghStorage.getNodes();
    PrepareRoutingSubnetworks preparation = new PrepareRoutingSubnetworks(ghStorage, encodingManager.fetchEdgeEncoders());
    preparation.setMinNetworkSize(minNetworkSize);
    preparation.setMinOneWayNetworkSize(minOneWayNetworkSize);
    preparation.doWork();
    int currNodeCount = ghStorage.getNodes();
    logger.info("edges: " + ghStorage.getAllEdges().getMaxId() + ", nodes " + currNodeCount + ", there were " + preparation.getMaxSubnetworks() + " subnetworks. removed them => " + (prevNodeCount - currNodeCount) + " less nodes");
}
Also used : PrepareRoutingSubnetworks(com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks) GHPoint(com.graphhopper.util.shapes.GHPoint)

Aggregations

PrepareRoutingSubnetworks (com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks)2 GHPoint (com.graphhopper.util.shapes.GHPoint)2 OSMReader (com.graphhopper.reader.osm.OSMReader)1 LocationIndex (com.graphhopper.storage.index.LocationIndex)1 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)1 File (java.io.File)1 IOException (java.io.IOException)1 ZipFile (java.util.zip.ZipFile)1