Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [udig-devel] Layer Attribute Query

Jesse,

 

Thanks for the help. I have got this working as follows

 

URL shpFileURL = new File("C:/temp/test.shp").toURL();

                 

ShapefileDataStore store = new ShapefileDataStore(shpFileURL);

                 

String nameOfFeatureType = store.getTypeNames()[0];

System.out.println("nameOfFeatureType " + nameOfFeatureType);

 

FeatureSource source = store.getFeatureSource(nameOfFeatureType);

 

FilterFactory filterFactory = FilterFactoryFinder.createFilterFactory();

 

FidFilter filter1 = filterFactory.createFidFilter("test.1");

FidFilter filter2 = filterFactory.createFidFilter("test.2");

 

Feature feature1 = source.getFeatures(filter1).features().next();

Feature feature2 = source.getFeatures(filter2).features().next();

             

System.out.println("Num features1: " + source.getFeatures(filter1).size());

System.out.println("Num features2: " + source.getFeatures(filter2).size());

 

but I would like to perform an attribute query on a field rather than an ID query, I am trying a new filter

 

CompareFilter filter1 = filterFactory.createCompareFilter(CompareFilter.COMPARE_EQUALS);

filter1.addLeftValue(filterFactory.createAttributeExpression("Short_name"));

filter1.addRightValue(filterFactory.createAttributeExpression("CAWSAND DG RAN"));

             

CompareFilter filter2 = filterFactory.createCompareFilter(CompareFilter.COMPARE_EQUALS);

filter2.addLeftValue(filterFactory.createAttributeExpression("Short_name"));

filter2.addRightValue(filterFactory.createAttributeExpression("WEMBURY A"));

 

Feature feature1 = source.getFeatures(filter1).features().next();

Feature feature2 = source.getFeatures(filter2).features().next();

             

System.out.println("Num features1: " + source.getFeatures(filter1).size());

System.out.println("Num features2: " + source.getFeatures(filter2).size());

 

 

but it does filter the results properly, I get returned too many features. Is this the correct filter and syntax

 

Cheers
Andy

 


From: udig-devel-bounces@xxxxxxxxxxxxxxxxxxxxx [mailto:udig-devel-bounces@xxxxxxxxxxxxxxxxxxxxx] On Behalf Of Andy Cox
Sent: 15 August 2007 08:24
To: 'User-friendly Desktop Internet GIS'
Subject: RE: [udig-devel] Layer Attribute Query

 

Jesse,

 

Thanks for the pointers. Is there an easy way to search the e-mail list archives for previous posts as you suggest below ?

 

Cheers

Andy

 


From: udig-devel-bounces@xxxxxxxxxxxxxxxxxxxxx [mailto:udig-devel-bounces@xxxxxxxxxxxxxxxxxxxxx] On Behalf Of Jesse Eichar
Sent: 14 August 2007 17:28
To: User-friendly Desktop Internet GIS
Subject: Re: [udig-devel] Layer Attribute Query

 

Hi,

 

You'll want to look at the code snippets I sent in a previous email and the Geotools Filters and JTS operations.

 

Here's a tip:

 

ff = FilterFactoryFinder.createFilterFactory()

idFilter1 = ff.createFidFilter( id1 );

 

idFilter2 = ff.createFidFilter( id2 );

 

or = ff.createLogicFilter( FilterType.LOGIC_OR )

 

or.addFilter( idFilter1 );

or.addFilter( idFilter2 );

 

Something like that.

 

Jesse

 

On Aug 14, 2007, at 8:21 AM, Andy Cox wrote:

 

Hello,

I have a polygon layer which has about 10 polygons. I want to get access to two specific polygons based on attribute query (e.g. their IDs). Then I want to perform a Boolean spatial intersection to find out they intersect. Does anyone have any pointers to where I can find some info on this?

Any help greatly appreciated.

Thanks
Andy

_______________________________________________

User-friendly Desktop Internet GIS (uDig)

 


Back to the top