Search in sources :

Example 16 with DataSource

use of org.opentripplanner.datastore.DataSource in project OpenTripPlanner by opentripplanner.

the class GsDataSourceRepository method createCompositeSource.

private CompositeDataSource createCompositeSource(BlobId blobId, FileType type) {
    if (GsHelper.isRoot(blobId)) {
        return new GsDirectoryDataSource(storage, blobId, type);
    }
    if (blobId.getName().endsWith(".zip")) {
        Blob blob = storage.get(blobId);
        if (blob == null) {
            throw new IllegalArgumentException(type.text() + " not found: " + GsHelper.toUriString(blobId));
        }
        DataSource gsSource = new GsFileDataSource(blob, type);
        return new ZipStreamDataSourceDecorator(gsSource);
    }
    return new GsDirectoryDataSource(storage, blobId, type);
}
Also used : Blob(com.google.cloud.storage.Blob) ZipStreamDataSourceDecorator(org.opentripplanner.datastore.base.ZipStreamDataSourceDecorator) DataSource(org.opentripplanner.datastore.DataSource) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource)

Example 17 with DataSource

use of org.opentripplanner.datastore.DataSource in project OpenTripPlanner by opentripplanner.

the class GraphBuilder method create.

/**
 * Factory method to create and configure a GraphBuilder with all the appropriate modules to
 * build a graph from the given data source and configuration directory.
 */
