Andrea already indicated that you need to pass the featureSource to the map in
order to take advantage of the cache. It uses a spatial index internally to
make Query perform faster.
The CachingFeatureSource is good at grabbing data into the cache as needed; if
you know upfront that you can fit all your data into memory you can use a
different technique.
You may wish to consider another idea
-
http://docs.geotools.org/latest/userguide/library/main/collection.html#performance-options
SpatialIndexFeatureCollection (on the above page).
--
Jody Garnett
On Friday, 15 July 2011 at 8:53 PM, Emmanuel Blondel wrote:
> Dear all,
>
> I started using Geotools & I have some issue in using the
> CachingFeatureSource (presented here:
> http://geotoolsnews.blogspot.com/2010_04_01_archive.html)
> When I don't use the CachingFeatureSource, I can get all the features I
> want. If I use the cache, I don't get all features.
> Do you have any idea about how to solve this? You will find the code below.
>
> Thanks a lot in advance for your answers,
>
> Regards,
> Emmanuel
>
> Code:
>
> URL url = new URL( Constants.localGeoserverWFS );
> Map<String, Serializable> params = new HashMap<String, Serializable>();
> params.put(WFSDataStoreFactory.URL.key, url);
> params.put(WFSDataStoreFactory.TIMEOUT.key, new Integer(60000));
> params.put(WFSDataStoreFactory.MAXFEATURES.key, new Integer(200000));
> params.put(WFSDataStoreFactory.WFS_STRATEGY.key, "geoserver");
>
> DataStore store = DataStoreFinder.getDataStore(params);
>
> String typeName = "fao:t_statarea_csquare05_hseez_wgs84";
> SimpleFeatureSource featureSource = store.getFeatureSource(typeName);
>
> //Filter
> String textFilterEEZ ="geocode_1 IN('21','31') AND geocode_3 ='163'";
> Filter filterEEZ = ECQL.toFilter(textFilterEEZ);
> Query query = new Query( typeName, filterEEZ);
>
> //Cache
> CachingFeatureSource cacheFeatureSource = new
> CachingFeatureSource(featureSource);
> SimpleFeatureCollection features = cacheFeatureSource.getFeatures(query);
>
> //Default style
> StyleBuilder sb1 = new StyleBuilder();
> PolygonSymbolizer ps1 = sb1.createPolygonSymbolizer(new Color(185, 211,
> 238), new Color(58, 95, 205), 1);
> Style style = sb1.createStyle(ps1);
>
> //MapContext
> MapContext map = new DefaultMapContext();
> map.setTitle("Using cached features");
> map.addLayer(features, style);
> JMapFrame.showMap(map);
> --
> Emmanuel Blondel
> GIS Consultant
>
> Geographic Information Systems
> in Agronomy - Environment -Fisheries
> Email: [email protected] (mailto:[email protected]) -
> [email protected] (mailto:[email protected])
> Phone: +33 (0) 6 45 97 87 52
> ------------------------------------------------------------------------------
> AppSumo Presents a FREE Video for the SourceForge Community by Eric
> Ries, the creator of the Lean Startup Methodology on "Lean Startup
> Secrets Revealed." This video shows you how to validate your ideas,
> optimize your ideas and identify your business strategy.
> http://p.sf.net/sfu/appsumosfdev2dev
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> (mailto:[email protected])
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric
Ries, the creator of the Lean Startup Methodology on "Lean Startup
Secrets Revealed." This video shows you how to validate your ideas,
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users