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; }
public void zoomOut() { modelBounds.expandBy(modelBounds.getWidth(), modelBounds.getHeight()); drawLevel = DRAW_ALL; }
void zoom(double f, Point p) { double ex = modelBounds.getWidth() * f; double ey = modelBounds.getHeight() * f; modelBounds.expandBy(ex / 2, ey / 2); if (p != null) { // Note: Graphics Y coordinates increase down the screen, hence the opposite signs. double tx = ex * -((p.getX() / this.width) - 0.5); double ty = ey * +((p.getY() / this.height) - 0.5); modelBounds.translate(tx, ty); } // update the display drawLevel = DRAW_PARTIAL; }
@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; } }
private Geometry crudeProjectedBuffer(Point pt, double distanceMeters) { final double mPerDegreeLat = 111111.111111; double lat = pt.getY(); double lonScale = Math.cos(Math.PI * lat / 180); double latExpand = distanceMeters / mPerDegreeLat; double lonExpand = latExpand / lonScale; Envelope env = pt.getEnvelopeInternal(); env.expandBy(lonExpand, latExpand); return gf.toGeometry(env); }
/** * 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 zoomToLocation(Coordinate c) { Envelope e = new Envelope(); e.expandToInclude(c); e.expandBy(0.002); modelBounds = e; matchAspect(); drawLevel = DRAW_ALL; }
public void zoomToVertex(Vertex v) { Envelope e = new Envelope(); e.expandToInclude(v.getCoordinate()); e.expandBy(0.002); modelBounds = e; 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; } };
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; }
env.expandBy(searchRadiusLat / xscale, searchRadiusLat); @SuppressWarnings("unchecked") Collection<Vertex> vertices = graph.streetIndex.getVerticesForEnvelope(env);
@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; }
env.expandBy(SphericalDistanceLibrary.metersToLonDegrees(CLUSTER_RADIUS, s0.getLat()), SphericalDistanceLibrary.metersToDegrees(CLUSTER_RADIUS)); for (TransitStop ts1 : stopSpatialIndex.query(env)) {
void matchAspect() { /* Basic sinusoidal projection of lat/lon data to square pixels */ double yCenter = modelBounds.centre().y; float xScale = cos(radians((float) yCenter)); double newX = modelBounds.getHeight() * (1 / xScale) * ((float) this.getWidth() / this.getHeight()); modelBounds.expandBy((newX - modelBounds.getWidth()) / 2f, 0); }
/** * @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(); }
modelBounds.expandBy(0.02); matchAspect();