Hi,

As member of the SLD/SE standard working I'm working on a POC to test the next  Feature2DStyle model.

Here you have a first implementation : https://github.com/orbisgis/orbismap

I'm looking for testing Feature2DStyle model with Geotools.

Feature2DStyle supports expression (ParameterValue) for each symbol elements.

Example to manage the width of a line with a SQL CASE WHEN.

Feature2DStyle style = new Feature2DStyle();
LineSymbolizer lineSymbolizer = new LineSymbolizer();
lineSymbolizer.setGeometryParameter("the_geom");
PenStroke ps = new PenStroke();
ps.setWidth(new Expression("CASE WHEN ST_AREA(THE_GEOM)>10000 then 5 else 1 END"));
SolidFill solidFill = new SolidFill();
ps.setFill(solidFill);
lineSymbolizer.setStroke(ps);
Feature2DRule rule = new Feature2DRule();
rule.addSymbolizer(lineSymbolizer);
style.addRule(rule);

Geotools has an abstract query language and mechanism to run expression or filter that are translated in the language supported by the datastore (very useful for POSTGIS and H2GIS).

I have successfully used it on an H2GIS table.

List<Definition> definitions = new ArrayList<Definition>();
definitions.add(new Definition("THE_GEOM", ECQL.toExpression("centroid(buffer(THE_GEOM, 1))"))); definitions.add(new Definition("AREA", ECQL.toExpression("AREA(THE_GEOM)/1000"))); SimpleFeatureSource transformed = TransformFactory.transform((SimpleFeatureSource) fs, "OUTPUT_TABLE_TEST_F", definitions);

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 ?

e.g.

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

if_then_else(area(buffer(THE_GEOM))>10,5, 1)

Or a way to implement it ?


Best regards


Erwan Bocher

--
Ingénieur de Recherche CNRS - HDR,
Laboratoire Lab-STICC – UMR 6285
Equipe DECIDE
https://github.com/orbisgis
https://noise-planet.org/
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
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to