Angel, Eric wrote: > Is there a performance difference between using CQL vs creating your own > filters? > There are three ways to produce a Filter; they all produce the same object: 1. FilterFactory2 is fast; you as the programmer are saying exactly what you mean 2. CQL has the overhead of a lexer and parser to turn your String into a series of FilterFactory2 calls 3. Filter XML has the over head of SAX (and sometimes DOM or a GTXML parser) to turn your document into a series of FilterFactory2 calls
> I'm currently using the below code and it's really slow. > > --------------- > FilterFactory2 ff2 = > CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints()); > Expression stateProperty = ff2.property("STATE"); > Expression stateValue = ff2.literal(statecode); > Filter stateFilter = ff2.equals(stateProperty, stateValue); > > Filter nameFilter = ff2.equal(ff2.property("NAME"), > ff2.literal(cityname), false); > geoFilter = ff2.and(stateFilter, nameFilter); > > FeatureSource featureSource = > ds.getFeatureSource(ds.getTypeNames()[0]); > FeatureCollection featureCollection = > featureSource.getFeatures(geoFilter); > FeatureIterator iterator = featureCollection.features(); > ----------------- > > Is there a better way to do this if I'm doing this thousands of times per > minute? > That does not sound two sane; Things to try ... 1. using a FeatureID filter; it makes use of an identifier generated by the DataStore you are using; for a Shapefile this will be the row id and it will be able to make a couple calls; rather than go through and test ever feature. For a database this will end up using the primary key etc... 2. Related to the above: If you only expect one result indicate that in the query as max results value of 1, also you should only make use of the attributes you need; if you don't need any attributes at all shapefile will be able to find you a geometry must faster 3. If your data is small enough load it into a MemoryDataStore; that will store the fetaures in a TreeSet organized by FeatureID (so you can use the FeatureId filters very quickly) Jody ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Geotools-gt2-users mailing list Geotools-gt2-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users