Package org.geotools.caching.featurecache

Examples of org.geotools.caching.featurecache.FeatureCache


        features[i] = fb.buildFeature(i +"", new Object[]{new Integer(i), geoms[i]});
        mm.add(features[i]);
      }
     
      DataStore ds = new MemoryDataStore(mm);
      FeatureCache cache = new GridFeatureCache(ds.getFeatureSource(featureType.getTypeName()), 4, 4, MemoryStorage.createInstance());
     
      FilterFactory ff = new FilterFactoryImpl();
      Filter f1 = ff.bbox("the_geom", 0, 0, 4.4, 4.4, DefaultEngineeringCRS.CARTESIAN_2D.toString());
      Envelope e1 = new Envelope(0, 4.4, 0, 4.4);
     
      Filter f2 = ff.bbox("the_geom", 0, 4.6, 4.4, 8.5, DefaultEngineeringCRS.CARTESIAN_2D.toString());
      Envelope e2 = new Envelope(0, 4.4, 4.6, 8.5);
     
      Filter f3 = ff.bbox("the_geom", 4.6, 0, 8.5, 4.4, DefaultEngineeringCRS.CARTESIAN_2D.toString());
      Envelope e3 = new Envelope(4.6, 8.5, 0, 4.4);
     
      Filter f4 = ff.bbox("the_geom", 4.6, 4.6, 8.5, 8.5, DefaultEngineeringCRS.CARTESIAN_2D.toString());
      Envelope e4 = new Envelope(4.6, 8.5, 4.6, 8.5);     

      //there should be two features in each region
      FeatureCollection fc = cache.getFeatures(f1);
      assertEquals(2, fc.size());
     
      fc = cache.getFeatures(f2);
      assertEquals(2, fc.size());
     
      fc = cache.getFeatures(f3);
      assertEquals(2, fc.size());

      //at this point the cache should contain feature from area 2 & 3 and features from area 1
      //should have been evicted.
      assertEquals(0, ((GridFeatureCache)cache).peek(e4).size());
      assertEquals(0, ((GridFeatureCache)cache).peek(e1).size());
      assertEquals(2, ((GridFeatureCache)cache).peek(e2).size());
      assertEquals(2, ((GridFeatureCache)cache).peek(e3).size());
     
      //lets test the last region
      fc = cache.getFeatures(f4);
      assertEquals(2, fc.size());
     
      //at this point the cache should contain features from areas 3 & 4 and area 2 should
      //have been evicted;
      assertEquals(2, ((GridFeatureCache)cache).peek(e3).size());
      assertEquals(2, ((GridFeatureCache)cache).peek(e4).size());
      assertEquals(0, ((GridFeatureCache)cache).peek(e2).size());
      assertEquals(0, ((GridFeatureCache)cache).peek(e1).size());
     
      //lets query region 4 again
      fc = cache.getFeatures(f4);
      assertEquals(2, fc.size());
     
      //at this point the cache should contain features from areas 3 & 4 and area 2 should
      //have been evicted;
      assertEquals(2, ((GridFeatureCache)cache).peek(e3).size());
      assertEquals(2, ((GridFeatureCache)cache).peek(e4).size());
      assertEquals(0, ((GridFeatureCache)cache).peek(e2).size());
      assertEquals(0, ((GridFeatureCache)cache).peek(e1).size());     
     
      //now lets go back to 1
      fc = cache.getFeatures(f1);
      assertEquals(2, fc.size());

      assertEquals(2, ((GridFeatureCache)cache).peek(e4).size());
      assertEquals(2, ((GridFeatureCache)cache).peek(e1).size());
      assertEquals(0, ((GridFeatureCache)cache).peek(e2).size());
      assertEquals(0, ((GridFeatureCache)cache).peek(e3).size());
     
      //if we peek at 4
      fc = ((GridFeatureCache)cache).peek(e4);
      //now the cache should be order (least recently used to most recently used) 1, 4
      //ask for 2
      fc  = cache.getFeatures(f2);
      //cache: 4,2
      assertEquals(2, ((GridFeatureCache)cache).peek(e4).size());
      assertEquals(2, ((GridFeatureCache)cache).peek(e2).size());
      assertEquals(0, ((GridFeatureCache)cache).peek(e1).size());
      assertEquals(0, ((GridFeatureCache)cache).peek(e3).size());
