Search in sources :

Example 46 with Envelope

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);
    }
}
Also used : Envelope(com.vividsolutions.jts.geom.Envelope) ZipFile(java.util.zip.ZipFile) URL(java.net.URL)

Example 47 with Envelope

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();
    }
}
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) StopShort(org.opentripplanner.index.model.StopShort) Envelope(com.vividsolutions.jts.geom.Envelope) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 48 with Envelope

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;
}
Also used : TransitStopStreetVertex(org.opentripplanner.routing.vertextype.TransitStopStreetVertex) TransitStopStreetVertex(org.opentripplanner.routing.vertextype.TransitStopStreetVertex) Vertex(org.opentripplanner.routing.graph.Vertex) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 49 with Envelope

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;
}
Also used : Envelope(com.vividsolutions.jts.geom.Envelope)

Example 50 with Envelope

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;
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) Router(org.opentripplanner.standalone.Router) BikeRentalStationService(org.opentripplanner.routing.bike_rental.BikeRentalStationService) Envelope(com.vividsolutions.jts.geom.Envelope) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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