use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class NoDownloadIDException method getDownloadURLsCached.
private List<URL> getDownloadURLsCached() {
Envelope extent = graph.getExtent();
Formatter formatter = new Formatter();
String filename = formatter.format("%f,%f-%f,%f.urls", extent.getMinX(), extent.getMinY(), extent.getMaxX(), extent.getMaxY()).toString();
formatter.close();
try {
File file = new File(cacheDirectory, filename);
List<URL> urls;
if (!file.exists()) {
return getAndCacheUrls(file);
}
// read cached urls
FileInputStream is = new FileInputStream(file);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
urls = new ArrayList<URL>();
while (true) {
String line = reader.readLine();
if (line == null || line.length() == 0) {
break;
}
urls.add(new URL(line));
}
reader.close();
is.close();
if (urls.size() == 0) {
return getAndCacheUrls(file);
}
return urls;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class IndexAPI method getStopsInRadius.
/**
* Return a list of all stops within a circle around the given coordinate.
*/
@GET
@Path("/stops")
public Response getStopsInRadius(@QueryParam("minLat") Double minLat, @QueryParam("minLon") Double minLon, @QueryParam("maxLat") Double maxLat, @QueryParam("maxLon") Double maxLon, @QueryParam("lat") Double lat, @QueryParam("lon") Double lon, @QueryParam("radius") Double radius) {
/* When no parameters are supplied, return all stops. */
if (uriInfo.getQueryParameters().isEmpty()) {
Collection<Stop> stops = index.stopForId.values();
return Response.status(Status.OK).entity(StopShort.list(stops)).build();
}
/* If any of the circle parameters are specified, expect a circle not a box. */
boolean expectCircle = (lat != null || lon != null || radius != null);
if (expectCircle) {
if (lat == null || lon == null || radius == null || radius < 0) {
return Response.status(Status.BAD_REQUEST).entity(MSG_400).build();
}
if (radius > MAX_STOP_SEARCH_RADIUS) {
radius = MAX_STOP_SEARCH_RADIUS;
}
List<StopShort> stops = Lists.newArrayList();
Coordinate coord = new Coordinate(lon, lat);
for (TransitStop stopVertex : streetIndex.getNearbyTransitStops(new Coordinate(lon, lat), radius)) {
double distance = SphericalDistanceLibrary.fastDistance(stopVertex.getCoordinate(), coord);
if (distance < radius) {
stops.add(new StopShort(stopVertex.getStop(), (int) distance));
}
}
return Response.status(Status.OK).entity(stops).build();
} else {
/* We're not circle mode, we must be in box mode. */
if (minLat == null || minLon == null || maxLat == null || maxLon == null) {
return Response.status(Status.BAD_REQUEST).entity(MSG_400).build();
}
if (maxLat <= minLat || maxLon <= minLon) {
return Response.status(Status.BAD_REQUEST).entity(MSG_400).build();
}
List<StopShort> stops = Lists.newArrayList();
Envelope envelope = new Envelope(new Coordinate(minLon, minLat), new Coordinate(maxLon, maxLat));
for (TransitStop stopVertex : streetIndex.getTransitStopForEnvelope(envelope)) {
stops.add(new StopShort(stopVertex.getStop()));
}
return Response.status(Status.OK).entity(stops).build();
}
}
use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class TransitToTaggedStopsModule method connectVertexToStop.
private boolean connectVertexToStop(TransitStop ts, boolean wheelchairAccessible) {
String stopCode = ts.getStopCode();
if (stopCode == null) {
return false;
}
Envelope envelope = new Envelope(ts.getCoordinate());
double xscale = Math.cos(ts.getCoordinate().y * Math.PI / 180);
envelope.expandBy(searchRadiusLat / xscale, searchRadiusLat);
Collection<Vertex> vertices = index.getVerticesForEnvelope(envelope);
// in their ref= tag that matches the GTFS stop code of this TransitStop.
for (Vertex v : vertices) {
if (!(v instanceof TransitStopStreetVertex)) {
continue;
}
TransitStopStreetVertex tsv = (TransitStopStreetVertex) v;
// Only use stop codes for linking TODO: find better method to connect stops without stop code
if (tsv.stopCode != null && tsv.stopCode.equals(stopCode)) {
new StreetTransitLink(ts, tsv, wheelchairAccessible);
new StreetTransitLink(tsv, ts, wheelchairAccessible);
LOG.debug("Connected " + ts.toString() + " to " + tsv.getLabel());
return true;
}
}
return false;
}
use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class BoundingCircle method bbox.
public Envelope bbox() {
Envelope env = new Envelope(center());
double meters_per_degree_lon = METERS_PER_DEGREE_LAT * Math.cos(Math.toRadians(lat));
env.expandBy(radius / meters_per_degree_lon, radius / METERS_PER_DEGREE_LAT);
return env;
}
use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class BikeRental method getBikeRentalStations.
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML + Q, MediaType.TEXT_XML + Q })
public BikeRentalStationList getBikeRentalStations(@QueryParam("lowerLeft") String lowerLeft, @QueryParam("upperRight") String upperRight, @PathParam("routerId") String routerId, @QueryParam("locale") String locale_param) {
Router router = otpServer.getRouter(routerId);
if (router == null)
return null;
BikeRentalStationService bikeRentalService = router.graph.getService(BikeRentalStationService.class);
Locale locale;
locale = ResourceBundleSingleton.INSTANCE.getLocale(locale_param);
if (bikeRentalService == null)
return new BikeRentalStationList();
Envelope envelope;
if (lowerLeft != null) {
envelope = getEnvelope(lowerLeft, upperRight);
} else {
envelope = new Envelope(-180, 180, -90, 90);
}
Collection<BikeRentalStation> stations = bikeRentalService.getBikeRentalStations();
List<BikeRentalStation> out = new ArrayList<>();
for (BikeRentalStation station : stations) {
if (envelope.contains(station.x, station.y)) {
BikeRentalStation station_localized = station.clone();
station_localized.locale = locale;
out.add(station_localized);
}
}
BikeRentalStationList brsl = new BikeRentalStationList();
brsl.stations = out;
return brsl;
}
Aggregations