Search in sources :

Example 96 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project OpenTripPlanner by opentripplanner.

the class IsoChroneSPTRendererRecursiveGrid method computeInitialPoints.

/**
 * Compute a set of initial coordinates for the given SPT
 *
 * @param spt
 * @return
 */
private List<Coordinate> computeInitialPoints(ShortestPathTree spt) {
    List<Coordinate> retval = new ArrayList<Coordinate>(spt.getVertexCount());
    for (State s : spt.getAllStates()) {
        Vertex v = s.getVertex();
        // Take only street
        if (v instanceof StreetVertex) {
            retval.add(v.getCoordinate());
        }
    }
    LOG.debug("Created {} initial points from {} vertexes.", retval.size(), spt.getVertexCount());
    return retval;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Coordinate(com.vividsolutions.jts.geom.Coordinate) State(org.opentripplanner.routing.core.State) ArrayList(java.util.ArrayList) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex)

Example 97 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project OpenTripPlanner by opentripplanner.

the class SampleGridRenderer method getSampleGrid.

/**
 * @param spgRequest
 * @param sptRequest
 * @return
 */
public ZSampleGrid<WTWD> getSampleGrid(SampleGridRequest spgRequest, RoutingRequest sptRequest) {
    final double offRoadDistanceMeters = spgRequest.offRoadDistanceMeters;
    // m/s, off-road walk speed
    final double offRoadWalkSpeedMps = 1.00;
    // 1. Compute the Shortest Path Tree.
    long t0 = System.currentTimeMillis();
    long tOvershot = (long) (2 * offRoadDistanceMeters / offRoadWalkSpeedMps);
    sptRequest.worstTime = (sptRequest.dateTime + (sptRequest.arriveBy ? -spgRequest.maxTimeSec - tOvershot : spgRequest.maxTimeSec + tOvershot));
    sptRequest.batch = (true);
    sptRequest.setRoutingContext(graph);
    // TODO swap in different state dominance logic (earliest arrival, pareto, etc.)
    final ShortestPathTree spt = new AStar().getShortestPathTree(sptRequest);
    // 3. Create a sample grid based on the SPT.
    long t1 = System.currentTimeMillis();
    Coordinate coordinateOrigin = spgRequest.coordinateOrigin;
    if (coordinateOrigin == null)
        coordinateOrigin = sptRequest.from.getCoordinate();
    final double gridSizeMeters = spgRequest.precisionMeters;
    final double cosLat = FastMath.cos(toRadians(coordinateOrigin.y));
    double dY = Math.toDegrees(gridSizeMeters / SphericalDistanceLibrary.RADIUS_OF_EARTH_IN_M);
    double dX = dY / cosLat;
    SparseMatrixZSampleGrid<WTWD> sampleGrid = new SparseMatrixZSampleGrid<WTWD>(16, spt.getVertexCount(), dX, dY, coordinateOrigin);
    sampleSPT(spt, sampleGrid, gridSizeMeters, offRoadDistanceMeters, offRoadWalkSpeedMps, sptRequest.getMaxWalkDistance(), spgRequest.maxTimeSec, cosLat);
    sptRequest.cleanup();
    long t2 = System.currentTimeMillis();
    LOG.info("Computed SPT in {}msec, {}msec for sampling ({} msec total)", (int) (t1 - t0), (int) (t2 - t1), (int) (t2 - t0));
    return sampleGrid;
}
Also used : ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) Coordinate(com.vividsolutions.jts.geom.Coordinate) AStar(org.opentripplanner.routing.algorithm.AStar) SparseMatrixZSampleGrid(org.opentripplanner.common.geometry.SparseMatrixZSampleGrid)

Example 98 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project OpenTripPlanner by opentripplanner.

the class SampleGridRenderer method sampleSPT.

/**
 * Sample a SPT using a SPTWalker and an AccumulativeGridSampler.
 */