View Full Code Here


    //
    // ---- CACHING FEATURE COLLECTION -----
    //
    DataStore ds = new MemoryDataStore(mm);
    SimpleFeatureSource fs = ds.getFeatureSource(featureType.getTypeName());
    FeatureCache cache = new StreamingGridFeatureCache(fs, 4, 4,MemoryStorage.createInstance());
   
    Filter upperLeft = filterFactory.bbox(featureType.getGeometryDescriptor().getLocalName(), 0, 5.1, 4.9, 9.9,featureType.getCoordinateReferenceSystem().toString());
    SimpleFeatureCollection fc = cache.getFeatures(upperLeft);
    assertEquals(2, fc.size());

    //this should end up getting the same features from the source that are already in the cache
    //however we only want one copy of those feature returned;
    Filter upperHalf = filterFactory.bbox(featureType.getGeometryDescriptor().getLocalName(), 0, 5.1, 9.9, 9.9,featureType.getCoordinateReferenceSystem().toString());
    fc = cache.getFeatures(upperHalf);
    assertEquals(2, fc.size());

  }
View Full Code Here

        features[i] = fb.buildFeature(i +"", new Object[]{new Integer(i), geoms[i]});
        mm.add(features[i]);
      }
     
      DataStore ds = new MemoryDataStore(mm);
      FeatureCache cache = new StreamingGridFeatureCache(ds.getFeatureSource(featureType.getTypeName()), 4, 4, MemoryStorage.createInstance());
     
      FilterFactory ff = new FilterFactoryImpl();
      Filter f1 = ff.bbox("the_geom", 0, 0, 4.4, 4.4, DefaultEngineeringCRS.CARTESIAN_2D.toString());
      Envelope e1 = new Envelope(0, 4.4, 0, 4.4);
     
      Filter f2 = ff.bbox("the_geom", 0, 4.6, 4.4, 8.5, DefaultEngineeringCRS.CARTESIAN_2D.toString());
      Envelope e2 = new Envelope(0, 4.4, 4.6, 8.5);
     
      Filter f3 = ff.bbox("the_geom", 4.6, 0, 8.5, 4.4, DefaultEngineeringCRS.CARTESIAN_2D.toString());
      Envelope e3 = new Envelope(4.6, 8.5, 0, 4.4);
     
      Filter f4 = ff.bbox("the_geom", 4.6, 4.6, 8.5, 8.5, DefaultEngineeringCRS.CARTESIAN_2D.toString());
      Envelope e4 = new Envelope(4.6, 8.5, 4.6, 8.5);     

      //there should be two features in each region
      FeatureCollection fc = cache.getFeatures(f1);
      assertEquals(2, fc.size());
     
      fc = cache.getFeatures(f2);
      assertEquals(2, fc.size());
     
      fc = cache.getFeatures(f3);
      assertEquals(2, fc.size());

      //at this point the cache should contain feature from area 2 & 3 and features from area 1
      //should have been evicted.
      assertEquals(0, cache.peek(e4).size());
      assertEquals(0, cache.peek(e1).size());
      assertEquals(2, cache.peek(e2).size());
      assertEquals(2, cache.peek(e3).size());
     
      fc = cache.getFeatures(f4);
      assertEquals(2, fc.size());
     
      //at this point the cache should contain features from areas 3 & 4 and area 2 should
      //have been evicted;
      assertEquals(2, cache.peek(e3).size());
      assertEquals(2, cache.peek(e4).size());
      assertEquals(0, cache.peek(e2).size());
      assertEquals(0, cache.peek(e1).size());
     
      //lets query region 4 again
      fc = cache.getFeatures(f4);
      assertEquals(2, fc.size());
     
      //at this point the cache should contain features from areas 3 & 4 and area 2 should
      //have been evicted;
      assertEquals(2, cache.peek(e3).size());
      assertEquals(2, cache.peek(e4).size());
      assertEquals(0, cache.peek(e2).size());
      assertEquals(0, cache.peek(e1).size());     
     
      //now lets go back to 1
      fc = cache.getFeatures(f1);
      assertEquals(2, fc.size());

      assertEquals(2, cache.peek(e4).size());
      assertEquals(2, cache.peek(e1).size());
      assertEquals(0, cache.peek(e2).size());
      assertEquals(0, cache.peek(e3).size());
     
      //if we peek at 4
      fc = cache.peek(e4);
      fc.size()//(note area isn't actually visited until features are iterated through
      //now the cache should be order (least recently used to most recently used) 1, 4

      //ask for 2
      //fc = cache.peek(e2);
      fc  = cache.getFeatures(f2);
      fc.size();
      //cache: 4,2
     
      assertEquals(2, cache.peek(e4).size());
      assertEquals(2, cache.peek(e2).size());
      assertEquals(0, cache.peek(e1).size());
      assertEquals(0, cache.peek(e3).size());
    }
View Full Code Here

TOP

Related Classes of org.geotools.caching.featurecache.FeatureCache

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.