Hi list,

I'm trying to write a new coverage processing operation. I've followed 
the instructions in 
http://www.nabble.com/forum/ViewPost.jtp?post=3585286&framed=y and the 
service provider class seems to be being picked up fine by the Registry. 
My OpImage class is also registered fine with JAI (and I can run it 
using getRenderedImage() from my GridCoverage2D and then creating a neew 
GridCoverage2D with the result), but when I try instantiating the 
Operation I get the stack trace below.

I've attached the code for the geotools JAIOperation and the JAI 
OperationDescriptor below, as I've a feeling from the traceback that I 
could be missing something in the OperationDescriptor (but can't work 
out what).

Any ideas much appreciated! If I can get this to work then I've got a 
few coverage operations that I want to turn into "proper" JAI/GeoTools 
operations and would then be able to donate to GeoTools...

Thanks in advance,

Ed

The stack trace:

> WARNUNG: Can't load a service for category "Operation". Cause is 
> "ServiceConfigurationError: org (...) java.lang.NullPointerException".
> sun.misc.ServiceConfigurationError: 
> org.opengis.coverage.processing.Operation: Provider 
> org.preagro.utils.coverages.operations.OutlierFilterOperation could no
> t be instantiated: java.lang.NullPointerException
>         at sun.misc.Service.fail(Service.java:120)
>         at sun.misc.Service.access$200(Service.java:111)
>         at sun.misc.Service$LazyIterator.next(Service.java:276)
>         at 
> org.geotools.factory.FactoryRegistry.scanForPlugins(FactoryRegistry.java:564)
>         at 
> org.geotools.factory.FactoryRegistry.safeScanForPlugins(FactoryRegistry.java:540)
>         at 
> org.geotools.factory.FactoryRegistry.getServiceProviders(FactoryRegistry.java:175)
>         at 
> org.geotools.factory.FactoryRegistry.getServiceProviders(FactoryRegistry.java:117)
>         at 
> org.geotools.coverage.processing.DefaultProcessor.scanForPlugins(DefaultProcessor.java:331)
>         at 
> org.geotools.coverage.processing.DefaultProcessor.getOperation(DefaultProcessor.java:231)
>         at 
> org.geotools.coverage.processing.BufferedProcessor.getOperation(BufferedProcessor.java:107)
>         at 
> org.preagro.wps.processes.generic.coverageoperations.DivideByMean.execute(DivideByMean.java:115)
>         at 
> org.deegree.ogcwebservices.wps.execute.ExecuteRequestHandler.startProcess(ExecuteRequestHandler.java:322)
>         at 
> org.deegree.ogcwebservices.wps.execute.ExecuteRequestHandler.handleStoreParameter(ExecuteRequestHandler.java:255)
>         at 
> org.deegree.ogcwebservices.wps.execute.ExecuteRequestHandler.handleRequest(ExecuteRequestHandler.java:182)
>         at 
> org.deegree.ogcwebservices.wps.WPService.doService(WPService.java:123)
>         at 
> org.deegree.enterprise.servlet.WPSHandler.perform(WPSHandler.java:101)
>         at 
> org.deegree.enterprise.servlet.OGCServletController.doService(OGCServletController.java:144)
>         at 
> org.deegree.enterprise.servlet.OGCServletController.doGet(OGCServletController.java:228)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>         at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
>         at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
>         at 
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
>         at 
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
>         at 
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
>         at 
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
>         at 
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
>         at 
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
>         at 
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
>         at 
> org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
>         at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
>         at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:754)
>         at 
> org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:684)
>         at 
> org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:876)
>         at 
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
>         at java.lang.Thread.run(Thread.java:595)
> Caused by: java.lang.NullPointerException
>         at 
> org.geotools.referencing.NamedIdentifier.getName(NamedIdentifier.java:437)
>         at 
> org.geotools.referencing.NamedIdentifier.getName(NamedIdentifier.java:424)
>         at 
> org.geotools.referencing.NamedIdentifier.toString(NamedIdentifier.java:565)
>         at 
> org.geotools.referencing.AbstractIdentifiedObject.<init>(AbstractIdentifiedObject.java:463)
>         at 
> org.geotools.referencing.AbstractIdentifiedObject.<init>(AbstractIdentifiedObject.java:247)
>         at 
> org.geotools.parameter.AbstractParameterDescriptor.<init>(AbstractParameterDescriptor.java:88)
>         at 
> org.geotools.parameter.DefaultParameterDescriptorGroup.<init>(DefaultParameterDescriptorGroup.java:161)
>         at 
> org.geotools.parameter.ImagingParameterDescriptors.<init>(ImagingParameterDescriptors.java:193)
>         at 
> org.geotools.parameter.ImagingParameterDescriptors.<init>(ImagingParameterDescriptors.java:163)
>         at 
> org.geotools.parameter.ImagingParameterDescriptors.<init>(ImagingParameterDescriptors.java:140)
>         at 
> org.geotools.coverage.processing.OperationJAI.<init>(OperationJAI.java:160)
>         at 
> org.geotools.coverage.processing.OperationJAI.<init>(OperationJAI.java:150)
>         at 
> org.preagro.utils.coverages.operations.OutlierFilterOperation.<init>(OutlierFilterOperation.java:44)
>         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native 
> Method)
>         at 
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>         at 
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>         at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
>         at java.lang.Class.newInstance0(Class.java:350)
>         at java.lang.Class.newInstance(Class.java:303)
>         at sun.misc.Service$LazyIterator.next(Service.java:271)
>         ... 33 more