public static GraphBuilder create(BuildConfig config, GraphBuilderDataSources dataSources, Graph baseGraph) {
    boolean hasOsm = dataSources.has(OSM);
    boolean hasDem = dataSources.has(DEM);
    boolean hasGtfs = dataSources.has(GTFS);
    boolean hasNetex = dataSources.has(NETEX);
    boolean hasTransitData = hasGtfs || hasNetex;
    GraphBuilder graphBuilder = new GraphBuilder(baseGraph);
    if (hasOsm) {
        List<BinaryOpenStreetMapProvider> osmProviders = Lists.newArrayList();
        for (DataSource osmFile : dataSources.get(OSM)) {
            osmProviders.add(new BinaryOpenStreetMapProvider(osmFile, config.osmCacheDataInMem));
        }
        OpenStreetMapModule osmModule = new OpenStreetMapModule(osmProviders);
        DefaultStreetEdgeFactory streetEdgeFactory = new DefaultStreetEdgeFactory();
        streetEdgeFactory.useElevationData = hasDem;
        osmModule.edgeFactory = streetEdgeFactory;
        osmModule.customNamer = config.customNamer;
        osmModule.setDefaultWayPropertySetSource(config.osmWayPropertySet);
        osmModule.skipVisibility = !config.areaVisibility;
        osmModule.platformEntriesLinking = config.platformEntriesLinking;
        osmModule.staticBikeRental = config.staticBikeRental;
        osmModule.staticBikeParkAndRide = config.staticBikeParkAndRide;
        osmModule.staticParkAndRide = config.staticParkAndRide;
        osmModule.banDiscouragedWalking = config.banDiscouragedWalking;
        osmModule.banDiscouragedBiking = config.banDiscouragedBiking;
        graphBuilder.addModule(osmModule);
        PruneFloatingIslands pruneFloatingIslands = new PruneFloatingIslands();
        pruneFloatingIslands.setPruningThresholdIslandWithoutStops(config.pruningThresholdIslandWithoutStops);
        pruneFloatingIslands.setPruningThresholdIslandWithStops(config.pruningThresholdIslandWithStops);
        graphBuilder.addModule(pruneFloatingIslands);
    }
    if (hasGtfs) {
        List<GtfsBundle> gtfsBundles = Lists.newArrayList();
        for (DataSource gtfsData : dataSources.get(GTFS)) {
            GtfsBundle gtfsBundle = new GtfsBundle((CompositeDataSource) gtfsData);
            // TODO OTP2 - In OTP2 we have deleted the transfer edges from the street graph.
            // - The new transfer generation do not take this config param into
            // - account any more. This needs some investigation and probably
            // - a fix, but we are unsure if this is used any more. The Pathways.txt
            // - and osm import replaces this functionality.
            gtfsBundle.setTransfersTxtDefinesStationPaths(config.useTransfersTxt);
            if (config.parentStopLinking) {
                gtfsBundle.linkStopsToParentStations = true;
            }
            gtfsBundle.parentStationTransfers = config.stationTransfers;
            gtfsBundle.subwayAccessTime = config.getSubwayAccessTimeSeconds();
            gtfsBundle.maxInterlineDistance = config.maxInterlineDistance;
            gtfsBundles.add(gtfsBundle);
        }
        GtfsModule gtfsModule = new GtfsModule(gtfsBundles, config.getTransitServicePeriod());
        gtfsModule.setFareServiceFactory(config.fareServiceFactory);
        graphBuilder.addModule(gtfsModule);
    }
    if (hasNetex) {
        graphBuilder.addModule(netexModule(config, dataSources.get(NETEX)));
    }
    if (hasTransitData && (hasOsm || graphBuilder.graph.hasStreets)) {
        if (config.matchBusRoutesToStreets) {
            graphBuilder.addModule(new BusRouteStreetMatcher());
        }
        graphBuilder.addModule(new TransitToTaggedStopsModule());
    }
    // This module is outside the hasGTFS conditional block because it also links things like bike rental
    // which need to be handled even when there's no transit.
    StreetLinkerModule streetLinkerModule = new StreetLinkerModule();
    streetLinkerModule.setAddExtraEdgesToAreas(config.areaVisibility);
    graphBuilder.addModule(streetLinkerModule);
    // Load elevation data and apply it to the streets.
    // We want to do run this module after loading the OSM street network but before finding transfers.
    List<ElevationGridCoverageFactory> elevationGridCoverageFactories = new ArrayList<>();
    if (config.elevationBucket != null) {
        // Download the elevation tiles from an Amazon S3 bucket
        S3BucketConfig bucketConfig = config.elevationBucket;
        File cacheDirectory = new File(dataSources.getCacheDirectory(), "ned");
        DegreeGridNEDTileSource awsTileSource = new DegreeGridNEDTileSource();
        awsTileSource.awsAccessKey = bucketConfig.accessKey;
        awsTileSource.awsSecretKey = bucketConfig.secretKey;
        awsTileSource.awsBucketName = bucketConfig.bucketName;
        elevationGridCoverageFactories.add(new NEDGridCoverageFactoryImpl(cacheDirectory, awsTileSource));
    } else if (dataSources.has(DEM)) {
        // Load the elevation from a file in the graph inputs directory
        for (DataSource demSource : dataSources.get(DEM)) {
            elevationGridCoverageFactories.add(new GeotiffGridCoverageFactoryImpl(demSource));
        }
    }
    // ElevationModule class.
    for (ElevationGridCoverageFactory factory : elevationGridCoverageFactories) {
        graphBuilder.addModule(new ElevationModule(factory, new File(dataSources.getCacheDirectory(), "cached_elevations.obj"), config.readCachedElevations, config.writeCachedElevations, config.elevationUnitMultiplier, config.distanceBetweenElevationSamples, config.includeEllipsoidToGeoidDifference, config.multiThreadElevationCalculations));
    }
    if (hasTransitData) {
        // Add links to flex areas after the streets has been split, so that also the split edges are connected
        if (OTPFeature.FlexRouting.isOn()) {
            graphBuilder.addModule(new FlexLocationsToStreetEdgesMapper());
        }
        // The stops can be linked to each other once they are already linked to the street network.
        if (!config.useTransfersTxt) {
            // This module will use streets or straight line distance depending on whether OSM data is found in the graph.
            graphBuilder.addModule(new DirectTransferGenerator(config.maxTransferDistance));
        }
        // Analyze routing between stops to generate report
        if (OTPFeature.TransferAnalyzer.isOn()) {
            graphBuilder.addModule(new DirectTransferAnalyzer(config.maxTransferDistance));
        }
    }
    if (config.dataImportReport) {
        graphBuilder.addModule(new DataImportIssuesToHTML(dataSources.getBuildReportDir(), config.maxDataImportIssuesPerFile));
    }
    return graphBuilder;
}
Also used : ElevationModule(org.opentripplanner.graph_builder.module.ned.ElevationModule) NEDGridCoverageFactoryImpl(org.opentripplanner.graph_builder.module.ned.NEDGridCoverageFactoryImpl) ArrayList(java.util.ArrayList) S3BucketConfig(org.opentripplanner.standalone.config.S3BucketConfig) GtfsModule(org.opentripplanner.graph_builder.module.GtfsModule) GeotiffGridCoverageFactoryImpl(org.opentripplanner.graph_builder.module.ned.GeotiffGridCoverageFactoryImpl) DirectTransferAnalyzer(org.opentripplanner.ext.transferanalyzer.DirectTransferAnalyzer) StreetLinkerModule(org.opentripplanner.graph_builder.module.StreetLinkerModule) TransitToTaggedStopsModule(org.opentripplanner.graph_builder.module.TransitToTaggedStopsModule) DegreeGridNEDTileSource(org.opentripplanner.graph_builder.module.ned.DegreeGridNEDTileSource) DirectTransferGenerator(org.opentripplanner.graph_builder.module.DirectTransferGenerator) OpenStreetMapModule(org.opentripplanner.graph_builder.module.osm.OpenStreetMapModule) BinaryOpenStreetMapProvider(org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider) ElevationGridCoverageFactory(org.opentripplanner.graph_builder.services.ned.ElevationGridCoverageFactory) DataSource(org.opentripplanner.datastore.DataSource) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) FlexLocationsToStreetEdgesMapper(org.opentripplanner.ext.flex.FlexLocationsToStreetEdgesMapper) PruneFloatingIslands(org.opentripplanner.graph_builder.module.PruneFloatingIslands) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) BusRouteStreetMatcher(org.opentripplanner.graph_builder.module.map.BusRouteStreetMatcher) DefaultStreetEdgeFactory(org.opentripplanner.graph_builder.services.DefaultStreetEdgeFactory) File(java.io.File)

