Search in sources :

Example 21 with GTFSFeed

use of com.conveyal.gtfs.GTFSFeed in project graphhopper by graphhopper.

the class TransfersTest method init.

@BeforeAll
public void init() throws IOException {
    GTFSFeed gtfsFeed1 = new GTFSFeed();
    gtfsFeed1.loadFromZipfileOrDirectory(new File("files/sample-feed"), "");
    sampleFeed = new Transfers(gtfsFeed1);
    GTFSFeed gtfsFeed2 = new GTFSFeed();
    gtfsFeed2.loadFromZipfileOrDirectory(new File("files/another-sample-feed"), "");
    anotherSampleFeed = new Transfers(gtfsFeed2);
}
Also used : GTFSFeed(com.conveyal.gtfs.GTFSFeed) File(java.io.File) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 22 with GTFSFeed

use of com.conveyal.gtfs.GTFSFeed in project graphhopper by graphhopper.

the class PtLocationSnapper method findByStopId.

private Snap findByStopId(GHStationLocation station, int indexForErrorMessage) {
    for (Map.Entry<String, GTFSFeed> entry : gtfsStorage.getGtfsFeeds().entrySet()) {
        final Integer node = gtfsStorage.getStationNodes().get(new GtfsStorage.FeedIdWithStopId(entry.getKey(), station.stop_id));
        if (node != null) {
            Stop stop = gtfsStorage.getGtfsFeeds().get(entry.getKey()).stops.get(station.stop_id);
            final Snap stationSnap = new Snap(stop.stop_lat, stop.stop_lon);
            stationSnap.setClosestNode(node);
            return stationSnap;
        }
    }
    throw new PointNotFoundException("Cannot find station: " + station.stop_id, indexForErrorMessage);
}
Also used : Stop(com.conveyal.gtfs.model.Stop) PointNotFoundException(com.graphhopper.util.exceptions.PointNotFoundException) Map(java.util.Map) GTFSFeed(com.conveyal.gtfs.GTFSFeed) Snap(com.graphhopper.storage.index.Snap)

Example 23 with GTFSFeed

use of com.conveyal.gtfs.GTFSFeed in project graphhopper by graphhopper.

the class GtfsStorage method loadGtfsFromZipFileOrDirectory.

void loadGtfsFromZipFileOrDirectory(String id, File zipFileOrDirectory) {
    File dbFile = new File(dir.getLocation() + "/" + id);
    try {
        Files.deleteIfExists(dbFile.toPath());
        GTFSFeed feed = new GTFSFeed(dbFile);
        feed.loadFromFileAndLogErrors(zipFileOrDirectory);
        this.gtfsFeeds.put(id, feed);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    this.gtfsFeedIds.add(id);
}
Also used : IOException(java.io.IOException) File(java.io.File) GTFSFeed(com.conveyal.gtfs.GTFSFeed)

Example 24 with GTFSFeed

use of com.conveyal.gtfs.GTFSFeed in project graphhopper by graphhopper.

the class GtfsStorage method loadExisting.

boolean loadExisting() {
    File file = new File(dir.getLocation() + "/transit_schedule");
    if (!file.exists()) {
        return false;
    }
    this.data = DBMaker.newFileDB(file).transactionDisable().mmapFileEnable().readOnly().make();
    init();
    for (String gtfsFeedId : this.gtfsFeedIds) {
        File dbFile = new File(dir.getLocation() + "/" + gtfsFeedId);
        if (!dbFile.exists()) {
            throw new RuntimeException(String.format("The mapping of the gtfsFeeds in the transit_schedule DB does not reflect the files in %s. " + "dbFile %s is missing.", dir.getLocation(), dbFile.getName()));
        }
        GTFSFeed feed = new GTFSFeed(dbFile);
        this.gtfsFeeds.put(gtfsFeedId, feed);
    }
    postInit();
    return true;
}
Also used : File(java.io.File) GTFSFeed(com.conveyal.gtfs.GTFSFeed)

Example 25 with GTFSFeed

use of com.conveyal.gtfs.GTFSFeed in project graphhopper by graphhopper.

the class GtfsStorage method close.

public void close() {
    if (!isClosed) {
        isClosed = true;
        data.close();
        for (GTFSFeed feed : gtfsFeeds.values()) {
            feed.close();
        }
    }
}
Also used : GTFSFeed(com.conveyal.gtfs.GTFSFeed)

Aggregations

GTFSFeed (com.conveyal.gtfs.GTFSFeed)25 Fun (org.mapdb.Fun)12 StopTime (com.conveyal.gtfs.model.StopTime)8 GtfsRealtime (com.google.transit.realtime.GtfsRealtime)8 File (java.io.File)8 java.util (java.util)7 Collectors (java.util.stream.Collectors)7 IntHashSet (com.carrotsearch.hppc.IntHashSet)6 Trip (com.conveyal.gtfs.model.Trip)6 Stream (java.util.stream.Stream)6 StreamSupport (java.util.stream.StreamSupport)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 com.conveyal.gtfs.model (com.conveyal.gtfs.model)5 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)5 Stop (org.onebusaway.gtfs.model.Stop)5 GtfsBundle (org.opentripplanner.graph_builder.model.GtfsBundle)5 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)5 IntArrayList (com.carrotsearch.hppc.IntArrayList)4 IntLongHashMap (com.carrotsearch.hppc.IntLongHashMap)4