Search in sources :

Example 51 with Envelope

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

the class BikeRental method getEnvelope.

/**
 * Envelopes are in latitude, longitude format
 */
public static Envelope getEnvelope(String lowerLeft, String upperRight) {
    String[] lowerLeftParts = lowerLeft.split(",");
    String[] upperRightParts = upperRight.split(",");
    Envelope envelope = new Envelope(Double.parseDouble(lowerLeftParts[1]), Double.parseDouble(upperRightParts[1]), Double.parseDouble(lowerLeftParts[0]), Double.parseDouble(upperRightParts[0]));
    return envelope;
}
Also used : Envelope(com.vividsolutions.jts.geom.Envelope)

Example 52 with Envelope

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

the class GraphIndex method clusterByProximityAndName.

/**
 * Cluster stops by proximity and name.
 * This functionality was developed for the Washington, DC area and probably will not work anywhere else in the
 * world. It depends on the exact way stops are named and the way street intersections are named in that geographic
 * region and in the GTFS data sets which represent it. Based on comments, apparently it might work for TriMet
 * as well.
 *
 * We can't use a name similarity comparison, we need exact matches. This is because many street names differ by
 * only one letter or number, e.g. 34th and 35th or Avenue A and Avenue B. Therefore normalizing the names before
 * the comparison is essential. The agency must provide either parent station information or a well thought out stop
 * naming scheme to cluster stops -- no guessing is reasonable without that information.
 */
private void clusterByProximityAndName() {
    // unique index for next parent stop
    int psIdx = 0;
    LOG.info("Clustering stops by geographic proximity and name...");
    // Each stop without a cluster will greedily claim other stops without clusters.
    for (Stop s0 : stopForId.values()) {
        // skip stops that have already been claimed by a cluster
        if (stopClusterForStop.containsKey(s0))
            continue;
        String s0normalizedName = StopNameNormalizer.normalize(s0.getName());
        StopCluster cluster = new StopCluster(String.format("C%03d", psIdx++), s0normalizedName);
        // LOG.info("stop {}", s0normalizedName);
        // No need to explicitly add s0 to the cluster. It will be found in the spatial index query below.
        Envelope env = new Envelope(new Coordinate(s0.getLon(), s0.getLat()));
        env.expandBy(SphericalDistanceLibrary.metersToLonDegrees(CLUSTER_RADIUS, s0.getLat()), SphericalDistanceLibrary.metersToDegrees(CLUSTER_RADIUS));
        for (TransitStop ts1 : stopSpatialIndex.query(env)) {
            Stop s1 = ts1.getStop();
            double geoDistance = SphericalDistanceLibrary.fastDistance(s0.getLat(), s0.getLon(), s1.getLat(), s1.getLon());
            if (geoDistance < CLUSTER_RADIUS) {
                String s1normalizedName = StopNameNormalizer.normalize(s1.getName());
                // LOG.info("       geodist {} stringdist {}", geoDistance, stringDistance);
                if (s1normalizedName.equals(s0normalizedName)) {
                    // Create a bidirectional relationship between the stop and its cluster
                    cluster.children.add(s1);
                    stopClusterForStop.put(s1, cluster);
                }
            }
        }
        cluster.computeCenter();
        stopClusterForId.put(cluster.id, cluster);
    }
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) Coordinate(com.vividsolutions.jts.geom.Coordinate) StopCluster(org.opentripplanner.profile.StopCluster) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 53 with Envelope

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

the class GraphIndex method clusterStopsAsNeeded.

/**
 * Stop clustering is slow to perform and only used in profile routing for the moment.
 * Therefore it is not done automatically, and any method requiring stop clusters should call this method
 * to ensure that the necessary indexes are lazy-initialized.
 */
public synchronized void clusterStopsAsNeeded() {
    if (stopClusterSpatialIndex == null) {
        clusterStops();
        LOG.info("Creating a spatial index for stop clusters.");
        stopClusterSpatialIndex = new HashGridSpatialIndex<>();
        for (StopCluster cluster : stopClusterForId.values()) {
            Envelope envelope = new Envelope(new Coordinate(cluster.lon, cluster.lat));
            stopClusterSpatialIndex.insert(envelope, cluster);
        }
    }
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) StopCluster(org.opentripplanner.profile.StopCluster) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 54 with Envelope

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

the class SphericalDistanceLibrary method bounds.

public static final Envelope bounds(double lat, double lon, double latDistance, double lonDistance) {
    double radiusOfEarth = RADIUS_OF_EARTH_IN_M;
    double latRadians = toRadians(lat);
    double lonRadians = toRadians(lon);
    double latRadius = radiusOfEarth;
    double lonRadius = cos(latRadians) * radiusOfEarth;
    double latOffset = latDistance / latRadius;
    double lonOffset = lonDistance / lonRadius;
    double latFrom = toDegrees(latRadians - latOffset);
    double latTo = toDegrees(latRadians + latOffset);
    double lonFrom = toDegrees(lonRadians - lonOffset);
    double lonTo = toDegrees(lonRadians + lonOffset);
    return new Envelope(new Coordinate(lonFrom, latFrom), new Coordinate(lonTo, latTo));
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 55 with Envelope

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

the class BanoGeocoderTest method testOnLine.

/**
 * TODO -- This unit-test rely on an on-line API to be up and running, which may not be the case
 * if a network connection is not active or the server is down.
 */
@Test
public void testOnLine() throws Exception {
    BanoGeocoder banoGeocoder = new BanoGeocoder();
    // The Presidential palace of the French Republic is not supposed to move often
    Envelope bbox = new Envelope();
    bbox.expandToInclude(2.25, 48.8);
    bbox.expandToInclude(2.35, 48.9);
    GeocoderResults results = banoGeocoder.geocode("55 Rue du Faubourg Saint-Honoré", bbox);
    assert (results.getResults().size() >= 1);
    boolean found = false;
    for (GeocoderResult result : results.getResults()) {
        if ("55 Rue du Faubourg Saint-Honoré 75008 Paris".equals(result.getDescription())) {
            double dist = SphericalDistanceLibrary.distance(result.getLat(), result.getLng(), 48.870637, 2.316939);
            assert (dist < 100);
            found = true;
        }
    }
    assert (found);
}
Also used : GeocoderResults(org.opentripplanner.geocoder.GeocoderResults) Envelope(com.vividsolutions.jts.geom.Envelope) GeocoderResult(org.opentripplanner.geocoder.GeocoderResult) Test(org.junit.Test)

Aggregations

Envelope (com.vividsolutions.jts.geom.Envelope)111 Coordinate (com.vividsolutions.jts.geom.Coordinate)21 Node (org.locationtech.geogig.api.Node)16 Geometry (com.vividsolutions.jts.geom.Geometry)13 ObjectId (org.locationtech.geogig.api.ObjectId)13 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)12 STRtree (com.vividsolutions.jts.index.strtree.STRtree)11 ArrayList (java.util.ArrayList)11 Vertex (org.opentripplanner.routing.graph.Vertex)11 Test (org.junit.Test)9 NodeRef (org.locationtech.geogig.api.NodeRef)9 Edge (org.opentripplanner.routing.graph.Edge)9 LineString (com.vividsolutions.jts.geom.LineString)8 RevTree (org.locationtech.geogig.api.RevTree)8 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)7 Map (java.util.Map)6 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)6 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)6 RevFeature (org.locationtech.geogig.api.RevFeature)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5