Example 18 with DataSource

use of org.opentripplanner.datastore.DataSource in project OpenTripPlanner by opentripplanner.

the class GraphBuilderDataSources method logSkippedAndSelectedFiles.

private void logSkippedAndSelectedFiles() {
    LOG.info("Process data sources: {}", String.join(", ", store.getRepositoryDescriptions()));
    // Sort data input files by type
    LOG.info("Load files:");
    for (FileType type : FileType.values()) {
        for (DataSource source : inputData.get(type)) {
            if (type == FileType.CONFIG) {
                LOG.info(BULLET_POINT + source.detailedInfo());
            } else {
                LOG.info(BULLET_POINT + source.detailedInfo());
            }
        }
    }
    LOG.info("Skip files:");
    for (FileType type : FileType.values()) {
        for (DataSource source : skipData.get(type)) {
            LOG.info(BULLET_POINT + source.detailedInfo());
        }
    }
}
Also used : FileType(org.opentripplanner.datastore.FileType) DataSource(org.opentripplanner.datastore.DataSource) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource)

Example 19 with DataSource

use of org.opentripplanner.datastore.DataSource in project OpenTripPlanner by opentripplanner.

the class NetexConfig method netexModule.

private NetexModule netexModule(Iterable<DataSource> netexSources) {
    List<NetexBundle> netexBundles = new ArrayList<>();
    for (DataSource it : netexSources) {
        NetexBundle netexBundle = netexBundle((CompositeDataSource) it);
        netexBundles.add(netexBundle);
    }
    return new NetexModule(buildParams.netex.netexFeedId, buildParams.parentStopLinking, buildParams.stationTransfers, buildParams.getSubwayAccessTimeSeconds(), buildParams.maxInterlineDistance, buildParams.getTransitServicePeriod(), netexBundles);
}
Also used : NetexModule(org.opentripplanner.netex.NetexModule) NetexBundle(org.opentripplanner.netex.loader.NetexBundle) ArrayList(java.util.ArrayList) DataSource(org.opentripplanner.datastore.DataSource) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) ZipFileDataSource(org.opentripplanner.datastore.file.ZipFileDataSource)

Aggregations

DataSource (org.opentripplanner.datastore.DataSource)19 CompositeDataSource (org.opentripplanner.datastore.CompositeDataSource)13 Test (org.junit.Test)11 File (java.io.File)7 ArrayList (java.util.ArrayList)3 FileDataSource (org.opentripplanner.datastore.file.FileDataSource)3 IOException (java.io.IOException)2 URI (java.net.URI)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Collection (java.util.Collection)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 IOUtils (org.apache.commons.io.IOUtils)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 ConstantsForTests (org.opentripplanner.ConstantsForTests)2 GTFS (org.opentripplanner.datastore.FileType.GTFS)2 BinaryOpenStreetMapProvider (org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider)2 Blob (com.google.cloud.storage.Blob)1