Package org.geotools.caching.spatialindex

Examples of org.geotools.caching.spatialindex.NodeIdentifier


        while (this.getStatistics().getNumberOfData() >= this.featureCapacity) {
          if (!getEvictionPolicy().evict()) {
            // no more space left and nothing else to evict
            // need to evict the areas covered by this feature
            NodeCursor cc = new NodeCursor(getRootNode(), shape);
            NodeIdentifier next = null;
            int cnt = 0;
            while ((next = cc.getNext()) != null) {
              Node n = readNode(next);
              cnt += n.getDataCount();
              n.clear();
View Full Code Here


        List<NodeIdentifier> missing_tiles = tiles[0];
       
        if (missing_tiles.size() > max_tiles) {
          Envelope env = new Envelope(e);
          for (Iterator<NodeIdentifier> it = missing_tiles.iterator(); it.hasNext();) {
            NodeIdentifier id = it.next();
                Envelope nextenv = CacheUtil.convert((Region) (id.getShape()));
                env.expandToInclude(nextenv);
          }
            missing.add(env);
        } else {
            for (Iterator<NodeIdentifier> it = missing_tiles.iterator(); it.hasNext();) {
              NodeIdentifier id = it.next();
                Region next = (Region) (id.getShape());
                missing.add(CacheUtil.convert(next));
            }
        }

        return missing;
View Full Code Here

            //isn't considered an access; it might be better to improve the way containment query is done.
            boolean recordaccess = this.tracker.getDoRecordAccess();
            try{
                this.tracker.setDoRecordAccess(false);
                for( Iterator<NodeIdentifier> iterator = nodes.iterator(); iterator.hasNext(); ) {
                    NodeIdentifier nodeIdentifier = (NodeIdentifier) iterator.next();
                    nodeIdentifier.setValid(true);
                }
            }finally{
                this.tracker.setDoRecordAccess(recordaccess);
            }
        } finally {
View Full Code Here

            //isn't considered an access; it might be better to improve the way containment query is done.
            boolean recordaccess = this.tracker.getDoRecordAccess();
            try{
                this.tracker.setDoRecordAccess(false);
                for( Iterator<NodeIdentifier> iterator = nodes.iterator(); iterator.hasNext(); ) {
                    NodeIdentifier nodeIdentifier = (NodeIdentifier) iterator.next();
                    nodeIdentifier.setValid(false);
                }
            }finally{
                this.tracker.setDoRecordAccess(recordaccess);
            }
        } finally {
View Full Code Here

    /**
     *
     * @return the next node id in the cursor; will return null if no more nodes
     */
    public NodeIdentifier getNext(){
        NodeIdentifier ret = null;
        if (hasNext){
            ret = root.getChildIdentifier(root.gridIndexToNodeId(cursor));
        }
        int dims = cursor.length;
        for (int i = 0; i < dims; i++) {
View Full Code Here

          this.grid.readUnLock();
          cacheFeatureReader = new GridCacheFeatureReader(found, (GridSpatialIndex)grid.getIndex());
      }else{
          //need a write lock; release all read locks
          for( Iterator<NodeIdentifier> iterator = found.iterator(); iterator.hasNext(); ) {
                    NodeIdentifier nodeid = (NodeIdentifier) iterator.next();
                    nodeid.readUnLock();
          }
          this.grid.readUnLock();
          this.grid.writeLock();
          try{
              //re-get read locks
              acquireReadLocks(missing, found);
         
              // acquire write locks
              if (missing.size() > 0 && fs != null) {
                        acquireWriteLocks(missing, found);
              }
             
              // register working area
              if (missing.size() > 0 && fs != null) {
                       this.grid.register(missing);
              }
          }finally{
              this.grid.writeUnLock();
          }
         
                 if (fs != null) {
                    // note that for performance reasons this query might actually return
                    // features from an area larger than we are interested in caching
                    DefaultQuery dq = new DefaultQuery(featureType.getName().getLocalPart(), this.createFilter(missing));
                    dq.setCoordinateSystem(featureType.getCoordinateReferenceSystem());
                    if (query != null) {
                        dq.setHints(query.getHints());
                        dq.setHandle(query.getHandle());
                    } else {
                        dq.setHints(new Hints(Hints.JTS_COORDINATE_SEQUENCE_FACTORY,new LiteCoordinateSequenceFactory()));
                    }
                    try{
                        sourceFeatureReader = ((DataStore) fs.getDataStore()).getFeatureReader(dq,Transaction.AUTO_COMMIT);
                    }catch (Exception ex){
                        //nothing to get
                        missing.clear();
                        sourceFeatureReader = null;
                    }
                } else {
                    missing.clear(); // we didn't get anything so we don't want to register these as write locks
                }

                if (found.size() > 0) {
                    cacheFeatureReader = new GridCacheFeatureReader(found, (GridSpatialIndex) grid.getIndex());
                }
      }
     
      boolean localcache = cacheFeatures;
      if (query != null && query.getMaxFeatures() != Integer.MAX_VALUE){
          localcache = false;
      }
      FeatureReader<SimpleFeatureType, SimpleFeature> fr = null;
      if (sourceFeatureReader != null && cacheFeatureReader != null){
          fr = new CombiningCachingFeatureReader(cacheFeatureReader, sourceFeatureReader, false, localcache, grid.getIndex(), this.postFilter);
      }else if (sourceFeatureReader != null && cacheFeatureReader == null){
          fr = new CombiningCachingFeatureReader(new EmptyFeatureReader<SimpleFeatureType, SimpleFeature>((SimpleFeatureType)featureType), sourceFeatureReader, false, localcache, grid.getIndex(), this.postFilter);
      }else if (sourceFeatureReader == null && cacheFeatureReader != null){
          fr = new CombiningCachingFeatureReader(cacheFeatureReader, new EmptyFeatureReader<SimpleFeatureType, SimpleFeature>((SimpleFeatureType)featureType), false, false, grid.getIndex(), this.postFilter);
      }else{
          fr = new CombiningCachingFeatureReader(new EmptyFeatureReader<SimpleFeatureType, SimpleFeature>((SimpleFeatureType)featureType), new EmptyFeatureReader<SimpleFeatureType, SimpleFeature>((SimpleFeatureType)featureType), false, false, grid.getIndex(), this.postFilter);
      }
     
      it = new FeatureReaderFeatureIterator(wrapFeatureReader(fr), missing, found);

    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Failed to create feature collection iterator.", ex);
          if (missing != null){
              for( Iterator<NodeIdentifier> iterator = missing.iterator(); iterator.hasNext(); ) {
                  NodeIdentifier nodeid = (NodeIdentifier) iterator.next();
                  nodeid.writeUnLock();
              }
          }
          if (found != null){
              for( Iterator<NodeIdentifier> iterator = found.iterator(); iterator.hasNext(); ) {
                    NodeIdentifier nodeid = (NodeIdentifier) iterator.next();
                    nodeid.readUnLock();
                }
          }
        if (missing != null){
            this.grid.unregister(missing);
        }
View Full Code Here

   * @throws Exception
   */
    private void acquireWriteLocks( List<NodeIdentifier> missing, List<NodeIdentifier> found )
            throws Exception {
        for( Iterator<NodeIdentifier> iterator = missing.iterator(); iterator.hasNext(); ) {
            NodeIdentifier nodeid = (NodeIdentifier) iterator.next();
            try {
                nodeid.writeLock();
            }catch (Exception ex){
                //error occurred; remove from list
                iterator.remove();
                logger.log(Level.SEVERE, "Could not acquire necessary write locks.", ex);
                continue;
            }
            if (nodeid.isValid()) {
                // might have been validated by previous thread; so lets make sure we have the correct queue
                nodeid.readLock();
                found.add(nodeid);
                nodeid.writeUnLock();
                iterator.remove();
            }
        }
    }
View Full Code Here

     * @param missing
     * @param found
     */
    private void acquireReadLocks( List<NodeIdentifier> missing, List<NodeIdentifier> found ) {
        for( Iterator<NodeIdentifier> iterator = found.iterator(); iterator.hasNext(); ) {
            NodeIdentifier nodeid = (NodeIdentifier) iterator.next();
            try {
                nodeid.readLock();
            } catch (Exception ex) {
                // remove from list
                logger.log(Level.SEVERE, "Could not acquire necessary read locks.", ex);
                iterator.remove();
                continue;
            }
            if (!nodeid.isValid()) {
                // this node is no longer valid add to missing list
                nodeid.readUnLock();
                missing.add(nodeid);
                iterator.remove();
            }
        }
    }
View Full Code Here

        assertEquals(node.getCapacity(), node.children.size());

        double size = node.getShape().getArea() / node.getCapacity();

        for (Iterator<NodeIdentifier> it = node.children.iterator(); it.hasNext();) {
            NodeIdentifier next = (NodeIdentifier) it.next();
            assertTrue(node.getShape().intersects(next.getShape()));
            assertEquals(size, next.getShape().getArea(), 1e-2);
        }
    }
View Full Code Here

        assertEquals(node3D.getCapacity(), node3D.children.size());

        double size = node3D.getShape().getArea() / node3D.getCapacity();

        for (Iterator<NodeIdentifier> it = node3D.children.iterator(); it.hasNext();) {
            NodeIdentifier next = (NodeIdentifier) it.next();
            assertTrue(node3D.getShape().intersects(next.getShape()));
            assertEquals(size, next.getShape().getArea(), 1e-2);
        }
    }
View Full Code Here

TOP

Related Classes of org.geotools.caching.spatialindex.NodeIdentifier

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.