Search in sources :

Example 1 with StreetLinkerModule

use of org.opentripplanner.graph_builder.module.StreetLinkerModule in project OpenTripPlanner by opentripplanner.

the class TestHalfEdges method testNetworkLinker.

@Test
public void testNetworkLinker() {
    int numVerticesBefore = graph.getVertices().size();
    StreetLinkerModule ttsnm = new StreetLinkerModule();
    ttsnm.buildGraph(graph, new HashMap<Class<?>, Object>());
    int numVerticesAfter = graph.getVertices().size();
    assertEquals(4, numVerticesAfter - numVerticesBefore);
    Collection<Edge> outgoing = station1.getOutgoing();
    assertTrue(outgoing.size() == 2);
    Edge edge = outgoing.iterator().next();
    Vertex midpoint = edge.getToVertex();
    assertTrue(Math.abs(midpoint.getCoordinate().y - 40.01) < 0.00000001);
    outgoing = station2.getOutgoing();
    assertTrue(outgoing.size() == 2);
    edge = outgoing.iterator().next();
    Vertex station2point = edge.getToVertex();
    assertTrue(Math.abs(station2point.getCoordinate().x - -74.002) < 0.00000001);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetLinkerModule(org.opentripplanner.graph_builder.module.StreetLinkerModule) TemporaryFreeEdge(org.opentripplanner.routing.edgetype.TemporaryFreeEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Example 2 with StreetLinkerModule

use of org.opentripplanner.graph_builder.module.StreetLinkerModule in project OpenTripPlanner by opentripplanner.

the class ConstantsForTests method setupPortland.

private void setupPortland() {
    try {
        portlandContext = GtfsLibrary.readGtfs(new File(ConstantsForTests.PORTLAND_GTFS));
        portlandGraph = new Graph();
        GTFSPatternHopFactory factory = new GTFSPatternHopFactory(portlandContext);
        factory.run(portlandGraph);
        TransferGraphLinker linker = new TransferGraphLinker(portlandGraph);
        linker.run();
        // TODO: eliminate GTFSContext
        // this is now making a duplicate calendarservicedata but it's oh so practical
        portlandGraph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(portlandContext.getDao()));
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    StreetLinkerModule ttsnm = new StreetLinkerModule();
    ttsnm.buildGraph(portlandGraph, new HashMap<Class<?>, Object>());
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) TransferGraphLinker(org.opentripplanner.routing.edgetype.factory.TransferGraphLinker) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) File(java.io.File) StreetLinkerModule(org.opentripplanner.graph_builder.module.StreetLinkerModule) IOException(java.io.IOException)

Example 3 with StreetLinkerModule

use of org.opentripplanner.graph_builder.module.StreetLinkerModule in project OpenTripPlanner by opentripplanner.

the class GraphBuilder method forDirectory.

/**
 * Factory method to create and configure a GraphBuilder with all the appropriate modules to build a graph from
 * the files in the given directory, accounting for any configuration files located there.
 *
 * TODO parameterize with the router ID and call repeatedly to make multiple builders
 * note of all command line options this is only using  params.inMemory params.preFlight and params.build directory
 */
public static GraphBuilder forDirectory(CommandLineParameters params, File dir) {
    LOG.info("Wiring up and configuring graph builder task.");
    GraphBuilder graphBuilder = new GraphBuilder();
    List<File> gtfsFiles = Lists.newArrayList();
    List<File> osmFiles = Lists.newArrayList();
    JsonNode builderConfig = null;
    JsonNode routerConfig = null;
    File demFile = null;
    LOG.info("Searching for graph builder input files in {}", dir);
    if (!dir.isDirectory() && dir.canRead()) {
        LOG.error("'{}' is not a readable directory.", dir);
        return null;
    }
    graphBuilder.setPath(dir);
    // Find and parse config files first to reveal syntax errors early without waiting for graph build.
    builderConfig = OTPMain.loadJson(new File(dir, BUILDER_CONFIG_FILENAME));
    GraphBuilderParameters builderParams = new GraphBuilderParameters(builderConfig);
    // Load the router config JSON to fail fast, but we will only apply it later when a router starts up
    routerConfig = OTPMain.loadJson(new File(dir, Router.ROUTER_CONFIG_FILENAME));
    LOG.info(ReflectionLibrary.dumpFields(builderParams));
    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 DEM:
                if (!builderParams.fetchElevationUS && demFile == null) {
                    LOG.info("Found DEM file {}", file);
                    demFile = file;
                } else {
                    LOG.info("Skipping DEM file {}", file);
                }
                break;
            case OTHER:
                LOG.warn("Skipping unrecognized file '{}'", file);
        }
    }
    boolean hasOSM = builderParams.streets && !osmFiles.isEmpty();
    boolean hasGTFS = builderParams.transit && !gtfsFiles.isEmpty();
    if (!(hasOSM || hasGTFS)) {
        LOG.error("Found no input files from which to build a graph in {}", dir);
        return null;
    }
    if (hasOSM) {
        List<OpenStreetMapProvider> osmProviders = Lists.newArrayList();
        for (File osmFile : osmFiles) {
            OpenStreetMapProvider osmProvider = new AnyFileBasedOpenStreetMapProviderImpl(osmFile);
            osmProviders.add(osmProvider);
        }
        OpenStreetMapModule osmModule = new OpenStreetMapModule(osmProviders);
        DefaultStreetEdgeFactory streetEdgeFactory = new DefaultStreetEdgeFactory();
        streetEdgeFactory.useElevationData = builderParams.fetchElevationUS || (demFile != null);
        osmModule.edgeFactory = streetEdgeFactory;
        osmModule.customNamer = builderParams.customNamer;
        osmModule.setDefaultWayPropertySetSource(builderParams.wayPropertySet);
        osmModule.skipVisibility = !builderParams.areaVisibility;
        osmModule.platformEntriesLinking = builderParams.platformEntriesLinking;
        osmModule.staticBikeRental = builderParams.staticBikeRental;
        osmModule.staticBikeParkAndRide = builderParams.staticBikeParkAndRide;
        osmModule.staticParkAndRide = builderParams.staticParkAndRide;
        osmModule.banDiscouragedWalking = builderParams.banDiscouragedWalking;
        osmModule.banDiscouragedBiking = builderParams.banDiscouragedBiking;
        graphBuilder.addModule(osmModule);
        PruneFloatingIslands pruneFloatingIslands = new PruneFloatingIslands();
        pruneFloatingIslands.setPruningThresholdIslandWithoutStops(builderParams.pruningThresholdIslandWithoutStops);
        pruneFloatingIslands.setPruningThresholdIslandWithStops(builderParams.pruningThresholdIslandWithStops);
        graphBuilder.addModule(pruneFloatingIslands);
    }
    if (hasGTFS) {
        List<GtfsBundle> gtfsBundles = Lists.newArrayList();
        for (File gtfsFile : gtfsFiles) {
            GtfsBundle gtfsBundle = new GtfsBundle(gtfsFile);
            gtfsBundle.setTransfersTxtDefinesStationPaths(builderParams.useTransfersTxt);
            if (builderParams.parentStopLinking) {
                gtfsBundle.linkStopsToParentStations = true;
            }
            gtfsBundle.parentStationTransfers = builderParams.stationTransfers;
            gtfsBundle.subwayAccessTime = (int) (builderParams.subwayAccessTime * 60);
            gtfsBundle.maxInterlineDistance = builderParams.maxInterlineDistance;
            gtfsBundles.add(gtfsBundle);
        }
        GtfsModule gtfsModule = new GtfsModule(gtfsBundles);
        gtfsModule.setFareServiceFactory(builderParams.fareServiceFactory);
        graphBuilder.addModule(gtfsModule);
        if (hasOSM) {
            if (builderParams.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.
    graphBuilder.addModule(new StreetLinkerModule());
    // We want to do run this module after loading the OSM street network but before finding transfers.
    if (builderParams.elevationBucket != null) {
        // Download the elevation tiles from an Amazon S3 bucket
        S3BucketConfig bucketConfig = builderParams.elevationBucket;
        File cacheDirectory = new File(params.cacheDirectory, "ned");
        DegreeGridNEDTileSource awsTileSource = new DegreeGridNEDTileSource();
        awsTileSource = new DegreeGridNEDTileSource();
        awsTileSource.awsAccessKey = bucketConfig.accessKey;
        awsTileSource.awsSecretKey = bucketConfig.secretKey;
        awsTileSource.awsBucketName = bucketConfig.bucketName;
        NEDGridCoverageFactoryImpl gcf = new NEDGridCoverageFactoryImpl(cacheDirectory);
        gcf.tileSource = awsTileSource;
        GraphBuilderModule elevationBuilder = new ElevationModule(gcf);
        graphBuilder.addModule(elevationBuilder);
    } else if (builderParams.fetchElevationUS) {
        // Download the elevation tiles from the official web service
        File cacheDirectory = new File(params.cacheDirectory, "ned");
        ElevationGridCoverageFactory gcf = new NEDGridCoverageFactoryImpl(cacheDirectory);
        GraphBuilderModule elevationBuilder = new ElevationModule(gcf);
        graphBuilder.addModule(elevationBuilder);
    } else if (demFile != null) {
        // Load the elevation from a file in the graph inputs directory
        ElevationGridCoverageFactory gcf = new GeotiffGridCoverageFactoryImpl(demFile);
        GraphBuilderModule elevationBuilder = new ElevationModule(gcf);
        graphBuilder.addModule(elevationBuilder);
    }
    if (hasGTFS) {
        // The stops can be linked to each other once they are already linked to the street network.
        if (!builderParams.useTransfersTxt) {
            // This module will use streets or straight line distance depending on whether OSM data is found in the graph.
            graphBuilder.addModule(new DirectTransferGenerator(builderParams.maxTransferDistance));
        }
    }
    graphBuilder.addModule(new EmbedConfig(builderConfig, routerConfig));
    if (builderParams.htmlAnnotations) {
        graphBuilder.addModule(new AnnotationsToHTML(params.build, builderParams.maxHtmlAnnotationsPerFile));
    }
    graphBuilder.serializeGraph = (!params.inMemory) || params.preFlight;
    return graphBuilder;
}
Also used : ElevationModule(org.opentripplanner.graph_builder.module.ned.ElevationModule) NEDGridCoverageFactoryImpl(org.opentripplanner.graph_builder.module.ned.NEDGridCoverageFactoryImpl) S3BucketConfig(org.opentripplanner.standalone.S3BucketConfig) JsonNode(com.fasterxml.jackson.databind.JsonNode) GtfsModule(org.opentripplanner.graph_builder.module.GtfsModule) GeotiffGridCoverageFactoryImpl(org.opentripplanner.graph_builder.module.ned.GeotiffGridCoverageFactoryImpl) GraphBuilderModule(org.opentripplanner.graph_builder.services.GraphBuilderModule) StreetLinkerModule(org.opentripplanner.graph_builder.module.StreetLinkerModule) EmbedConfig(org.opentripplanner.graph_builder.module.EmbedConfig) 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) OpenStreetMapProvider(org.opentripplanner.openstreetmap.services.OpenStreetMapProvider) ElevationGridCoverageFactory(org.opentripplanner.graph_builder.services.ned.ElevationGridCoverageFactory) PruneFloatingIslands(org.opentripplanner.graph_builder.module.PruneFloatingIslands) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) BusRouteStreetMatcher(org.opentripplanner.graph_builder.module.map.BusRouteStreetMatcher) AnyFileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.AnyFileBasedOpenStreetMapProviderImpl) GraphBuilderParameters(org.opentripplanner.standalone.GraphBuilderParameters) ZipFile(java.util.zip.ZipFile) File(java.io.File) DefaultStreetEdgeFactory(org.opentripplanner.graph_builder.services.DefaultStreetEdgeFactory)

