Search in sources :

Example 56 with Envelope

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

the class GeocoderServerTest method testGeocodeValidAddress.

@Test
public void testGeocodeValidAddress() {
    final double lat = 78.121;
    final double lng = -43.237;
    final String description = "121 elm street";
    geocoderServer.geocoder = new Geocoder() {

        @Override
        public GeocoderResults geocode(String address, Envelope bbox) {
            GeocoderResult result = new GeocoderResult(lat, lng, description);
            return new GeocoderResults(Arrays.asList(result));
        }
    };
    GeocoderResults results = geocoderServer.geocode("121 elm street", null);
    for (GeocoderResult result : results.getResults()) {
        // should only have one result
        assertEquals("description matches", description, result.getDescription());
        assertEquals(lat, result.getLat(), 0.001);
        assertEquals(lng, result.getLng(), 0.001);
    }
}
Also used : GeocoderResults(org.opentripplanner.geocoder.GeocoderResults) Envelope(com.vividsolutions.jts.geom.Envelope) Geocoder(org.opentripplanner.geocoder.Geocoder) GeocoderResult(org.opentripplanner.geocoder.GeocoderResult) Test(org.junit.Test)

Example 57 with Envelope

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

the class ShowGraph method buildSpatialIndex.

/*
     * Iterate through all vertices and their (outgoing) edges. If they are of 'interesting' types, 
     * add them to the corresponding spatial index.
     */
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();
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) Coordinate(com.vividsolutions.jts.geom.Coordinate) STRtree(com.vividsolutions.jts.index.strtree.STRtree) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) PathwayEdge(org.opentripplanner.routing.edgetype.PathwayEdge) SimpleTransfer(org.opentripplanner.routing.edgetype.SimpleTransfer) Envelope(com.vividsolutions.jts.geom.Envelope) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) PathwayEdge(org.opentripplanner.routing.edgetype.PathwayEdge) PatternEdge(org.opentripplanner.routing.edgetype.PatternEdge) Edge(org.opentripplanner.routing.graph.Edge) PatternEdge(org.opentripplanner.routing.edgetype.PatternEdge)

Example 58 with Envelope

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

the class ShowGraph method setup.

/*
     * Setup Processing applet
     */
public void setup() {
    size(getSize().width, getSize().height, P2D);
    /* Build spatial index of vertices and edges */
    buildSpatialIndex();
    /* Set model bounds to encompass all vertices in the index, and then some */
    modelBounds = (Envelope) (vertexIndex.getRoot().getBounds());
    modelBounds.expandBy(0.02);
    matchAspect();
    /* save this zoom level to allow returning to default later */
    modelOuterBounds = new Envelope(modelBounds);
    /* find and set up the appropriate font */
    String[] fonts = PFont.list();
    String[] preferredFonts = { "Mono", "Courier" };
    PFont font = null;
    for (String preferredFontName : preferredFonts) {
        for (String fontName : fonts) {
            if (fontName.contains(preferredFontName)) {
                font = createFont(fontName, 16);
                break;
            }
        }
        if (font != null) {
            break;
        }
    }
    textFont(font);
    textMode(SCREEN);
    addMouseWheelListener(this);
    addMouseMotionListener(new MouseMotionAdapter() {

        @Override
        public void mouseMoved(MouseEvent e) {
            super.mouseMoved(e);
            Point p = e.getPoint();
            mouseModelX = toModelX(p.x);
            mouseModelY = toModelY(p.y);
        }
    });
    addComponentListener(new ComponentAdapter() {

        public void componentResized(ComponentEvent e) {
            matchAspect();
            drawLevel = DRAW_PARTIAL;
        }
    });
    frameRate(FRAME_RATE);
}
Also used : MouseMotionAdapter(java.awt.event.MouseMotionAdapter) MouseEvent(java.awt.event.MouseEvent) PFont(processing.core.PFont) Point(java.awt.Point) ComponentEvent(java.awt.event.ComponentEvent) Envelope(com.vividsolutions.jts.geom.Envelope) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 59 with Envelope

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

the class ShowGraph method drawAnotation.

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

Example 60 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.

the class LsTree method runInternal.

@Override
public void runInternal(final GeogigCLI cli) throws IOException {
    String ref;
    if (refList.isEmpty()) {
        ref = null;
    } else {
        ref = refList.get(0);
    }
    Strategy lsStrategy = Strategy.CHILDREN;
    if (recursive) {
        if (includeTrees) {
            lsStrategy = Strategy.DEPTHFIRST;
        } else if (onlyTrees) {
            lsStrategy = Strategy.DEPTHFIRST_ONLY_TREES;
        } else {
            lsStrategy = Strategy.DEPTHFIRST_ONLY_FEATURES;
        }
    } else {
        if (onlyTrees) {
            lsStrategy = Strategy.TREES_ONLY;
        }
    }
    Iterator<NodeRef> iter = cli.getGeogig().command(LsTreeOp.class).setReference(ref).setStrategy(lsStrategy).call();
    final ConsoleReader console = cli.getConsole();
    Function<NodeRef, CharSequence> printFunctor = new Function<NodeRef, CharSequence>() {

        @Override
        public CharSequence apply(NodeRef input) {
            StringBuilder sb = new StringBuilder();
            if (!verbose) {
                sb.append(input.path());
            } else {
                Envelope env = new Envelope();
                input.getNode().expand(env);
                StringBuilder sbenv = new StringBuilder();
                sbenv.append(Double.toString(env.getMinX())).append(";").append(Double.toString(env.getMaxX())).append(";").append(Double.toString(env.getMinY())).append(";").append(Double.toString(env.getMaxY()));
                sb.append(input.getMetadataId().toString()).append(' ').append(input.getType().toString().toLowerCase()).append(' ').append(input.objectId().toString()).append(' ').append(input.path()).append(' ').append(sbenv);
                if (input.getType().equals(TYPE.TREE)) {
                    RevTree tree = cli.getGeogig().command(RevObjectParse.class).setObjectId(input.objectId()).call(RevTree.class).get();
                    sb.append(' ').append(tree.size()).append(' ').append(tree.numTrees());
                }
            }
            return sb;
        }
    };
    Iterator<CharSequence> lines = Iterators.transform(iter, printFunctor);
    while (lines.hasNext()) {
        console.println(lines.next());
    }
    console.flush();
}
Also used : ConsoleReader(jline.console.ConsoleReader) Envelope(com.vividsolutions.jts.geom.Envelope) NodeRef(org.locationtech.geogig.api.NodeRef) Function(com.google.common.base.Function) LsTreeOp(org.locationtech.geogig.api.plumbing.LsTreeOp) Strategy(org.locationtech.geogig.api.plumbing.LsTreeOp.Strategy) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevTree(org.locationtech.geogig.api.RevTree)

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