[Geoserver-users] Combining comparison and spatial predicates in CQL

Hi all.
I’ve searched google a lot for a question that sounds common to me but i didn’t found even a page.

How to combine comparison (attribute-based) predicates and spatial (topological) predicates in a filter in CQL (though, i think there would be no difference between CQL and filter encoding and solution for one can be converted to other)?
I’m aware of logical operators but that doesn’t satisfy my need. For example, finding a feature which its name = ‘someName’ and then finding adjacent features to this feature. Is it possible to combine these two filter expression, at all? or it needs more javascript programming than writing a simple filter string?

Regards

Hi Saka,

It sounds like you want to select a list of features and then find additional features within a small distance of the first features? CQL by itself (with no functions) is not powerful enough to express that in one go. I think of CQL as the ‘where’ clause for a single SQL statement with no joins.

Given all that, there are two, maybe three options: 1. Handle the two phases of querying yourself in client code (as you suggested) or 2. Use the GeoServer Cross-Layer filtering plugin(1). 3. If all your queries look mostly the same, you might be able to get away with a SQL View assuming you are using a traditional database like PostGIS.

The benefit (and downside) of #1 is that you’ll have complete control over the process. If I were doing this, I’d probably start with #2. The biggest gotchas there are with memory management.

Hope that help!

Jim

  1. http://docs.geoserver.org/stable/en/user/extensions/querylayer/index.html
  2. http://docs.geoserver.org/stable/en/user/data/database/sqlview.html
···

On 8/7/2016 3:45 AM, Saka Royban wrote:

Hi all.
I’ve searched google a lot for a question that sounds common to me but i didn’t found even a page.

How to combine comparison (attribute-based) predicates and spatial (topological) predicates in a filter in CQL (though, i think there would be no difference between CQL and filter encoding and solution for one can be converted to other)?
I’m aware of logical operators but that doesn’t satisfy my need. For example, finding a feature which its name = ‘someName’ and then finding adjacent features to this feature. Is it possible to combine these two filter expression, at all? or it needs more javascript programming than writing a simple filter string?

Regards

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

_______________________________________________
Geoserver-users mailing list
[Geoserver-users@lists.sourceforge.net](mailto:Geoserver-users@lists.sourceforge.net)
[https://lists.sourceforge.net/lists/listinfo/geoserver-users](https://lists.sourceforge.net/lists/listinfo/geoserver-users)

On Sun, Aug 7, 2016 at 4:28 PM, Jim Hughes <jnh5y@anonymised.com> wrote:

Given all that, there are two, maybe three options: 1. Handle the two
phases of querying yourself in client code (as you suggested) or 2. Use
the GeoServer Cross-Layer filtering plugin(1). 3. If all your queries
look mostly the same, you might be able to get away with a SQL View
assuming you are using a traditional database like PostGIS.

Option number 4, use WFS 2.0 joins. Mind, they are not fully implemented,
but should be able to answer the query you specify.
First downside, they always return full tuples, that is, if you join ft1
and ft2, you'll get back tuples made of a full ft1 feature
and a full ft2 feature.
Second downside, you basically have to figure out how to write a join by
reading the specs,
although we have some examples here (yes, you cannot use CQL, they have to
be POST xml requests):
https://github.com/geoserver/geoserver/blob/master/src/wfs/src/test/java/org/geoserver/wfs/v2_0/GetFeatureJoinTest.java

Cheers
Andrea

--

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

Ing. Andrea Aime
@geowolf
Technical Lead

GeoSolutions S.A.S.
Via di Montramito 3/A
55054 Massarosa (LU)
phone: +39 0584 962313
fax: +39 0584 1660272
mob: +39 339 8844549

http://www.geo-solutions.it
http://twitter.com/geosolutions_it

*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.

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

Hi Andrea,

Thanks for noting the WFS 2.0 joins (I obviously didn’t know about them:)).

Is the join delegated to the GeoTools DataStore level or does GeoServer execute queries across the layers?

Cheers,

Jim

···

On 8/7/2016 10:52 AM, Andrea Aime wrote:

On Sun, Aug 7, 2016 at 4:28 PM, Jim Hughes <jnh5y@anonymised.com> wrote:

Given all that, there are two, maybe three options: 1. Handle the two phases of querying yourself in client code (as you suggested) or 2. Use the GeoServer Cross-Layer filtering plugin(1). 3. If all your queries look mostly the same, you might be able to get away with a SQL View assuming you are using a traditional database like PostGIS.

