On Mon, Sep 21, 2020 at 11:08 AM Erwan Bocher <erwan.boc...@univ-ubs.fr>
wrote:

> I'd like to apply more complex expressions as the Case When above. It
> seems there is a function  closed to the SQL Case When called if_then_else.
>
> So I try :
>
> Expression expression =
> ECQL.toExpression("if_then_else(area(THE_GEOM)>10,5, 1)");
>
> definitions.add(new Definition("EXP", expression));
>
> SimpleFeatureSource transformed =
> TransformFactory.transform((SimpleFeatureSource) fs,
> "OUTPUT_TABLE_TEST_F", definitions);
>
> Unfortunately, it returns the following exception
>
> Exception in thread "main" org.geotools.filter.text.cql2.CQLException:
> Encountered ">" at line 1, column 28.
>
> Is there a way to execute nested expression with Geotools ECQL parser ?
>

It is, but you're mixing filters and expressions in the wrong way. Filters
use expressions, but
they are not expressions. So something like "area(THE_GEOM)>10" is a
filter, it cannot
be nested inside an expression, only inside another filter.

There are filter functions that try to work around this limitation, so you
could write this instead:

if_then_else(greater(area(THE_GEOM), 10),5, 1)

I'd love to see an improvement in GeoTools allowing to treat a Filter like
an Expression that returns
a boolean but... the change would not be trivial, and rife with
repercussions (would allow building
filters/expressions that are not valid anymore, not in CQL, nor in Filter
Encoding).

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
------------------------------------------------------- *Con riferimento
alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 -
Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni
circostanza inerente alla presente email (il suo contenuto, gli eventuali
allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i
destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per
errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le
sarei comunque grato se potesse darmene notizia. This email is intended
only for the person or entity to which it is addressed and may contain
information that is privileged, confidential or otherwise protected from
disclosure. We remind that - as provided by European Regulation 2016/679
“GDPR” - copying, dissemination or use of this e-mail or the information
herein by anyone other than the intended recipient is prohibited. If you
have received this email by mistake, please notify us immediately by
telephone or e-mail.*
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to