CQL Parsing and Filtering with GeoTools

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

CQL Parsing and Filtering with GeoTools

sbrooke

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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|

Re: CQL Parsing and Filtering with GeoTools

Jim Hughes
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
[hidden email]
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|

Re: CQL Parsing and Filtering with GeoTools

sbrooke

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:[hidden email]]
Sent: Sunday, March 15, 2015 10:20 AM
To: [hidden email]
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
[hidden email]
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|

Re: CQL Parsing and Filtering with GeoTools

Jim Hughes
Hi Steve,

No problem.  If you are using Postgres/PostGIS, then using a PostGISDataStore and organizing your data in SimpleFeatures will net you some benefits! 

Check out http://docs.geotools.org/stable/userguide/library/jdbc/postgis.html

I'll try and respond later with more info about creating SimpleFeatures.

Jim

On 03/15/2015 02:17 PM, Stephen Brooke wrote:

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 [[hidden email]]
Sent: Sunday, March 15, 2015 10:20 AM
To: [hidden email]
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
[hidden email]
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|

Re: CQL Parsing and Filtering with GeoTools

sbrooke
In reply to this post by Jim Hughes

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'; [hidden email]
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 [[hidden email]]
Sent: Sunday, March 15, 2015 10:20 AM
To: [hidden email]
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
[hidden email]
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|

Re: CQL Parsing and Filtering with GeoTools

geowolf
On Sun, Mar 15, 2015 at 8:06 PM, Stephen Brooke <[hidden email]> wrote:

Any further thoughts you may have on this are much appreciated,


Here is another option to consider. 
CQL parses to Filter, which in turn evaluates an Object, not a Feature.
So how do we evaluate properies against a random object? Using property accessors,
which can be registered in SPI:


So you could write your own property accessor that knows how to extract the properties out of
your objects, instead of converting them to simple features.

I don't think we have docs on how to write an accessor (this is kind of advanced stuff, Jody please
correct me if I'm wrong) but have a look at PropertyAccessor sublasses with your IDE, and see how they are getting
registered in SPI checking the META-INF/services directory in the same geotools module

Cheers
Andrea

--
==
GeoServer Professional Services from the experts! Visit
http://goo.gl/NWWaa2 for more information.
==

Ing. Andrea Aime 
@geowolf
Technical Lead

GeoSolutions S.A.S.
Via Poggio alle Viti 1187
55054  Massarosa (LU)
Italy
phone: +39 0584 962313
fax: +39 0584 1660272
mob: +39  339 8844549


AVVERTENZE AI SENSI DEL D.Lgs. 196/2003

Le informazioni contenute in questo messaggio di posta elettronica e/o nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il loro utilizzo è consentito esclusivamente al destinatario del messaggio, per le finalità indicate nel messaggio stesso. Qualora riceviate questo messaggio senza esserne il destinatario, Vi preghiamo cortesemente di darcene notizia via e-mail e di procedere alla distruzione del messaggio stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od utilizzarlo per finalità diverse, costituisce comportamento contrario ai principi dettati dal D.Lgs. 196/2003.

 

The information in this message and/or attachments, is intended solely for the attention and use of the named addressee(s) and may be confidential or proprietary in nature or covered by the provisions of privacy act (Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection Code).Any use not in accord with its purpose, any disclosure, reproduction, copying, distribution, or either dissemination, either whole or partial, is strictly forbidden except previous formal approval of the named addressee(s). If you are not the intended recipient, please contact immediately the sender by telephone, fax or e-mail and delete the information in this message that has been received in error. The sender does not give any warranty or accept liability as the content, accuracy or completeness of sent messages and accepts no responsibility  for changes made after they were sent or for other risks which arise as a result of e-mail transmission, viruses, etc.


-------------------------------------------------------

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|

Re: CQL Parsing and Filtering with GeoTools

sbrooke

Thanks Andrea, this is the kind of additional advice I am looking for.  So far, to me converting my object to a SimpleFeature actually doesn’t look as daunting as creating my own PropertyAccessor, although I don’t think I would have too much trouble with the latter either.  However, at the moment, creating my own PropertyAccessor doesn’t look to be the shortest path to getting something working which is what converting to a SimpleFeature has done for me.  I am just trying to verify an overall design approach and this is just one of the many details I need to work out.

 

