Package com.vividsolutions.jts.index.strtree

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


        return false;
    }

    public synchronized void clear() {
        index = null;
        index = new STRtree();
        listeners.clear();
        listeners = null;
    }
View Full Code Here


        throw new IllegalArgumentException(
            "The provided SimpleFeatureCollection  or empty, it's impossible to create an index!");
     
      // now build the index
      // TODO make it configurable as far the index is involved
      STRtree tree = new STRtree();
      long size=0;
      while (it.hasNext()) {
        final GranuleDescriptor granule = it.next();
        final ReferencedEnvelope env=ReferencedEnvelope.reference(granule.getGranuleBBOX());
        final Geometry g = (Geometry)FeatureUtilities.getPolygon(
            new Rectangle2D.Double(env.getMinX(),env.getMinY(),env.getWidth(),env.getHeight()),0);
        tree.insert(g.getEnvelopeInternal(), granule);
      }
     
      // force index construction --> STRTrees are built on first call to
      // query
      tree.build();
     
      // save the soft reference
      index=tree;
    }
    catch (Throwable e) {
View Full Code Here

    junit.textui.TestRunner.main(testCaseName);
  }

  public void testEmptyTreeUsingListQuery() 
  {
    STRtree tree = new STRtree();
    List list = tree.query(new Envelope(0, 0, 1, 1));
    assertTrue(list.isEmpty());
  }
View Full Code Here

    assertTrue(list.isEmpty());
  }
 
  public void testEmptyTreeUsingItemVisitorQuery() 
  {
    STRtree tree = new STRtree();
    tree.query(new Envelope(0,0,1,1), new ItemVisitor() {
      public void visitItem(Object item) {
        assertTrue("Should never reach here", true);
      }
    })
  }
View Full Code Here

  public void testSpatialIndex()
  throws Exception
  {
    SpatialIndexTester tester = new SpatialIndexTester();
    tester.setSpatialIndex(new STRtree(4));
    tester.init();
    tester.run();
    assertTrue(tester.isSuccess());
  }
View Full Code Here

  public void testSerialization()
  throws Exception
  {
    SpatialIndexTester tester = new SpatialIndexTester();
    tester.setSpatialIndex(new STRtree(4));
    tester.init();

    STRtree tree = (STRtree) tester.getSpatialIndex();
    // create the index before serialization
    tree.query(new Envelope());
   
    byte[] data = SerializationUtil.serialize(tree);
    tree = (STRtree) SerializationUtil.deserialize(data);
   
    tester.setSpatialIndex(tree);
View Full Code Here

    tester.run();
    assertTrue(tester.isSuccess());
  }

  public void testDisallowedInserts() {
    STRtree t = new STRtree(5);
    t.insert(new Envelope(0, 0, 0, 0), new Object());
    t.insert(new Envelope(0, 0, 0, 0), new Object());
    t.query(new Envelope());
    try {
      t.insert(new Envelope(0, 0, 0, 0), new Object());
      assertTrue(false);
    }
    catch (AssertionFailedException e) {
      assertTrue(true);
    }
View Full Code Here

     * into groups of close geometries.
     * This makes unioning more efficient, since vertices are more likely
     * to be eliminated on each round.
     */
//    STRtree index = new STRtree();
    STRtree index = new STRtree(STRTREE_NODE_CAPACITY);
    for (Iterator i = inputPolys.iterator(); i.hasNext(); ) {
      Geometry item = (Geometry) i.next();
      index.insert(item.getEnvelopeInternal(), item);
    }
    List itemTree = index.itemsTree();

//    printItemEnvelopes(itemTree);
   
    Geometry unionAll = unionTree(itemTree);
    return unionAll;
View Full Code Here

                polygonizer.add(g);
            }

            ArrayList polys = (ArrayList) polygonizer.getPolygons();

            final SpatialIndex idx = new STRtree();
            FeatureIterator mt = areaMainCollection.features();
            try {
                while (mt.hasNext()) {
                    try {
                        SimpleFeature feat = (SimpleFeature) mt.next();
                        Geometry point = (Geometry) feat.getAttribute(geomName
                                + "_point");
                        idx.insert(point.getEnvelopeInternal(), feat);
                    } catch (NullPointerException e) {
                        // Gibts anscheinend in anderen Kantonen.
                        logger.warn("Empty point found.");
                    }
                }
            } finally {
                mt.close();
            }

            ArrayList<Polygon> holes = new ArrayList();

            for (int i = 0; i < polys.size(); i++) {
                boolean found = false;
                Polygon p = (Polygon) polys.get(i);
                PreparedPolygon ppoly = new PreparedPolygon(p);

                for (final Object o : idx.query(p.getEnvelopeInternal())) {
                    SimpleFeature f = (SimpleFeature) o;

                    // Funktioniert auch intersect? Schneller?
                    if (ppoly.contains(((Geometry) f.getAttribute(geomName
                            + "_point")))) {
                        f.setAttribute(geomName, p);
                        features.add(f);
                        found = true;
                        break;
                    }
                }

                if (!found) {

                    // Falls wirklich bewusste Löcher im Datensatz sind, führt
                    // das zu falschen
                    // Resultaten. Nur zu den "holes" hinzufügen, falls kleiner
                    // als ein bestimmter Wert.
                    if (p.getArea() < 1.0) {
                        holes.add(p);
                    }
                }
            }

            // Restflächen, die aufgrund des neu Verknotens entstanden sind,
            // werden dem Polygon mit der längsten gemeinsamen Kanten
            // zugewiesen.
            // Mal schauen obs schon hinhaut.
            boolean repair = true;
            if (repair) {
                final SpatialIndex spatialIndex = new STRtree();
                Iterator nt = features.iterator();

                while (nt.hasNext()) {
                    SimpleFeature feat = (SimpleFeature) nt.next();
                    Geometry point = (Geometry) feat.getAttribute(geomName);
                    spatialIndex.insert(point.getEnvelopeInternal(), feat);
                }

                logger.debug("Anzahl Löcher: ");
                logger.debug(holes.size());
                for (int i = 0; i < holes.size(); i++) {
                    Polygon p = holes.get(i);
                    PreparedPolygon ppoly = new PreparedPolygon(p);

                    double length = 0.0;
                    SimpleFeature feat = null;

                    for (final Object o : spatialIndex.query(p
                            .getEnvelopeInternal())) {
                        SimpleFeature f = (SimpleFeature) o;
                        Geometry g = ((Geometry) f.getAttribute(geomName));
                        if (ppoly.intersects(g)) {
                            // logger.debug("***************************");
 
View Full Code Here

    private SpatialIndex spatialIndex;

    public IndexedFeatureCollection(FeatureCollection fc) {
        //Based on tests on Victoria ICI data, 10 is an optimum node-capacity for
        //fast queries. [Jon Aquino]
        this(fc, new STRtree(10));
    }
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.