public static void sampleSPT(final ShortestPathTree spt, ZSampleGrid<WTWD> sampleGrid, final double gridSizeMeters, final double offRoadDistanceMeters, final double offRoadWalkSpeedMps, final double maxWalkDistance, final int maxTimeSec, final double cosLat) {
    AccumulativeMetric<WTWD> accMetric = new WTWDAccumulativeMetric(cosLat, offRoadDistanceMeters, offRoadWalkSpeedMps, gridSizeMeters);
    final AccumulativeGridSampler<WTWD> gridSampler = new AccumulativeGridSampler<WTWD>(sampleGrid, accMetric);
    // At which distance we split edges along the geometry during sampling.
    // For best results, this should be slighly lower than the grid size.
    double walkerSplitDistanceMeters = gridSizeMeters * 0.5;
    SPTWalker johnny = new SPTWalker(spt);
    johnny.walk(new SPTVisitor() {

        @Override
        public final boolean accept(Edge e) {
            return e instanceof StreetEdge;
        }

        @Override
        public final void visit(Edge e, Coordinate c, State s0, State s1, double d0, double d1, double speedAlongEdge) {
            double wd0 = s0.getWalkDistance() + d0;
            double wd1 = s0.getWalkDistance() + d1;
            double t0 = wd0 > maxWalkDistance ? Double.POSITIVE_INFINITY : s0.getActiveTime() + d0 / speedAlongEdge;
            double t1 = wd1 > maxWalkDistance ? Double.POSITIVE_INFINITY : s1.getActiveTime() + d1 / speedAlongEdge;
            if (t0 < maxTimeSec || t1 < maxTimeSec) {
                if (!Double.isInfinite(t0) || !Double.isInfinite(t1)) {
                    WTWD z = new WTWD();
                    z.w = 1.0;
                    z.d = 0.0;
                    if (t0 < t1) {
                        z.wTime = t0;
                        z.wBoardings = s0.getNumBoardings();
                        z.wWalkDist = s0.getWalkDistance() + d0;
                    } else {
                        z.wTime = t1;
                        z.wBoardings = s1.getNumBoardings();
                        z.wWalkDist = s1.getWalkDistance() + d1;
                    }
                    gridSampler.addSamplingPoint(c, z, offRoadWalkSpeedMps);
                }
            }
        }
    }, walkerSplitDistanceMeters);
    gridSampler.close();
}
Also used : SPTVisitor(org.opentripplanner.routing.spt.SPTWalker.SPTVisitor) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) SPTWalker(org.opentripplanner.routing.spt.SPTWalker) Coordinate(com.vividsolutions.jts.geom.Coordinate) AccumulativeGridSampler(org.opentripplanner.common.geometry.AccumulativeGridSampler) State(org.opentripplanner.routing.core.State) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 99 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project OpenTripPlanner by opentripplanner.

the class Graph method calculateTransitCenter.

/**
 * Calculates Transit center from median of coordinates of all transitStops if graph
 * has transit. If it doesn't it isn't calculated. (mean walue of min, max latitude and longitudes are used)
 *
 * Transit center is saved in center variable
 *
 * This speeds up calculation, but problem is that median needs to have all of latitudes/longitudes
 * in memory, this can become problematic in large installations. It works without a problem on New York State.
 * @see GraphEnvelope
 */
