public GraphBuilderTask builderFromParameters() {
if (params.build == null || params.build.isEmpty()) {
return null;
}
LOG.info("Wiring up and configuring graph builder task.");
GraphBuilderTask graphBuilder = new GraphBuilderTask();
List<File> gtfsFiles = Lists.newArrayList();
List<File> osmFiles = Lists.newArrayList();
File configFile = null;
/* For now this is adding files from all directories listed, rather than building multiple graphs. */
for (File dir : params.build) {
LOG.info("Searching for graph builder input files in {}", dir);
if ( ! dir.isDirectory() && dir.canRead()) {
LOG.error("'{}' is not a readable directory.", dir);
continue;
}
graphBuilder.setPath(dir);
for (File file : dir.listFiles()) {
switch (InputFileType.forFile(file)) {
case GTFS:
LOG.info("Found GTFS file {}", file);
gtfsFiles.add(file);
break;
case OSM:
LOG.info("Found OSM file {}", file);
osmFiles.add(file);
break;
case CONFIG:
if (!params.noEmbedConfig) {
LOG.info("Found CONFIG file {}", file);
configFile = file;
}
break;
case OTHER:
LOG.debug("Skipping file '{}'", file);
}
}
}
boolean hasOSM = ! (osmFiles.isEmpty() || params.noStreets);
boolean hasGTFS = ! (gtfsFiles.isEmpty() || params.noTransit);
if ( ! (hasOSM || hasGTFS )) {
LOG.error("Found no input files from which to build a graph in {}", params.build.toString());
return null;
}
if ( hasOSM ) {
List<OpenStreetMapProvider> osmProviders = Lists.newArrayList();
for (File osmFile : osmFiles) {
OpenStreetMapProvider osmProvider = new AnyFileBasedOpenStreetMapProviderImpl(osmFile);
osmProviders.add(osmProvider);
}
OpenStreetMapGraphBuilderImpl osmBuilder = new OpenStreetMapGraphBuilderImpl(osmProviders);
DefaultStreetEdgeFactory streetEdgeFactory = new DefaultStreetEdgeFactory();
streetEdgeFactory.useElevationData = params.elevation;
osmBuilder.edgeFactory = streetEdgeFactory;
DefaultWayPropertySetSource defaultWayPropertySetSource = new DefaultWayPropertySetSource();
osmBuilder.setDefaultWayPropertySetSource(defaultWayPropertySetSource);
osmBuilder.skipVisibility = params.skipVisibility;
graphBuilder.addGraphBuilder(osmBuilder);
graphBuilder.addGraphBuilder(new PruneFloatingIslands());
}
if ( hasGTFS ) {
List<GtfsBundle> gtfsBundles = Lists.newArrayList();
for (File gtfsFile : gtfsFiles) {
GtfsBundle gtfsBundle = new GtfsBundle(gtfsFile);
gtfsBundle.setTransfersTxtDefinesStationPaths(params.useTransfersTxt);
if (!params.noParentStopLinking) {
gtfsBundle.linkStopsToParentStations = true;
}
gtfsBundle.parentStationTransfers = params.parentStationTransfers;
gtfsBundles.add(gtfsBundle);
}
GtfsGraphBuilderImpl gtfsBuilder = new GtfsGraphBuilderImpl(gtfsBundles);
graphBuilder.addGraphBuilder(gtfsBuilder);
// When using the long distance path service, or when there is no street data,
// link stops to each other based on distance only, unless user has requested linking
// based on transfers.txt or the street network (if available).
if ((!hasOSM ) || params.longDistance) {
if (!params.useTransfersTxt) {
if (!hasOSM || !params.useStreetsForLinking) {
graphBuilder.addGraphBuilder(new StreetlessStopLinker());
}
}
}
if ( hasOSM ) {
graphBuilder.addGraphBuilder(new TransitToTaggedStopsGraphBuilderImpl());
graphBuilder.addGraphBuilder(new TransitToStreetNetworkGraphBuilderImpl());
// The stops can be linked to each other once they have links to the street network.
if (params.longDistance && params.useStreetsForLinking && !params.useTransfersTxt) {
graphBuilder.addGraphBuilder(new StreetfulStopLinker());
}
}
gtfsBuilder.setFareServiceFactory(new DefaultFareServiceFactory());
}
if (configFile != null) {
EmbeddedConfigGraphBuilderImpl embeddedConfigBuilder = new EmbeddedConfigGraphBuilderImpl();
embeddedConfigBuilder.propertiesFile = configFile;
graphBuilder.addGraphBuilder(embeddedConfigBuilder);
}
if (params.elevation) {
File cacheDirectory = new File(params.cacheDirectory, "ned");
ElevationGridCoverageFactory gcf = new NEDGridCoverageFactoryImpl(cacheDirectory);
GraphBuilder elevationBuilder = new ElevationGraphBuilderImpl(gcf);
graphBuilder.addGraphBuilder(elevationBuilder);
}
graphBuilder.serializeGraph = ( ! params.inMemory ) || params.preFlight;
return graphBuilder;
}