If I hit a snag with using SimpleFeature then I will definitely be looking at other options,

Thanks,

 

--Steve

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Andrea Aime
Sent: Sunday, March 15, 2015 12:19 PM
To: Stephen Brooke
Cc: Jim Hughes; [hidden email]
Subject: Re: [Geotools-gt2-users] CQL Parsing and Filtering with GeoTools

 

On Sun, Mar 15, 2015 at 8:06 PM, Stephen Brooke <[hidden email]> wrote:

Any further thoughts you may have on this are much appreciated,

 

Here is another option to consider. 

CQL parses to Filter, which in turn evaluates an Object, not a Feature.

So how do we evaluate properies against a random object? Using property accessors,

which can be registered in SPI:

 

 

So you could write your own property accessor that knows how to extract the properties out of

your objects, instead of converting them to simple features.

 

I don't think we have docs on how to write an accessor (this is kind of advanced stuff, Jody please

correct me if I'm wrong) but have a look at PropertyAccessor sublasses with your IDE, and see how they are getting

registered in SPI checking the META-INF/services directory in the same geotools module

 

Cheers

Andrea

 

--

==

GeoServer Professional Services from the experts! Visit

http://goo.gl/NWWaa2 for more information.

==

 

Ing. Andrea Aime 

@geowolf

Technical Lead

 

GeoSolutions S.A.S.

Via Poggio alle Viti 1187

55054  Massarosa (LU)

Italy

phone: +39 0584 962313

fax: +39 0584 1660272

mob: +39  339 8844549

 

 

AVVERTENZE AI SENSI DEL D.Lgs. 196/2003

Le informazioni contenute in questo messaggio di posta elettronica e/o nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il loro utilizzo è consentito esclusivamente al destinatario del messaggio, per le finalità indicate nel messaggio stesso. Qualora riceviate questo messaggio senza esserne il destinatario, Vi preghiamo cortesemente di darcene notizia via e-mail e di procedere alla distruzione del messaggio stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od utilizzarlo per finalità diverse, costituisce comportamento contrario ai principi dettati dal D.Lgs. 196/2003.

 

The information in this message and/or attachments, is intended solely for the attention and use of the named addressee(s) and may be confidential or proprietary in nature or covered by the provisions of privacy act (Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection Code).Any use not in accord with its purpose, any disclosure, reproduction, copying, distribution, or either dissemination, either whole or partial, is strictly forbidden except previous formal approval of the named addressee(s). If you are not the intended recipient, please contact immediately the sender by telephone, fax or e-mail and delete the information in this message that has been received in error. The sender does not give any warranty or accept liability as the content, accuracy or completeness of sent messages and accepts no responsibility  for changes made after they were sent or for other risks which arise as a result of e-mail transmission, viruses, etc.

 

-------------------------------------------------------


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|

Re: CQL Parsing and Filtering with GeoTools

Jim Hughes
In reply to this post by geowolf
Andrea,

Thanks for mentioning the PropertyAccessors!  I had seen them, but I hadn't had a chance to figure them out.

With context and reading through now, they make a great deal of sense.  It seems like with an hour or two and dependencies on gt-api and gt-cql, one could wire up CQL filtering to a custom classes.  Neat.

Do folks think this should be documented?  I'm mildly amused by this since I've mucked with CQL a bit.

Thanks,

Jim

On 03/15/2015 03:19 PM, Andrea Aime wrote:
On Sun, Mar 15, 2015 at 8:06 PM, Stephen Brooke <[hidden email]> wrote:

Any further thoughts you may have on this are much appreciated,


Here is another option to consider. 
CQL parses to Filter, which in turn evaluates an Object, not a Feature.
So how do we evaluate properies against a random object? Using property accessors,
which can be registered in SPI:


So you could write your own property accessor that knows how to extract the properties out of
your objects, instead of converting them to simple features.

I don't think we have docs on how to write an accessor (this is kind of advanced stuff, Jody please
correct me if I'm wrong) but have a look at PropertyAccessor sublasses with your IDE, and see how they are getting
registered in SPI checking the META-INF/services directory in the same geotools module

Cheers
Andrea

--
==
GeoServer Professional Services from the experts! Visit
http://goo.gl/NWWaa2 for more information.
==

Ing. Andrea Aime 
@geowolf
Technical Lead

