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;
}
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);
}
}
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);
}
}
}
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));
}
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);
}
Aggregations