Code for the OperationJAI extension is:

public class OutlierFilterOperation extends OperationJAI {
     public OutlierFilterOperation() {
        super("org.preagro.OutlierFilter");
     }
     @Override
     protected NumberRange deriveRange(
                                        final NumberRange[] ranges,
                                        final Parameters parameters
                                )
     {
        final NumberRange originalRange = ranges[0];
        ParameterBlock params = parameters.parameters;
        final double min = Math.max(
                                        originalRange.getMinimum(),
                                        params.getDoubleParameter(0)
                                );
        final double max = Math.min(
                                        originalRange.getMaximum(),
                                        params.getDoubleParameter(1)
                                );
        return new NumberRange(min, max);
     }
     @Override
     protected Unit deriveUnit(Unit[] units, Parameters parameters) {
        return units[0];
     }
}

And the JAI OperationDescriptor (since looking at the traceback I have a 
feeling that there might be something missing here):

public class OutlierFilterDescriptor extends OperationDescriptorImpl {

     private static boolean registered = false;

     public static final String VENDOR_NAME = "org.preagro";

     public static final String OPERATION_NAME = VENDOR_NAME + 
".OutlierFilter";

     public static final String ERROR = "The OriginalValues and 
TargetValues must have the same number of components";

     public OutlierFilterDescriptor() {
         super(new String[][]{{"GlobalName",  OPERATION_NAME},
                              {"LocalName",   OPERATION_NAME},
                              {"Vendor",      VENDOR_NAME},
                              {"Description", "Filter outlier values 
below minValue and above maxValue and turn them to NaNs"},
                              {"DocURL",      "http://www.preagro.de/"},
                              {"Version",     "1.0"}},
               new String[]   {RenderedRegistryMode.MODE_NAME}, 1,
               new String[]   {"minValue", "maxValue"},
               new Class[]    {Double.class, Double.class},
               new Object[]   {- Double.MAX_VALUE, Double.MAX_VALUE},
               null)
         );
     }

     public static RenderedOp create(final RenderedImage original, final 
double minValue, final double maxValue, final RenderingHints hints) {
        ParameterBlock params = new ParameterBlock();
        params.addSource(original);
        params.add(new Double(minValue));
        params.add(new Double(maxValue));
        return JAI.create(OPERATION_NAME, params, hints);
     }

     public static boolean register(final OperationRegistry registry) {
        try {
            if (!registered) {
            registry.registerDescriptor(new OutlierFilterDescriptor());
                    registry.registerFactory(RenderedRegistryMode.MODE_NAME, 
OPERATION_NAME, VENDOR_NAME, new OutlierFilterCRIF());
                    registered = true;
            }
        } catch (IllegalArgumentException e) {
            // TODO suppress the error ?
            // TODO log rather than printStackTrace ??
            System.out.println("Failed to register operation");
            e.printStackTrace();
        }
        return registered;
     }

     static {
        // force registration of the operation in case registryFile.jai
        // is/was not available to the JAI classloader
        register(JAI.getDefaultInstance().getOperationRegistry());
     }
}

-- 
preagro TP7 - Geodateninfrastruktur
http://www.preagro.de

Universität Rostock
Agrar- und Umweltwissenschaftliche Fakultät
Professur für Geodäsie und Geoinformatik
Justus-von-Liebig-Weg 6
18059 Rostock

Tel: +49 381 498 3212
Fax: +49 381 498 3202
Web: http://www.auf.uni-rostock.de/gg


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to