How to create a filter by a propertyName ?

View: New views
2 Messages — Rating Filter:   Alert me  

How to create a filter by a propertyName ?

by Sovireak :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
I want to use geotools for getting features from my Datastore Oracle.
I want to get only features filtered by a list of names.
How can i manage to build my filter and my query to get this feature collection?

This is what i have tried :

public FeatureCollection getCollection(String typeName, List<String> featureIdList)
    throws IOException {
    FilterFactory filterFactory = FilterFactoryFinder.createFilterFactory();
    FidFilter fidFilter = filterFactory.createFidFilter();

    Iterator<String> featureIdIterator = featureIdList.iterator();
    while (featureIdIterator.hasNext()) {
        fidFilter.addFid(featureIdIterator.next());
    }
    DefaultQuery query = new DefaultQuery();
    query.setTypeName(typeName);
    query.setFilter(fidFilter);

   
    FeatureSource table = factory.getDataStore().getFeatureSource(typeName);
    return table.getFeatures(query);
}

The FeatureCollection does not contain my features.

Thanks

Re: How to create a filter by a propertyName ?

by Jody Garnett-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Fid filter is used to check the feature ids or identifiers; this
should work - however it sounds like you may have a list of names (in
the form of an attribute called "NAME")?.

If you would like to check an attribute please use an or filter to
perform a bunch of equals checks. You may also wish to consider the
use of the like filter and wild card expressions.

In CQL syntax:
NAME = 'Fred' OR NAME = 'John'

For more CQL examples check the user guide.

Jody

On Sat, Jun 6, 2009 at 2:41 AM, Sovireak<sovireak.moeung@...> wrote:

>
> Hi,
> I want to use geotools for getting features from my Datastore Oracle.
> I want to get only features filtered by a list of names.
> How can i manage to build my filter and my query to get this feature
> collection?
>
> This is what i have tried :
>
> public FeatureCollection getCollection(String typeName, List<String>
> featureIdList)
>    throws IOException {
>    FilterFactory filterFactory = FilterFactoryFinder.createFilterFactory();
>    FidFilter fidFilter = filterFactory.createFidFilter();
>
>    Iterator<String> featureIdIterator = featureIdList.iterator();
>    while (featureIdIterator.hasNext()) {
>        fidFilter.addFid(featureIdIterator.next());
>    }
>    DefaultQuery query = new DefaultQuery();
>    query.setTypeName(typeName);
>    query.setFilter(fidFilter);
>
>
>    FeatureSource table = factory.getDataStore().getFeatureSource(typeName);
>    return table.getFeatures(query);
> }
>
> The FeatureCollection does not contain my features.
>
> Thanks
> --
> View this message in context: http://www.nabble.com/How-to-create-a-filter-by-a-propertyName---tp23891628p23891628.html
> Sent from the geotools - dev mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email