Search in sources :

Example 1 with WorldEnvelope

use of org.opentripplanner.util.WorldEnvelope in project OpenTripPlanner by opentripplanner.

the class Graph method calculateEnvelope.

/**
 * Calculates envelope out of all OSM coordinates
 *
 * Transit stops are added to the envelope as they are added to the graph
 */
public void calculateEnvelope() {
    this.envelope = new WorldEnvelope();
    for (Vertex v : this.getVertices()) {
        Coordinate c = v.getCoordinate();
        this.envelope.expandToInclude(c);
    }
}
Also used : PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) Coordinate(com.vividsolutions.jts.geom.Coordinate) WorldEnvelope(org.opentripplanner.util.WorldEnvelope)

Example 2 with WorldEnvelope

use of org.opentripplanner.util.WorldEnvelope in project OpenTripPlanner by opentripplanner.

the class Router method startup.

/**
 * Below is functionality moved into Router from the "router lifecycle manager" interface and implementation.
 * Current responsibilities are: 1) Binding proper services (depending on the configuration from command-line or
 * JSON config files) and 2) starting / stopping real-time updaters (delegated to the GraphUpdaterConfigurator class).
 */
/**
 * Start up a new router once it has been created.
 * @param config The configuration (loaded from Graph.properties for example).
 */
public void startup(JsonNode config) {
    this.tileRendererManager = new TileRendererManager(this.graph);
    // Analyst Modules FIXME make these optional based on JSON?
    {
        this.tileCache = new TileCache(this.graph);
        this.renderer = new Renderer(this.tileCache);
        this.sampleGridRenderer = new SampleGridRenderer(this.graph);
        this.isoChroneSPTRenderer = new IsoChroneSPTRendererAccSampling(this.sampleGridRenderer);
    }
    /* Create the default router parameters from the JSON router config. */
    JsonNode routingDefaultsNode = config.get("routingDefaults");
    if (routingDefaultsNode != null) {
        LOG.info("Loading default routing parameters from JSON:");
        ReflectiveInitializer<RoutingRequest> scraper = new ReflectiveInitializer(RoutingRequest.class);
        this.defaultRoutingRequest = scraper.scrape(routingDefaultsNode);
    } else {
        LOG.info("No default routing parameters were found in the router config JSON. Using built-in OTP defaults.");
        this.defaultRoutingRequest = new RoutingRequest();
    }
    /* Apply single timeout. */
    JsonNode timeout = config.get("timeout");
    if (timeout != null) {
        if (timeout.isNumber()) {
            this.timeouts = new double[] { timeout.doubleValue() };
        } else {
            LOG.error("The 'timeout' configuration option should be a number of seconds.");
        }
    }
    /* Apply multiple timeouts. */
    JsonNode timeouts = config.get("timeouts");
    if (timeouts != null) {
        if (timeouts.isArray() && timeouts.size() > 0) {
            this.timeouts = new double[timeouts.size()];
            int i = 0;
            for (JsonNode node : timeouts) {
                this.timeouts[i++] = node.doubleValue();
            }
        } else {
            LOG.error("The 'timeouts' configuration option should be an array of values in seconds.");
        }
    }
    LOG.info("Timeouts for router '{}': {}", this.id, this.timeouts);
    JsonNode requestLogFile = config.get("requestLogFile");
    if (requestLogFile != null) {
        this.requestLogger = createLogger(requestLogFile.asText());
        LOG.info("Logging incoming requests at '{}'", requestLogFile.asText());
    } else {
        LOG.info("Incoming requests will not be logged.");
    }
    JsonNode boardTimes = config.get("boardTimes");
    if (boardTimes != null && boardTimes.isObject()) {
        graph.boardTimes = new EnumMap<>(TraverseMode.class);
        for (TraverseMode mode : TraverseMode.values()) {
            if (boardTimes.has(mode.name())) {
                graph.boardTimes.put(mode, boardTimes.get(mode.name()).asInt(0));
            }
        }
    }
    JsonNode alightTimes = config.get("alightTimes");
    if (alightTimes != null && alightTimes.isObject()) {
        graph.alightTimes = new EnumMap<>(TraverseMode.class);
        for (TraverseMode mode : TraverseMode.values()) {
            if (alightTimes.has(mode.name())) {
                graph.alightTimes.put(mode, alightTimes.get(mode.name()).asInt(0));
            }
        }
    }
    JsonNode stopClusterMode = config.get("stopClusterMode");
    if (stopClusterMode != null) {
        graph.stopClusterMode = stopClusterMode.asText();
    } else {
        graph.stopClusterMode = "proximity";
    }
    /* Create Graph updater modules from JSON config. */
    GraphUpdaterConfigurator.setupGraph(this.graph, config);
    /* Compute ellipsoidToGeoidDifference for this Graph */
    try {
        WorldEnvelope env = graph.getEnvelope();
        double lat = (env.getLowerLeftLatitude() + env.getUpperRightLatitude()) / 2;
        double lon = (env.getLowerLeftLongitude() + env.getUpperRightLongitude()) / 2;
        graph.ellipsoidToGeoidDifference = ElevationUtils.computeEllipsoidToGeoidDifference(lat, lon);
        LOG.info("Computed ellipsoid/geoid offset at (" + lat + ", " + lon + ") as " + graph.ellipsoidToGeoidDifference);
    } catch (Exception e) {
        LOG.error("Error computing ellipsoid/geoid difference");
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ReflectiveInitializer(org.opentripplanner.reflect.ReflectiveInitializer) TileRendererManager(org.opentripplanner.inspector.TileRendererManager) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) TraverseMode(org.opentripplanner.routing.core.TraverseMode) WorldEnvelope(org.opentripplanner.util.WorldEnvelope)

Aggregations

WorldEnvelope (org.opentripplanner.util.WorldEnvelope)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 TileRendererManager (org.opentripplanner.inspector.TileRendererManager)1 ReflectiveInitializer (org.opentripplanner.reflect.ReflectiveInitializer)1 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)1 TraverseMode (org.opentripplanner.routing.core.TraverseMode)1 PatternArriveVertex (org.opentripplanner.routing.vertextype.PatternArriveVertex)1