public void calculateTransitCenter() {
    if (hasTransit) {
        TDoubleList latitudes = new TDoubleLinkedList();
        TDoubleList longitudes = new TDoubleLinkedList();
        Median median = new Median();
        getVertices().stream().filter(v -> v instanceof TransitStop).forEach(v -> {
            latitudes.add(v.getLat());
            longitudes.add(v.getLon());
        });
        median.setData(latitudes.toArray());
        double medianLatitude = median.evaluate();
        median = new Median();
        median.setData(longitudes.toArray());
        double medianLongitude = median.evaluate();
        this.center = new Coordinate(medianLongitude, medianLatitude);
    }
}
Also used : TDoubleList(gnu.trove.list.TDoubleList) TurnRestriction(org.opentripplanner.common.TurnRestriction) LoggerFactory(org.slf4j.LoggerFactory) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) StreetSpeedSnapshotSource(org.opentripplanner.traffic.StreetSpeedSnapshotSource) GraphUtils(org.opentripplanner.common.geometry.GraphUtils) StreetVertexIndexService(org.opentripplanner.routing.services.StreetVertexIndexService) Median(org.apache.commons.math3.stat.descriptive.rank.Median) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) Geometry(com.vividsolutions.jts.geom.Geometry) TraverseMode(org.opentripplanner.routing.core.TraverseMode) com.google.common.collect(com.google.common.collect) FeedInfo(org.onebusaway.gtfs.model.FeedInfo) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) MavenVersion(org.opentripplanner.common.MavenVersion) TransferTable(org.opentripplanner.routing.core.TransferTable) StreetNotesService(org.opentripplanner.routing.services.notes.StreetNotesService) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SampleFactory(org.opentripplanner.analyst.request.SampleFactory) CalendarService(org.onebusaway.gtfs.services.calendar.CalendarService) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Stop(org.onebusaway.gtfs.model.Stop) Agency(org.onebusaway.gtfs.model.Agency) GraphUpdaterManager(org.opentripplanner.updater.GraphUpdaterManager) TimetableSnapshotSource(org.opentripplanner.updater.stoptime.TimetableSnapshotSource) StreetVertexIndexFactory(org.opentripplanner.routing.services.StreetVertexIndexFactory) java.util(java.util) AlertPatch(org.opentripplanner.routing.alertpatch.AlertPatch) WorldEnvelope(org.opentripplanner.util.WorldEnvelope) TDoubleList(gnu.trove.list.TDoubleList) TDoubleLinkedList(gnu.trove.list.linked.TDoubleLinkedList) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) NoFutureDates(org.opentripplanner.graph_builder.annotation.NoFutureDates) GraphUpdaterConfigurator(org.opentripplanner.updater.GraphUpdaterConfigurator) GraphBuilderAnnotation(org.opentripplanner.graph_builder.annotation.GraphBuilderAnnotation) GeometryIndex(org.opentripplanner.analyst.core.GeometryIndex) MortonVertexComparatorFactory(org.opentripplanner.routing.core.MortonVertexComparatorFactory) EdgeWithCleanup(org.opentripplanner.routing.edgetype.EdgeWithCleanup) Coordinate(com.vividsolutions.jts.geom.Coordinate) Logger(org.slf4j.Logger) Envelope(com.vividsolutions.jts.geom.Envelope) CalendarServiceImpl(org.onebusaway.gtfs.impl.calendar.CalendarServiceImpl) GraphBundle(org.opentripplanner.model.GraphBundle) DateTime(org.joda.time.DateTime) TransitStation(org.opentripplanner.routing.vertextype.TransitStation) Preferences(java.util.prefs.Preferences) java.io(java.io) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Deduplicator(org.opentripplanner.routing.trippattern.Deduplicator) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) VisibleForTesting(com.google.common.annotations.VisibleForTesting) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Coordinate(com.vividsolutions.jts.geom.Coordinate) TDoubleLinkedList(gnu.trove.list.linked.TDoubleLinkedList) Median(org.apache.commons.math3.stat.descriptive.rank.Median)

Example 100 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate 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)

Aggregations

Coordinate (com.vividsolutions.jts.geom.Coordinate)336 LineString (com.vividsolutions.jts.geom.LineString)70 Geometry (com.vividsolutions.jts.geom.Geometry)67 ArrayList (java.util.ArrayList)65 Test (org.junit.Test)60 Point (com.vividsolutions.jts.geom.Point)52 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)48 Polygon (com.vividsolutions.jts.geom.Polygon)30 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)27 SimpleFeature (org.opengis.feature.simple.SimpleFeature)23 LinearRing (com.vividsolutions.jts.geom.LinearRing)22 Vertex (org.opentripplanner.routing.graph.Vertex)22 Envelope (com.vividsolutions.jts.geom.Envelope)21 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)20 Edge (org.opentripplanner.routing.graph.Edge)19 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)19 CoordinateSequence (com.vividsolutions.jts.geom.CoordinateSequence)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)13 File (java.io.File)11 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)11