You need to "register" the function in META_INF/servies as described in the 
function tutorial. It will need to be loaded in the same classloader as 
geotools for the gt-main module FunctionFinder to see it.

There is a geotools FunctionFactory implementation that scans all the functions 
defined in META_INF/services and provides them to the library (including the 
renderer).

You can also take a larger gulp and register your own complete FunctionFactory 
implementation.

For more details:
- http://docs.geotools.org/latest/userguide/tutorial/advanced/factory.html
- http://docs.geotools.org/latest/userguide/tutorial/advanced/function.html

Jody

On 29/06/2012, at 10:39 PM, Trupti Pol wrote:

> Hi,
> 
> I am trying to develope a custom function "ColorMap" which can be used in
> SLD to get the different style based on feature attributes.
> 
> This function is mainly utilized to provide different draw color to each
> feature based on the "ColorIndex" attribute.
> 
> My Sample function is as follows
> 
> public class ColorMapFunction extends FunctionExpressionImpl{
> 
>       public ColorMapFunction(String name) {
>               super("ColorMap");
>       }
> 
>       @Override
>       public int getArgCount() {
>               return 1;
>       }
> 
>       public Object evaluate(Object feature) {
>                String colorIndex;
> 
> 
>                try { 
>                colorIndex = getExpression(0).evaluate(feature).toString();
>          } catch (Exception e){ // probably a type error
>                      throw new IllegalArgumentException(
>                          "Filter Function problem for function ColorMap
> argument #0 - expected type String");
>               }
> 
>               return getColor(colorIndex);
>               }
>       
>          private String getColor(String colorTablePath, String colorIndex){
>               // will provide different color based on colorIndex             
>          }
> }
> 
> But when i try to use this function in my .sld file it gives me error as
> below
> 
> Unable to find function Colourmap
>> java.lang.RuntimeException: Unable to find function Colourmap
>>    at
>> org.geotools.filter.FunctionFinder.findFunction(FunctionFinder.java:103)
>>    at
>> org.geotools.filter.FunctionFinder.findFunction(FunctionFinder.java:69)
>>    at
>> org.geotools.filter.FilterFactoryImpl.function(FilterFactoryImpl.java:469)
> 
> 
> Please let me know am i skipping something here..I am using geotools 2.6 M2
> version
> 
> --
> View this message in context: 
> http://gis.19327.n5.nabble.com/Unable-to-find-custom-function-Colourmap-tp5714582.html
> Sent from the uDig Developer mailing list archive at Nabble.com.
> _______________________________________________
> User-friendly Desktop Internet GIS (uDig)
> http://udig.refractions.net
> http://lists.refractions.net/mailman/listinfo/udig-devel

_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel

Reply via email to