GeoSolutions S.A.S.
Via Poggio alle Viti 1187
55054  Massarosa (LU)
Italy
phone: +39 0584 962313
fax: +39 0584 1660272
mob: +39  339 8844549


AVVERTENZE AI SENSI DEL D.Lgs. 196/2003

Le informazioni contenute in questo messaggio di posta elettronica e/o nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il loro utilizzo è consentito esclusivamente al destinatario del messaggio, per le finalità indicate nel messaggio stesso. Qualora riceviate questo messaggio senza esserne il destinatario, Vi preghiamo cortesemente di darcene notizia via e-mail e di procedere alla distruzione del messaggio stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od utilizzarlo per finalità diverse, costituisce comportamento contrario ai principi dettati dal D.Lgs. 196/2003.

 

The information in this message and/or attachments, is intended solely for the attention and use of the named addressee(s) and may be confidential or proprietary in nature or covered by the provisions of privacy act (Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection Code).Any use not in accord with its purpose, any disclosure, reproduction, copying, distribution, or either dissemination, either whole or partial, is strictly forbidden except previous formal approval of the named addressee(s). If you are not the intended recipient, please contact immediately the sender by telephone, fax or e-mail and delete the information in this message that has been received in error. The sender does not give any warranty or accept liability as the content, accuracy or completeness of sent messages and accepts no responsibility  for changes made after they were sent or for other risks which arise as a result of e-mail transmission, viruses, etc.


-------------------------------------------------------


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|

Re: CQL Parsing and Filtering with GeoTools

geowolf

>
> Do folks think this should be documented?  I'm mildly amused by this since I've mucked with CQL a bit.
>

Everything should be documented!
If this picks your interest,  go for it :-)

Cheers
Andrea


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|

Re: CQL Parsing and Filtering with GeoTools

jody.garnett
In reply to this post by sbrooke
A couple things Steve:

The CQL code is pretty generic - it just parses out a GeoTools Filter object. ECQL is our custom extension of CQL that offers a better reflection of what our Filter object can do. As an example CQL can compare a property name to an expression, while ECQL can compare two expressions.

There is no difference to the data structure if you create it with a FilterFactory or an ECQL expression.

The Filter data structure has two places you can extend it:
- Function - create your own function following the tutorial in the user guide
- PropertyAccessor - teach filter how to extract values out of your objects (GeoTools does Features, other applications do java beans, or java.util.Map, or whatever ....).

FilterVisitor is used to process your expression once it is written. A very simple process is to evaluate to a value. A more complicated one would be to simplify or refactor an expression ... or to generate SQL.

Jody

--
Jody Garnett

On 15 March 2015 at 09:54, Stephen Brooke <[hidden email]> 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
[hidden email]
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|

Re: CQL Parsing and Filtering with GeoTools

sbrooke

Thanks a lot Jody for that clear explanation.  For now I am currently just creating a SimpleFeature from my own property map and using the ECQL.toFilter(myECQLstring) and Filter.evaluate(feature) functions which are working beautifully.  But you’ve shown me the road to making what I’ve got more flexible and I will definitely look at those as the need arises.

 

--Steve

 

From: Jody Garnett [mailto:[hidden email]]
Sent: Monday, March 16, 2015 3:59 PM
To: Stephen Brooke
Cc: [hidden email]
Subject: Re: [Geotools-gt2-users] CQL Parsing and Filtering with GeoTools

 

A couple things Steve:

 

The CQL code is pretty generic - it just parses out a GeoTools Filter object. ECQL is our custom extension of CQL that offers a better reflection of what our Filter object can do. As an example CQL can compare a property name to an expression, while ECQL can compare two expressions.

 

There is no difference to the data structure if you create it with a FilterFactory or an ECQL expression.

 

The Filter data structure has two places you can extend it:

- Function - create your own function following the tutorial in the user guide

- PropertyAccessor - teach filter how to extract values out of your objects (GeoTools does Features, other applications do java beans, or java.util.Map, or whatever ....).

 

FilterVisitor is used to process your expression once it is written. A very simple process is to evaluate to a value. A more complicated one would be to simplify or refactor an expression ... or to generate SQL.

 

Jody


--

Jody Garnett

 

On 15 March 2015 at 09:54, Stephen Brooke <[hidden email]> 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
[hidden email]
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users