Sadly the function returns null if the lookup does not have a match,
see evaluate
method
<https://github.com/geotools/geotools/blob/master/modules/library/main/src/main/java/org/geotools/filter/function/RecodeFunction.java#L175>
.
I think your solution is fine, although it does require a lot of duplicate
work on your part.
If I was doing this myself I would consider adding a new function that
returns a nonNull value, or substitutes a fallback value:
CQL: nullFallback( recode( C9, 4, '#FF9900',5, 'CC9933',10,'FFFF00'),
'#554400')
Aside: When implementing Recode we did consider providing a fallback value,
the Function interface was revised for SE Functions which provide a
fallback value as part of the function call. It is intended to assist with
interoperability, when a particular function is not available in an
execution environment.
GeoTools FunctionFinder provides ability to set fallback
<http://docs.geotools.org/latest/userguide/library/main/filter.html#functionfinder>
:
Function function = finder.findFunction( "Recode", List<Expression>,
fallback );
It was tempting to make Recode return this fallback value if there was not
a match.
--
Jody Garnett
On 5 April 2018 at 20:17, Raif S. Naffah <r...@forge.com.au> wrote:
> hi,
>
> i'm using the Recode transformation function in SLDs w/ GeoServer 2.8.5
> and GeoTools 14.5.
>
> i was wondering though what would be the most elegant way for catering
> for input values _other_ than those specified w/in the parameters of the
> function?
>
> i was able to achieve this by having 2 Rules like so:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld"
> xmlns:sld="http://www.opengis.net/sld"
> xmlns:gml="http://www.opengis.net/gml"
> xmlns:ogc="http://www.opengis.net/ogc" version="1.0.0">
> <sld:NamedLayer>
> <sld:Name>P2307937L1T2</sld:Name>
> <sld:UserStyle>
> <sld:Name>P2307937L1T2</sld:Name>
> <sld:FeatureTypeStyle>
> <sld:Name>name</sld:Name>
> <sld:Rule>
> <ogc:Filter>
> <ogc:PropertyIsEqualTo>
> <ogc:Function name="in">
> <ogc:PropertyName>C9</ogc:PropertyName>
> <ogc:Literal>4</ogc:Literal>
> <ogc:Literal>5</ogc:Literal>
> ...
> <ogc:Literal>10</ogc:Literal>
> </ogc:Function>
> <ogc:Literal>true</ogc:Literal>
> </ogc:PropertyIsEqualTo>
> </ogc:Filter>
>
> <sld:PointSymbolizer>
> <sld:Graphic>
> <sld:Mark>
> <sld:WellKnownName>triangle</sld:WellKnownName>
> <sld:Fill>
> <sld:CssParameter name="fill">
> <ogc:Function name="Recode">
> <ogc:PropertyName>C9</ogc:PropertyName>
> <ogc:Literal>4</ogc:Literal>
> <ogc:Literal>#FF9900</ogc:Literal>
> <ogc:Literal>5</ogc:Literal>
> <ogc:Literal>#CC9933</ogc:Literal>
> ...
> <ogc:Literal>10</ogc:Literal>
> <ogc:Literal>#FFFF00</ogc:Literal>
> </ogc:Function>
> </sld:CssParameter>
> </sld:Fill>
> <sld:Stroke>...</sld:Stroke>
> </sld:Mark>
> <sld:Size>10.0</sld:Size>
> </sld:Graphic>
> </sld:PointSymbolizer>
> </sld:Rule>
> <sld:Rule>
> <ogc:ElseFilter/>
> <sld:PointSymbolizer>...</sld:PointSymbolizer>
> </sld:Rule>
> </sld:FeatureTypeStyle>
> </sld:UserStyle>
> </sld:NamedLayer>
> </sld:StyledLayerDescriptor>
>
> is there a better way to do this?
>
>
> TIA + cheers;
> rsn
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> GeoTools-GT2-Users mailing list
> GeoTools-GT2-Users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users