Example 4 with StreetLinkerModule

use of org.opentripplanner.graph_builder.module.StreetLinkerModule in project OpenTripPlanner by opentripplanner.

the class TestPatternHopFactory method setUp.

public void setUp() throws Exception {
    context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
    graph = new Graph();
    feedId = context.getFeedId().getId();
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(graph);
    graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    String[] stops = { feedId + ":A", feedId + ":B", feedId + ":C", feedId + ":D", feedId + ":E", feedId + ":entrance_a", feedId + ":entrance_b" };
    for (int i = 0; i < stops.length; ++i) {
        TransitStop stop = (TransitStop) (graph.getVertex(stops[i]));
        IntersectionVertex front = new IntersectionVertex(graph, "near_1_" + stop.getStopId(), stop.getX() + 0.0001, stop.getY() + 0.0001);
        IntersectionVertex back = new IntersectionVertex(graph, "near_2_" + stop.getStopId(), stop.getX() - 0.0001, stop.getY() - 0.0001);
        StreetEdge street1 = new StreetEdge(front, back, GeometryUtils.makeLineString(stop.getX() + 0.0001, stop.getY() + 0.0001, stop.getX() - 0.0001, stop.getY() - 0.0001), "street", 100, StreetTraversalPermission.ALL, false);
        StreetEdge street2 = new StreetEdge(back, front, GeometryUtils.makeLineString(stop.getX() - 0.0001, stop.getY() - 0.0001, stop.getX() + 0.0001, stop.getY() + 0.0001), "street", 100, StreetTraversalPermission.ALL, true);
    }
    StreetLinkerModule ttsnm = new StreetLinkerModule();
    // Linkers aren't run otherwise
    graph.hasStreets = true;
    graph.hasTransit = true;
    ttsnm.buildGraph(graph, new HashMap<Class<?>, Object>());
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) Graph(org.opentripplanner.routing.graph.Graph) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) File(java.io.File) StreetLinkerModule(org.opentripplanner.graph_builder.module.StreetLinkerModule)

