Search in sources :

Example 91 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.

the class ShowGraph method zoomToDefault.

public void zoomToDefault() {
    modelBounds = new Envelope(modelOuterBounds);
    drawLevel = DRAW_ALL;
}
Also used : Envelope(com.vividsolutions.jts.geom.Envelope)

Example 92 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.

the class GeocoderServerTest method testGeocodeInvalidAddress.

@Test
public void testGeocodeInvalidAddress() {
    final String error = "uh oh";
    geocoderServer.geocoder = new Geocoder() {

        @Override
        public GeocoderResults geocode(String address, Envelope bbox) {
            return new GeocoderResults(error);
        }
    };
    GeocoderResults result = geocoderServer.geocode("121 elm street", null);
    assertEquals("error returned", error, result.getError());
}
Also used : GeocoderResults(org.opentripplanner.geocoder.GeocoderResults) Envelope(com.vividsolutions.jts.geom.Envelope) Geocoder(org.opentripplanner.geocoder.Geocoder) Test(org.junit.Test)

Example 93 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.

the class TransitStopsRegionsSourceImpl method getRegions.

@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;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Coordinate(com.vividsolutions.jts.geom.Coordinate) ArrayList(java.util.ArrayList) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 94 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.

the class GraphIndex method findNearbyStopClusters.

