Search in sources :

Example 86 with Envelope

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

the class TileRendererManager method renderTile.

public BufferedImage renderTile(final TileRequest tileRequest, String layer) {
    TileRenderContext context = new TileRenderContext() {

        @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;
        }
    };
    context.graph = graph;
    TileRenderer renderer = renderers.get(layer);
    if (renderer == null)
        throw new IllegalArgumentException("Unknown layer: " + layer);
    // The best place for caching tiles may be here
    BufferedImage image = new BufferedImage(tileRequest.width, tileRequest.height, renderer.getColorModel());
    context.graphics = image.createGraphics();
    Envelope2D trbb = tileRequest.bbox;
    context.bbox = new Envelope(trbb.x, trbb.x + trbb.width, trbb.y, trbb.y + trbb.height);
    context.transform = new AffineTransformation();
    double xScale = tileRequest.width / trbb.width;
    double yScale = tileRequest.height / trbb.height;
    context.transform.translate(-trbb.x, -trbb.y - trbb.height);
    context.transform.scale(xScale, -yScale);
    context.metersPerPixel = Math.toRadians(trbb.height) * 6371000 / tileRequest.height;
    context.tileWidth = tileRequest.width;
    context.tileHeight = tileRequest.height;
    long start = System.currentTimeMillis();
    renderer.renderTile(context);
    LOG.debug("Rendered tile at {},{} in {} ms", tileRequest.bbox.y, tileRequest.bbox.x, System.currentTimeMillis() - start);
    return image;
}
Also used : TileRenderContext(org.opentripplanner.inspector.TileRenderer.TileRenderContext) AffineTransformation(com.vividsolutions.jts.geom.util.AffineTransformation) Envelope(com.vividsolutions.jts.geom.Envelope) Envelope2D(org.geotools.geometry.Envelope2D) BufferedImage(java.awt.image.BufferedImage)

Example 87 with Envelope

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

the class HashGridTest method testHashGridRandom.

/**
 * We perform a non-regression random test. We insert many random-envelop objects
 * into both a hash grid (OTP) and STRtree (JTS) spatial indexes. We check with
 * many random query that the set of returned objects is the same (after pruning
 * because both could return false positives).
 */
@SuppressWarnings("unchecked")
public void testHashGridRandom() {
    final double X0 = -0.05;
    final double Y0 = 44.0;
    final double DX = 0.1;
    final double DY = 0.1;
    final int N_OBJS = 1000;
    final int N_QUERIES = 1000;
    Random rand = new Random(42);
    SpatialIndex hashGrid = new HashGridSpatialIndex<>();
    SpatialIndex strTree = new STRtree();
    for (int i = 0; i < N_OBJS; i++) {
        Coordinate a = new Coordinate(rand.nextDouble() * DX + X0, rand.nextDouble() * DY + Y0);
        Coordinate b = new Coordinate(rand.nextDouble() * DX + X0, rand.nextDouble() * DY + Y0);
        DummyObject obj = new DummyObject();
        obj.envelope = new Envelope(a, b);
        hashGrid.insert(obj.envelope, obj);
        strTree.insert(obj.envelope, obj);
    }
    for (int i = 0; i < N_QUERIES; i++) {
        Coordinate a = new Coordinate(rand.nextDouble() * DX + X0, rand.nextDouble() * DY + Y0);
        Coordinate b = new Coordinate(rand.nextDouble() * DX + X0, rand.nextDouble() * DY + Y0);
        Envelope searchEnv = new Envelope(a, b);
        List<DummyObject> hashGridObjs = hashGrid.query(searchEnv);
        // Need to remove non intersecting
        Set<DummyObject> hashGridObjs2 = new HashSet<>();
        for (DummyObject obj : hashGridObjs) {
            if (obj.envelope.intersects(searchEnv))
                hashGridObjs2.add(obj);
        }
        List<DummyObject> strtreeObjs = hashGrid.query(searchEnv);
        // Need to remove non intersecting
        Set<DummyObject> strtreeObjs2 = new HashSet<>();
        for (DummyObject obj : strtreeObjs) {
            if (obj.envelope.intersects(searchEnv))
                strtreeObjs2.add(obj);
        }
        boolean equals = hashGridObjs2.equals(strtreeObjs2);
        assertTrue(equals);
    }
}
Also used : Envelope(com.vividsolutions.jts.geom.Envelope) Random(java.util.Random) Coordinate(com.vividsolutions.jts.geom.Coordinate) SpatialIndex(com.vividsolutions.jts.index.SpatialIndex) STRtree(com.vividsolutions.jts.index.strtree.STRtree) HashSet(java.util.HashSet)

Example 88 with Envelope

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

the class ShowGraph method mouseClicked.

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

Example 89 with Envelope

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

the class ShowGraph method zoomToVertex.

public void zoomToVertex(Vertex v) {
    Envelope e = new Envelope();
    e.expandToInclude(v.getCoordinate());
    e.expandBy(0.002);
    modelBounds = e;
    drawLevel = DRAW_ALL;
}
Also used : Envelope(com.vividsolutions.jts.geom.Envelope)

Example 90 with Envelope

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

the class ShowGraph method zoomToLocation.

public void zoomToLocation(Coordinate c) {
    Envelope e = new Envelope();
    e.expandToInclude(c);
    e.expandBy(0.002);
    modelBounds = e;
    matchAspect();
    drawLevel = DRAW_ALL;
}
Also used : Envelope(com.vividsolutions.jts.geom.Envelope)

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