I expect you can do what you need using an expression: Recode( modulo( strSubstringStart( attribute, ,3), 2), 0, '#FF0000'. 1, '#00GG00' )
If you are using YSLD for styling you can define this as a variable for reuse (for example polygon outline and fill): # define here define: &mycolor Recode( modulo( strSubstringStart( attribute, ,3), 2), 0, '#FF0000'. 1, '#00GG00') # reuse as needed - polygon: stroke-color: *mycolor fill-color: *mycolor fill-opacity: 0.25 If you do need to write your own Java function there are lots of ways to reuse function code: - Many of the functions have a static method (making the implementation easier to test). When writing your own function you can make use of these static methods to reuse functionality. The static method approach is used for the original autogenerated functions: FilterFunction_greatThan.java <https://github.com/geotools/geotools/blob/main/modules/library/main/src/main/java/org/geotools/filter/function/FilterFunction_greaterThan.java> - You can also create functions, or filters, and make use of them directly in your implementation. The implementation of FilterFunction_equalTo <https://github.com/geotools/geotools/blob/main/modules/library/main/src/main/java/org/geotools/filter/function/FilterFunction_equalTo.java> was replaced to reference the create a filter (thus using the exact same implementation). - You can also extend an existing implementation to reuse code and register your new function with factory spi. Another fun idea would be to make something like a function defined by a CQL expression. This would only help readability, there would not be a performance benefit. -- Jody Garnett On Sat, 26 Jun 2021 at 04:04, Peter Friess <pk.fri...@t-online.de> wrote: > Hi There, > > I was wondering if there exists a way of combining several functions > into one. I mean, that I can use the result of one function as input > parameter into the next function etc., kind of chaining functions. > Concrete: I have a feature which has among others a String attribute > which looks like "PC_L1", PC_L2" etc. i.e a numbered identifier. I want > to color code the features, by using a modulo function on the number > (even with a certain color, odd with a certain color). I therefore need > to extract the number with "strSubstringStart" convert it to an integer > with "parseInt" and then use "modulo". Is it possible to do this > somehow? If yes, how? > > Thanks in advance > > Peter Friess > > PS: if this is not possible, I need to introduce another attribute for > just the number. > > > > _______________________________________________ > GeoTools-GT2-Users mailing list > GeoTools-GT2-Users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >
_______________________________________________ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users