/**
 * 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;
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) StopCluster(org.opentripplanner.profile.StopCluster) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 95 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.

the class EdgeVertexTileRenderer method renderTile.

@Override
public void renderTile(TileRenderContext context) {
    float lineWidth = (float) (1.0f + 3.0f / Math.sqrt(context.metersPerPixel));
    // Grow a bit the envelope to prevent rendering glitches between tiles
    Envelope bboxWithMargins = context.expandPixels(lineWidth * 2.0, lineWidth * 2.0);
    Collection<Vertex> vertices = context.graph.streetIndex.getVerticesForEnvelope(bboxWithMargins);
    Collection<Edge> edges = context.graph.streetIndex.getEdgesForEnvelope(bboxWithMargins);
    Set<Edge> edgesSet = new HashSet<>(edges);
    /*
         * Some edges do not have geometry and thus do not get spatial-indexed. Add
         * outgoing/incoming edges of all vertices. This is not perfect, as if the edge cross a tile
         * it will not be rendered on it.
         */
    for (Vertex vertex : vertices) {
        edgesSet.addAll(vertex.getIncoming());
        edgesSet.addAll(vertex.getOutgoing());
    }
    // Note: we do not use the transform inside the shapeWriter, but do it ourselves
    // since it's easier for the offset to work in pixel size.
    ShapeWriter shapeWriter = new ShapeWriter(new IdentityPointTransformation(), new PointShapeFactory.Point());
    GeometryFactory geomFactory = new GeometryFactory();
    Stroke stroke = new BasicStroke(lineWidth * 1.4f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
    Stroke halfStroke = new BasicStroke(lineWidth * 0.6f + 1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
    Stroke halfDashedStroke = new BasicStroke(lineWidth * 0.6f + 1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1.0f, new float[] { 4 * lineWidth, lineWidth }, 2 * lineWidth);
    Stroke arrowStroke = new ShapeStroke(new Polygon(new int[] { 0, 0, 30 }, new int[] { 0, 20, 10 }, 3), lineWidth / 2, 5.0f * lineWidth, 2.5f * lineWidth);
    BasicStroke thinStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
    Font font = new Font(Font.SANS_SERIF, Font.PLAIN, Math.round(lineWidth));
    Font largeFont = new Font(Font.SANS_SERIF, Font.PLAIN, Math.round(lineWidth * 1.5f));
    FontMetrics largeFontMetrics = context.graphics.getFontMetrics(largeFont);
    context.graphics.setFont(largeFont);
    context.graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    context.graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    BufferParameters bufParams = new BufferParameters();
    bufParams.setSingleSided(true);
    bufParams.setJoinStyle(BufferParameters.JOIN_BEVEL);
    // Render all edges
    EdgeVisualAttributes evAttrs = new EdgeVisualAttributes();
    for (Edge edge : edgesSet) {
        evAttrs.color = null;
        evAttrs.label = null;
        Geometry edgeGeom = edge.getGeometry();
        boolean hasGeom = true;
        if (edgeGeom == null) {
            Coordinate[] coordinates = new Coordinate[] { edge.getFromVertex().getCoordinate(), edge.getToVertex().getCoordinate() };
            edgeGeom = GeometryUtils.getGeometryFactory().createLineString(coordinates);
            hasGeom = false;
        }
        boolean render = evRenderer.renderEdge(edge, evAttrs);
        if (!render)
            continue;
        Geometry midLineGeom = context.transform.transform(edgeGeom);
        OffsetCurveBuilder offsetBuilder = new OffsetCurveBuilder(new PrecisionModel(), bufParams);
        Coordinate[] coords = offsetBuilder.getOffsetCurve(midLineGeom.getCoordinates(), lineWidth * 0.4);
        if (coords.length < 2)
            // Can happen for very small edges (<1mm)
            continue;
        LineString offsetLine = geomFactory.createLineString(coords);
        Shape midLineShape = shapeWriter.toShape(midLineGeom);
        Shape offsetShape = shapeWriter.toShape(offsetLine);
        context.graphics.setStroke(hasGeom ? halfStroke : halfDashedStroke);
        context.graphics.setColor(evAttrs.color);
        context.graphics.draw(offsetShape);
        if (lineWidth > 6.0f) {
            context.graphics.setColor(Color.WHITE);
            context.graphics.setStroke(arrowStroke);
            context.graphics.draw(offsetShape);
        }
        if (lineWidth > 4.0f) {
            context.graphics.setColor(Color.BLACK);
            context.graphics.setStroke(thinStroke);
            context.graphics.draw(midLineShape);
        }
        if (evAttrs.label != null && lineWidth > 8.0f) {
            context.graphics.setColor(Color.BLACK);
            context.graphics.setStroke(new TextStroke("    " + evAttrs.label + "                              ", font, false, true));
            context.graphics.draw(offsetShape);
        }
    }
    // Render all vertices
    VertexVisualAttributes vvAttrs = new VertexVisualAttributes();
    for (Vertex vertex : vertices) {
        vvAttrs.color = null;
        vvAttrs.label = null;
        Point point = geomFactory.createPoint(new Coordinate(vertex.getLon(), vertex.getLat()));
        boolean render = evRenderer.renderVertex(vertex, vvAttrs);
        if (!render)
            continue;
        Point tilePoint = (Point) context.transform.transform(point);
        Shape shape = shapeWriter.toShape(tilePoint);
        context.graphics.setColor(vvAttrs.color);
        context.graphics.setStroke(stroke);
        context.graphics.draw(shape);
        if (vvAttrs.label != null && lineWidth > 6.0f && context.bbox.contains(point.getCoordinate())) {
            context.graphics.setColor(Color.BLACK);
            int labelWidth = largeFontMetrics.stringWidth(vvAttrs.label);
            /*
                 * Poor man's solution: stay on the tile if possible. Otherwise the renderer would
                 * need to expand the envelope by an unbounded amount (max label size).
                 */
            double x = tilePoint.getX();
            if (x + labelWidth > context.tileWidth)
                x -= labelWidth;
            context.graphics.drawString(vvAttrs.label, (float) x, (float) tilePoint.getY());
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Vertex(org.opentripplanner.routing.graph.Vertex) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Shape(java.awt.Shape) PointShapeFactory(com.vividsolutions.jts.awt.PointShapeFactory) PrecisionModel(com.vividsolutions.jts.geom.PrecisionModel) Envelope(com.vividsolutions.jts.geom.Envelope) Font(java.awt.Font) FontMetrics(java.awt.FontMetrics) TextStroke(com.jhlabs.awt.TextStroke) Polygon(java.awt.Polygon) HashSet(java.util.HashSet) ShapeStroke(com.jhlabs.awt.ShapeStroke) Stroke(java.awt.Stroke) TextStroke(com.jhlabs.awt.TextStroke) BasicStroke(java.awt.BasicStroke) ShapeWriter(com.vividsolutions.jts.awt.ShapeWriter) ShapeStroke(com.jhlabs.awt.ShapeStroke) BufferParameters(com.vividsolutions.jts.operation.buffer.BufferParameters) OffsetCurveBuilder(com.vividsolutions.jts.operation.buffer.OffsetCurveBuilder) Point(com.vividsolutions.jts.geom.Point) Point(com.vividsolutions.jts.geom.Point) Geometry(com.vividsolutions.jts.geom.Geometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) IdentityPointTransformation(com.vividsolutions.jts.awt.IdentityPointTransformation) Edge(org.opentripplanner.routing.graph.Edge)

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