|
From: Erwan B. <erw...@un...> - 2020-10-07 06:12:53
|
Dear Jody,
Sorry for the late reply.
Thanks for the suggestions.
I will check the best way to add the CASEWHEN function in ECQL and
delegate it to the SQL engine.
Erwan
Le 22/09/2020 à 00:34, Jody Garnett a écrit :
> Erwan:
>
> If you were interested in writing a caseWhen function you could do so,
> and then map it to the CASE WHEN syntax during SQL generation. We do
> need the pure java function as a fallback so that the resulting
> expressions work with all manner of datastores. We have functions such
> as categorization which may be a good starting point.
>
> Although it may not help your readability the function implementations
> delegate to the filter implementation.
>
> FilterFunction_greaterEqualThan implements greaterEqualThan function
> using:
>
> return Boolean.valueOf(StaticGeometry.greaterEqualThan(arg0, arg1));
>
> StaticGeometry:
>
> public static boolean greaterThan(Object o1, Object o2) {
> return getFilterFactory2().greater(ff.literal(o1),
> ff.literal(o2)).evaluate(null);
> }
>
>
> We do maintain an ECQL parser that extends the CQL standard. If you
> wished to do the work in geotools you could look at allowing ECQL to
> know about this relationship and parse ">" into a greaterEqualThan
> function.
> --
> Jody Garnett
>
>
> On Mon, 21 Sep 2020 at 03:54, Erwan Bocher <erw...@un...
> <mailto:erw...@un...>> wrote:
>
> Thanks Andrea,
>
>
>
> Le 21/09/2020 à 12:18, Andrea Aime a écrit :
>> On Mon, Sep 21, 2020 at 11:08 AM Erwan Bocher
>> <erw...@un... <mailto:erw...@un...>> 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)
>
> Thanks Andrea,
>
> if_then_else(greater(area(THE_GEOM), 10),5, 1) is a good way but
> I'd like to write in plain text form as SQL does.
>
>>
>> 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).
>
> I understand the standard compliant pb ;-) There is a need for an
> abstract and extensible language for expressions.
>
> We will have to think about something else and maybe implement our
> own parser expression.
>
> A temporary solution would be to parse the expression with a lib
> like JSQLParser (https://github.com/JSQLParser/JSqlParser) and
> build a "CQL compliant" expression.
>
> Best regards
>
> Erwan
>
>>
>> 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./
>>
> --
> Ingénieur de Recherche CNRS - HDR,
> Laboratoire Lab-STICC – UMR 6285
> Equipe DECIDE
> Institut Universitaire de Technologie de Vannes
> 8, Rue Montaigne - BP 561 56017 Vannes Cedex
> T: +33 2 97 62 64 92
> W:https://cv.archives-ouvertes.fr/erwan-bocher
> W:http://www.labsticc.fr
>
> _______________________________________________
> GeoTools-GT2-Users mailing list
> Geo...@li...
> <mailto:Geo...@li...>
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
--
Ingénieur de Recherche CNRS - HDR,
Laboratoire Lab-STICC – UMR 6285
Equipe DECIDE
Institut Universitaire de Technologie de Vannes
8, Rue Montaigne - BP 561 56017 Vannes Cedex
T: +33 2 97 62 64 92
W: https://cv.archives-ouvertes.fr/erwan-bocher
W: http://www.labsticc.fr
|