public void zoomToDefault() { modelBounds = new Envelope(modelOuterBounds); drawLevel = DRAW_ALL; }
public Envelope envelope () { return new Envelope(minLon, maxLon, minLat, maxLat); }
/** 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; }
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; }
/** * 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); } } }
@Override public Iterable<Envelope> getRegions() { List<Envelope> regions = new ArrayList<Envelope>(); for (Vertex gv : task.getGraph().getVertices()) { if (gv instanceof TransitStop) { Coordinate c = gv.getCoordinate(); Envelope env = new Envelope(c); double meters_per_degree_lon_here = METERS_PER_DEGREE_LAT * Math.cos(Math.toRadians(c.y)); env.expandBy(distance / meters_per_degree_lon_here, distance / METERS_PER_DEGREE_LAT); regions.add(env); } } LOG.debug("Total regions: " + regions.size()); return regions; } }
/** * Find transfer candidates for profile routing. * TODO replace with an on-street search using the existing profile router functions. */ public Map<StopCluster, Double> findNearbyStopClusters (StopCluster sc, double radius) { Map<StopCluster, Double> ret = Maps.newHashMap(); Envelope env = new Envelope(new Coordinate(sc.lon, sc.lat)); env.expandBy(SphericalDistanceLibrary.metersToLonDegrees(radius, sc.lat), SphericalDistanceLibrary.metersToDegrees(radius)); for (StopCluster cluster : stopClusterSpatialIndex.query(env)) { // TODO this should account for area-like nature of clusters. Use size of bounding boxes. double distance = SphericalDistanceLibrary.distance(sc.lat, sc.lon, cluster.lat, cluster.lon); if (distance < radius) ret.put(cluster, distance); } return ret; }
public void zoomToVertex(Vertex v) { Envelope e = new Envelope(); e.expandToInclude(v.getCoordinate()); e.expandBy(0.002); modelBounds = e; drawLevel = DRAW_ALL; }
public void zoomToLocation(Coordinate c) { Envelope e = new Envelope(); e.expandToInclude(c); e.expandBy(0.002); modelBounds = e; matchAspect(); drawLevel = DRAW_ALL; }
public Envelope getExtent() { Envelope env = new Envelope(); for (Vertex v : getVertices()) { env.expandToInclude(v.getCoordinate()); } return env; }
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)); }
@SuppressWarnings("unchecked") public void mouseClicked() { Envelope screenEnv = new Envelope(new Coordinate(mouseX, mouseY)); screenEnv.expandBy(4, 4); Envelope env = new Envelope(toModelX(screenEnv.getMinX()), toModelX(screenEnv.getMaxX()), toModelY(screenEnv.getMinY()), toModelY(screenEnv.getMaxY())); List<Vertex> nearby = (List<Vertex>) vertexIndex.query(env); selector.verticesSelected(nearby); drawLevel = DRAW_ALL; }
/** * Get all transit stops within a given distance of a coordinate */ @Override public List<TransitStop> getNearbyTransitStops(Coordinate coordinate, double radius) { Envelope env = new Envelope(coordinate); env.expandBy(SphericalDistanceLibrary.metersToLonDegrees(radius, coordinate.y), SphericalDistanceLibrary.metersToDegrees(radius)); List<TransitStop> nearby = getTransitStopForEnvelope(env); List<TransitStop> results = new ArrayList<TransitStop>(); for (TransitStop v : nearby) { if (SphericalDistanceLibrary.distance(v.getCoordinate(), coordinate) <= radius) { results.add(v); } } return results; }
@Override public Envelope expandPixels(double marginXPixels, double marginYPixels) { Envelope retval = new Envelope(bbox); retval.expandBy( marginXPixels / tileRequest.width * (bbox.getMaxX() - bbox.getMinX()), marginYPixels / tileRequest.height * (bbox.getMaxY() - bbox.getMinY())); return retval; } };
public final void insert(LineString geom, final Object item) { Coordinate[] coord = geom.getCoordinates(); final TLongSet keys = new TLongHashSet(coord.length * 8); for (int i = 0; i < coord.length - 1; i++) { // TODO Cut the segment if longer than bin size // to reduce the number of wrong bins Envelope env = new Envelope(coord[i], coord[i + 1]); visit(env, true, new BinVisitor<T>() { @Override public boolean visit(List<T> bin, long mapKey) { keys.add(mapKey); return false; } }); } keys.forEach(new TLongProcedure() { @SuppressWarnings("unchecked") @Override public boolean execute(long key) { // Note: bins have been initialized in the previous visit bins.get(key).add((T) item); nEntries++; return true; } }); nObjects++; }
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); // Iterate over all nearby vertices representing transit stops in OSM, linking to them if they have a stop code // 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; }
/** * @param coordinate Location to search intersection at. Look in a MAX_CORNER_DISTANCE_METERS radius. * @return The nearest intersection, null if none found. */ public StreetVertex getIntersectionAt(Coordinate coordinate) { double dLon = SphericalDistanceLibrary.metersToLonDegrees(MAX_CORNER_DISTANCE_METERS, coordinate.y); double dLat = SphericalDistanceLibrary.metersToDegrees(MAX_CORNER_DISTANCE_METERS); Envelope envelope = new Envelope(coordinate); envelope.expandBy(dLon, dLat); List<Vertex> nearby = getVerticesForEnvelope(envelope); StreetVertex nearest = null; double bestDistanceMeter = Double.POSITIVE_INFINITY; for (Vertex v : nearby) { if (v instanceof StreetVertex) { v.getLabel().startsWith("osm:"); double distanceMeter = SphericalDistanceLibrary.fastDistance(coordinate, v.getCoordinate()); if (distanceMeter < MAX_CORNER_DISTANCE_METERS) { if (distanceMeter < bestDistanceMeter) { bestDistanceMeter = distanceMeter; nearest = (StreetVertex) v; } } } } return nearest; }
public void drawAnotation(GraphBuilderAnnotation anno) { Envelope env = new Envelope(); Edge e = anno.getReferencedEdge(); if (e != null) { this.enqueueHighlightedEdge(e); env.expandToInclude(e.getFromVertex().getCoordinate()); env.expandToInclude(e.getToVertex().getCoordinate()); } ArrayList<Vertex> vertices = new ArrayList<Vertex>(); Vertex v = anno.getReferencedVertex(); if (v != null) { env.expandToInclude(v.getCoordinate()); vertices.add(v); } if (e == null && v == null) return; // make it a little bigger, especially needed for STOP_UNLINKED env.expandBy(0.02); // highlight relevant things this.clearHighlights(); this.setHighlightedVertices(vertices); // zoom the graph display this.zoomToEnvelope(env); // and draw this.draw(); }
public synchronized void buildSpatialIndex() { vertexIndex = new STRtree(); edgeIndex = new STRtree(); Envelope env; // int xminx, xmax, ymin, ymax; for (Vertex v : graph.getVertices()) { Coordinate c = v.getCoordinate(); env = new Envelope(c); vertexIndex.insert(env, v); for (Edge e : v.getOutgoing()) { if (e.getGeometry() == null) continue; if (e instanceof PatternEdge || e instanceof StreetTransitLink || e instanceof StreetEdge || e instanceof PathwayEdge || e instanceof SimpleTransfer) { env = e.getGeometry().getEnvelopeInternal(); edgeIndex.insert(env, e); } } } vertexIndex.build(); edgeIndex.build(); }