Option number 4, use WFS 2.0 joins. Mind, they are not fully implemented, but should be able to answer the query you specify.
First downside, they always return full tuples, that is, if you join ft1 and ft2, you’ll get back tuples made of a full ft1 feature
and a full ft2 feature.
Second downside, you basically have to figure out how to write a join by reading the specs,
although we have some examples here (yes, you cannot use CQL, they have to be POST xml requests):
https://github.com/geoserver/geoserver/blob/master/src/wfs/src/test/java/org/geoserver/wfs/v2_0/GetFeatureJoinTest.java

Cheers
Andrea

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

Ing. Andrea Aime

@geowolf
Technical Lead

GeoSolutions S.A.S.
Via di Montramito 3/A
55054 Massarosa (LU)
phone: +39 0584 962313

fax: +39 0584 1660272
mob: +39 339 8844549

http://www.geo-solutions.it
http://twitter.com/geosolutions_it

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.


Thanks Jim and Andrea

  1. first solution sounds a bit overwhelming. Running the first phase and getting result feature from server, then converting that geometry to WKT in client-side and putting it to another filter and sending to server to get the final result. Am i in the right way?
  2. Thanks for pointing this plugin. I was aware of this plugin but it didn’t came into my mind that in this plugin i can set layer B = layer A (All my data is in one layer). I’m gonna give it a try.
  3. Thanks again for this solution. Although, i’m currently using shapefiles, but knowing this feature of GeoServer will be useful for the future.
  4. Around 4th solution, i’m not sure i can handle it. I’m not that professional and waiting for future mature releases of this feature maybe the right choice for me.

Regards


From: Jim Hughes <jnh5y@…4616…>
To: geoserver-users@lists.sourceforge.net
Sent: Sunday, August 7, 2016 6:58 PM
Subject: Re: [Geoserver-users] Combining comparison and spatial predicates in CQL

Hi Saka,

It sounds like you want to select a list of features and then find additional features within a small distance of the first features? CQL by itself (with no functions) is not powerful enough to express that in one go. I think of CQL as the ‘where’ clause for a single SQL statement with no joins.

Given all that, there are two, maybe three options: 1. Handle the two phases of querying yourself in client code (as you suggested) or 2. Use the GeoServer Cross-Layer filtering plugin(1). 3. If all your queries look mostly the same, you might be able to get away with a SQL View assuming you are using a traditional database like PostGIS.

The benefit (and downside) of #1 is that you’ll have complete control over the process. If I were doing this, I’d probably start with #2. The biggest gotchas there are with memory management.

Hope that help!

Jim

  1. http://docs.geoserver.org/stable/en/user/extensions/querylayer/index.html
  2. http://docs.geoserver.org/stable/en/user/data/database/sqlview.html

On 8/7/2016 3:45 AM, Saka Royban wrote:

Hi all.
I’ve searched google a lot for a question that sounds common to me but i didn’t found even a page.

How to combine comparison (attribute-based) predicates and spatial (topological) predicates in a filter in CQL (though, i think there would be no difference between CQL and filter encoding and solution for one can be converted to other)?
I’m aware of logical operators but that doesn’t satisfy my need. For example, finding a feature which its name = ‘someName’ and then finding adjacent features to this feature. Is it possible to combine these two filter expression, at all? or it needs more javascript programming than writing a simple filter string?

Regards

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

