Hi Jim,
I think I have a basic way forward thanks to you and to GeoTools
"SimpleFeaturePropertyAccessorTest" which provides an example of how to
construct SimpleFeatures using the SimpleFeatureBuilder and
SimpleFeatureTypeBuilder.
Here's my basic Junit test case:
@Test
public void betweenPredicate() throws CQLException{
Filter filter = ECQL.toFilter("QUANTITY BETWEEN 10 AND 20");
Assert.assertTrue(filter instanceof PropertyIsBetween);
int testQuantityValue = 15;
SimpleFeature testFeature =
createTestFeatureWith_quantity(testQuantityValue);
//Verify filter matches feature with quantity=15
boolean match = filter.evaluate(testFeature);
Assert.assertTrue(match);
int testQuantityValue_no_match = 5;
SimpleFeature testFeature_no_match =
createTestFeatureWith_quantity(testQuantityValue_no_match);
//Verify filter does not match feature with quantity=5
boolean match2 = filter.evaluate(testFeature_no_match);
Assert.assertFalse(match2);
}
where "createTestFeatureWith_quantity()" is defined as:
private SimpleFeature createTestFeatureWith_quantity(int quantityValue) {
SimpleFeatureTypeBuilder typeBuilder = new
SimpleFeatureTypeBuilder();
typeBuilder.setName( "test" );
typeBuilder.setNamespaceURI( "http://mytest" );
typeBuilder.add( "QUANTITY", Integer.class );
SimpleFeatureType type = (SimpleFeatureType)
typeBuilder.buildFeatureType();
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
builder.add( new Integer( quantityValue ) );
SimpleFeature feature = (SimpleFeature) builder.buildFeature(
"fid" );
return feature;
}
One thing I will need to do to create SimpleFeatures is to be able to take my
list of attributes and values and determine what type they are (i.e. String,
Integer, Double, ...) and then construct the SimpleFeatures based on that
determination. But I think that isn't a big deal.
Any further thoughts you may have on this are much appreciated,
Thanks,
--Steve
From: Stephen Brooke
Sent: Sunday, March 15, 2015 11:18 AM
To: 'Jim Hughes'; geotools-gt2-users@lists.sourceforge.net
Subject: RE: [Geotools-gt2-users] CQL Parsing and Filtering with GeoTools
Thanks for your speedy response Jim.
I have been looking at the SimpleFeature implementations and trying to
determine how to construct one from one of my classes. What is the best way to
construct a SimpleFeature instance, would you recommend that I structure my
data such that I can retrieve a SimpleFeature directly from my PostGIS
database? I was hoping to at first just construct a SimpleFeature instance
from one of my own classes.
--Steve
From: Jim Hughes [mailto:jn...@ccri.com]
Sent: Sunday, March 15, 2015 10:20 AM
To:
geotools-gt2-users@lists.sourceforge.net<mailto:geotools-gt2-users@lists.sourceforge.net>
Subject: Re: [Geotools-gt2-users] CQL Parsing and Filtering with GeoTools
Hi Steve,
As a quick reply, I'd suggest looking at ECQL rather than CQL. For GeoServer,
the community has extended CQL in a few ways.
Assuming that your users will write queries in (E)CQL, ECQL.toFilter will parse
the string and handle building a filter object. It is a 'big if', but if you
are using SimpleFeatures, I know you'll be off to the races immediately. With
the filter, you can call filter.evaluate(simpleFeature); the return is a
boolean indicating if your object satisfies the filter or not.
Anyhow, the good news is that 'evaluate' actually takes an Object, so there's
some chance you won't be restricted to storing your data as SimpleFeatures.
Unfortunately, I haven't traced through the various classes to see how things
work in detail. Others will be able to speak to that better.
Does that help?
Jim
On 03/15/2015 12:54 PM, Stephen Brooke wrote:
Hi list,
I am thinking of using CQL as a filter language in my own application and I've
been looking at "gt-cql.jar" in the GeoTools suite of tools as a library to do
the heavy lifting. However, I'm having trouble knowing where to start.
The scenario I am trying to implement is as follows:
A user creates a rule for how they want to receive notifications about new data
available and the rule can contain a filter which I send to my application as a
CQL filter. The application stores the rule and when "new data available"
event occurs the application needs to go through all user rules and determine
whether notifications need to be sent to which users. So the application needs
to go through each rule and see which ones are a match for the "new data
available" event.
Does anyone have any pointers as to where to start if I want to use GeoTools to
help with this?
The classes I've studied so far are:
org.geoserver.wfs.GetFeature
org.geoserver.wfs.JoinExtractingVisitor
org.geoserver.monitor.FilterVisitorSupport
org.geotools.filter.FilterFactoryImpl
org.opengis.filter.Filter
org.geoserver.ows.KvpParser
org.geotools.filter.text.cql2.CQLTest
org.geotools.filter.text.cql2.CQL
--Steve
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net<mailto:GeoTools-GT2-Users@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users