Aggregations

StreetLinkerModule (org.opentripplanner.graph_builder.module.StreetLinkerModule)4 File (java.io.File)3 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)2 GTFSPatternHopFactory (org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory)2 Graph (org.opentripplanner.routing.graph.Graph)2 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 IOException (java.io.IOException)1 ZipFile (java.util.zip.ZipFile)1 Test (org.junit.Test)1 GtfsBundle (org.opentripplanner.graph_builder.model.GtfsBundle)1 DirectTransferGenerator (org.opentripplanner.graph_builder.module.DirectTransferGenerator)1 EmbedConfig (org.opentripplanner.graph_builder.module.EmbedConfig)1 GtfsModule (org.opentripplanner.graph_builder.module.GtfsModule)1 PruneFloatingIslands (org.opentripplanner.graph_builder.module.PruneFloatingIslands)1 TransitToTaggedStopsModule (org.opentripplanner.graph_builder.module.TransitToTaggedStopsModule)1 BusRouteStreetMatcher (org.opentripplanner.graph_builder.module.map.BusRouteStreetMatcher)1 DegreeGridNEDTileSource (org.opentripplanner.graph_builder.module.ned.DegreeGridNEDTileSource)1 ElevationModule (org.opentripplanner.graph_builder.module.ned.ElevationModule)1 GeotiffGridCoverageFactoryImpl (org.opentripplanner.graph_builder.module.ned.GeotiffGridCoverageFactoryImpl)1