_______________________________________________
Geoserver-users mailing list
[Geoserver-users@lists.sourceforge.net](mailto:Geoserver-users@lists.sourceforge.net)
[https://lists.sourceforge.net/lists/listinfo/geoserver-users](https://lists.sourceforge.net/lists/listinfo/geoserver-users)



Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

Hi Saka,

No worries, and it’s a great question. I’m happy that Andrea pointed out the WFS 2.0 joins!

The first solution does require some coding. Which JavaScript libraries are you using? I’m unsure what geometry functions are available in OpenLayers and Leaflet; worst case, you could check out Turf.js or JSTS.

All that assumes that the ‘cross-layer’ filtering doesn’t work for you!

Cheers,

Jim

  1. http://turfjs.org/
  2. https://github.com/bjornharrtell/jsts
···

On 8/7/2016 5:06 PM, Saka Royban wrote:

Thanks Jim and Andrea

  1. first solution sounds a bit overwhelming. Running the first phase and getting result feature from server, then converting that geometry to WKT in client-side and putting it to another filter and sending to server to get the final result. Am i in the right way?
  2. Thanks for pointing this plugin. I was aware of this plugin but it didn’t came into my mind that in this plugin i can set layer B = layer A (All my data is in one layer). I’m gonna give it a try.
  3. Thanks again for this solution. Although, i’m currently using shapefiles, but knowing this feature of GeoServer will be useful for the future.
  4. Around 4th solution, i’m not sure i can handle it. I’m not that professional and waiting for future mature releases of this feature maybe the right choice for me.

Regards


From: Jim Hughes jnh5y@anonymised.com
To: geoserver-users@lists.sourceforge.net
Sent: Sunday, August 7, 2016 6:58 PM
Subject: Re: [Geoserver-users] Combining comparison and spatial predicates in CQL

Hi Saka,

It sounds like you want to select a list of features and then find additional features within a small distance of the first features? CQL by itself (with no functions) is not powerful enough to express that in one go. I think of CQL as the ‘where’ clause for a single SQL statement with no joins.

Given all that, there are two, maybe three options: 1. Handle the two phases of querying yourself in client code (as you suggested) or 2. Use the GeoServer Cross-Layer filtering plugin(1). 3. If all your queries look mostly the same, you might be able to get away with a SQL View assuming you are using a traditional database like PostGIS.

The benefit (and downside) of #1 is that you’ll have complete control over the process. If I were doing this, I’d probably start with #2. The biggest gotchas there are with memory management.

Hope that help!

Jim

  1. http://docs.geoserver.org/stable/en/user/extensions/querylayer/index.html
  2. http://docs.geoserver.org/stable/en/user/data/database/sqlview.html

On 8/7/2016 3:45 AM, Saka Royban wrote:

Hi all.
I’ve searched google a lot for a question that sounds common to me but i didn’t found even a page.

How to combine comparison (attribute-based) predicates and spatial (topological) predicates in a filter in CQL (though, i think there would be no difference between CQL and filter encoding and solution for one can be converted to other)?
I’m aware of logical operators but that doesn’t satisfy my need. For example, finding a feature which its name = ‘someName’ and then finding adjacent features to this feature. Is it possible to combine these two filter expression, at all? or it needs more javascript programming than writing a simple filter string?

Regards

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

_______________________________________________
Geoserver-users mailing list
[Geoserver-users@lists.sourceforge.net](mailto:Geoserver-users@lists.sourceforge.net)
[https://lists.sourceforge.net/lists/listinfo/geoserver-users](https://lists.sourceforge.net/lists/listinfo/geoserver-users)



Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

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

_______________________________________________
Geoserver-users mailing list
[Geoserver-users@lists.sourceforge.net](mailto:Geoserver-users@lists.sourceforge.net)
[https://lists.sourceforge.net/lists/listinfo/geoserver-users](https://lists.sourceforge.net/lists/listinfo/geoserver-users)

On Sun, Aug 7, 2016 at 5:13 PM, Jim Hughes <jnh5y@anonymised.com> wrote:

Hi Andrea,

Thanks for noting the WFS 2.0 joins (I obviously didn't know about
them:)).

Is the join delegated to the GeoTools DataStore level or does GeoServer
execute queries across the layers?

Hi Jim,
fair question, indeed the join support has some limitations compared to the
filter subsystem:

   - It can be only delegated to the store, there is no in memory execution
   support
   - As a consequence, the tables in the join must all reside in the same
   source, and the filters in the join must be fully encodable
   - Only "star" joins are supported (single central feature type linking
   to N others), this is a limitation of the API, Query has a list of Join
   objects, but a Join cannot have child joins, meaning a "list join" (a join
   b join c join d) cannot be expressed
   - Presently, there is no way to say that you want to join N feature
   types, but only return one (so it's not possible to use joins as a pure
   filtering mechanism, but only as a tuple building one, the client has to
   throw away the excess weight after the fact)

The store needs to declare support for joins in its query capabilities, so
far only the JDBC ones support that.
For more details see:
https://github.com/geotools/geotools/blob/master/modules/library/api/src/main/java/org/geotools/data/Query.java#L79
https://github.com/geotools/geotools/blob/master/modules/library/api/src/main/java/org/geotools/data/Join.java
https://github.com/geotools/geotools/blob/master/modules/library/api/src/main/java/org/geotools/data/QueryCapabilities.java#L112

Of course, resources/funding to improve the join subsystem would be quite
welcomed!

Cheers
Andrea

--

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

Ing. Andrea Aime
@geowolf
Technical Lead

GeoSolutions S.A.S.
Via di Montramito 3/A
55054 Massarosa (LU)
phone: +39 0584 962313
fax: +39 0584 1660272
mob: +39 339 8844549

http://www.geo-solutions.it
http://twitter.com/geosolutions_it

*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.

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