Package com.vividsolutions.jts.index.strtree

Examples of com.vividsolutions.jts.index.strtree.STRtree


   *
   * @return the computed distance
   */
  public double getDistance(Geometry g)
  {
    STRtree tree2 = FacetSequenceTreeBuilder.build(g);
    Object[] obj = cachedTree.nearestNeighbour(tree2,
        new FacetSequenceDistance());
    return facetDistance(obj);
  }
View Full Code Here


    toNode.edges.add(fromNode);
  }

  public Node getClosestNode(double x, double y) {
    if (_index == null) {
      _index = new STRtree(_nodesById.size());
      for (Node node : _nodesById.values()) {
        _index.insert(new Envelope(node.x, node.x, node.y, node.y), node);
      }
      _index.build();
    }
View Full Code Here

  {
    public String toString() { return "STR[M=" + index.getNodeCapacity() + "]"; }
//    public String toString() { return "" + index.getNodeCapacity() + ""; }
    public STRtreeIndex(int nodeCapacity)
    {
      index = new STRtree(nodeCapacity);
    }
View Full Code Here

                    edges.put(new ReversibleLineStringWrapper(geom), e);
                }
            }
        }
        // insert unique edges
        pedestrianIndex = new STRtree();
        for (StreetEdge e : edges.values()) {
            LineString geom = e.getGeometry();
            pedestrianIndex.insert(geom.getEnvelopeInternal(), e);
        }
        pedestrianIndex.build();
View Full Code Here

        if (hashGrid) {
            edgeTree = new HashGridSpatialIndex<>();
            transitStopTree = new HashGridSpatialIndex<>();
            verticesTree = new HashGridSpatialIndex<>();
        } else {
            edgeTree = new STRtree();
            transitStopTree = new STRtree();
            verticesTree = new STRtree();
        }
        postSetup();
        if (!hashGrid) {
            ((STRtree) edgeTree).build();
            ((STRtree) transitStopTree).build();
View Full Code Here

        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);
View Full Code Here

    /*
     * 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();
View Full Code Here

    Graph graph;

    private STRtree index;

    STRtree createIndex() {
        STRtree edgeIndex = new STRtree();
        for (Vertex v : graph.getVertices()) {
            for (Edge e : v.getOutgoing()) {
                if (e instanceof StreetEdge) {
                    Envelope envelope;
                    Geometry geometry = e.getGeometry();
                    envelope = geometry.getEnvelopeInternal();
                    edgeIndex.insert(envelope, e);
                }
            }
        }
        log.debug("Created index");
        return edgeIndex;
View Full Code Here

        cloned.getHints().remove(Hints.GEOMETRY_DISTANCE);
       
        FeatureCollection features = wrapped.getFeatures(cloned);
        FeatureIterator fi = features.features();
        index = null;
        STRtree newIndex = new STRtree();
        while (fi.hasNext()) {
            // consider turning all geometries into packed ones, to save space
            Feature f = fi.next();
            newIndex.insert(ReferencedEnvelope.reference(f.getBounds()), f);
        }
        fi.close();
        index = newIndex;
        cachedQuery = query;
        cachedSchema = (SimpleFeatureType) features.getSchema();
View Full Code Here

            return;
        }

        // load shapefile end (docs marker)

        final SpatialIndex index = new STRtree();
        FeatureCollection features = source.getFeatures();
        System.out.println("Slurping in features ...");
        features.accepts(new FeatureVisitor() {

            @Override
            public void visit(Feature feature) {
                SimpleFeature simpleFeature = (SimpleFeature) feature;
                Geometry geom = (MultiLineString) simpleFeature.getDefaultGeometry();
                // Just in case: check for  null or empty geometry
                if (geom != null) {
                    Envelope env = geom.getEnvelopeInternal();
                    if (!env.isNull()) {
                        index.insert(env, new LocationIndexedLine(geom));
                    }
                }
            }
        }, new NullProgressListener());

        // cache features end (docs marker)

        /*
         * For test data, we generate a large number of points placed randomly
         * within the bounding rectangle of the features.
         */
        final int NUM_POINTS = 10000;
        ReferencedEnvelope bounds = features.getBounds();
        Coordinate[] points = new Coordinate[NUM_POINTS];
        Random rand = new Random(file.hashCode());
        for (int i = 0; i < NUM_POINTS; i++) {
            points[i] = new Coordinate(
                    bounds.getMinX() + rand.nextDouble() * bounds.getWidth(),
                    bounds.getMinY() + rand.nextDouble() * bounds.getHeight());
        }

        // generate points end (docs marker)

        /*
         * We defined the maximum distance that a line can be from a point
         * to be a candidate for snapping (1% of the width of the feature
         * bounds for this example).
         */
        final double MAX_SEARCH_DISTANCE = bounds.getSpan(0) / 100.0;

        // Maximum time to spend running the snapping process (milliseconds)
        final long DURATION = 5000;

        int pointsProcessed = 0;
        int pointsSnapped = 0;
        long elapsedTime = 0;
        long startTime = System.currentTimeMillis();
        while (pointsProcessed < NUM_POINTS &&
                (elapsedTime = System.currentTimeMillis() - startTime) < DURATION) {

            // Get point and create search envelope
            Coordinate pt = points[pointsProcessed++];
            Envelope search = new Envelope(pt);
            search.expandBy(MAX_SEARCH_DISTANCE);

            /*
             * Query the spatial index for objects within the search envelope.
             * Note that this just compares the point envelope to the line envelopes
             * so it is possible that the point is actually more distant than
             * MAX_SEARCH_DISTANCE from a line.
             */
            List<LocationIndexedLine> lines = index.query(search);

            // Initialize the minimum distance found to our maximum acceptable
            // distance plus a little bit
            double minDist = MAX_SEARCH_DISTANCE + 1.0e-6;
            Coordinate minDistPoint = null;
View Full Code Here

TOP

Related Classes of com.vividsolutions.jts.index.strtree.STRtree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.