error in library for ConvexHullDemo process

classic Classic list List threaded Threaded
41 messages Options
123
Reply | Threaded
Open this post in threaded view
|

error in library for ConvexHullDemo process

soshi
hi everybody,
I wrote a process, but eclipse has got error in libraries such as
import org.n52.wps.io.GTHelper;
import org.n52.wps.io.data.binding.complex.GTVectorDataBinding;
and dosen't know GTVectorDataBinding and GTHelper classes,

please help me,
thanks in advance.

process:
/**
 * Copyright (C) 2007 - 2016 52°North Initiative for Geospatial Open Source
 * Software GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.n52.wps.demo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.feature.DefaultFeatureCollections;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.n52.wps.io.GTHelper;
import org.n52.wps.io.data.IData;
import org.n52.wps.io.data.binding.complex.GTVectorDataBinding;
import org.n52.wps.server.AbstractSelfDescribingAlgorithm;
import org.n52.wps.server.ExceptionReport;
import org.opengis.feature.Feature;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;

/**
 * This algorithm creates a convex hull of a Geotools FeatureCollection
 * @author BenjaminPross
 *
 */
public class ConvexHullDemo extends AbstractSelfDescribingAlgorithm {

        @Override
        public Map<String, IData> run(Map<String, List<IData>> inputData)
                        throws ExceptionReport {
                if (inputData == null || !inputData.containsKey("FEATURES")) {
                        throw new RuntimeException(
                                        "Error while allocating input parameters");
                }
                List<IData> dataList = inputData.get("FEATURES");
                if (dataList == null || dataList.size() != 1) {
                        throw new RuntimeException(
                                        "Error while allocating input parameters");
                }
                IData firstInputData = dataList.get(0);
                FeatureCollection featureCollection = ((GTVectorDataBinding) firstInputData)
                                .getPayload();

                FeatureIterator iter = featureCollection.features();
                List<Coordinate> coordinateList = new ArrayList<Coordinate>();
                while (iter.hasNext()) {
                        SimpleFeature feature = (SimpleFeature) iter.next();
                        if (feature.getDefaultGeometry() == null) {
                                throw new NullPointerException(
                                                "defaultGeometry is null in feature id: "
                                                                + feature.getID());
                        }
                        Geometry geom = (Geometry) feature.getDefaultGeometry();
                        Coordinate[] coordinateArray = geom.getCoordinates();
                        for (Coordinate coordinate : coordinateArray) {
                                coordinateList.add(coordinate);
                        }
                }
               
                iter.close();

                Coordinate[] coordinateArray = new Coordinate[coordinateList.size()];
                for (int i = 0; i < coordinateList.size(); i++) {
                        coordinateArray[i] = coordinateList.get(i);
                }

                com.vividsolutions.jts.algorithm.ConvexHull convexHull = new com.vividsolutions.jts.algorithm.ConvexHull(
                                coordinateArray, new GeometryFactory());
                Geometry geometry = convexHull.getConvexHull();

                String uuid = UUID.randomUUID().toString();
                SimpleFeatureType featureType = GTHelper.createFeatureType(geometry,
                                uuid, featureCollection.getSchema()
                                                .getCoordinateReferenceSystem());
                GTHelper.createGML3SchemaForFeatureType(featureType);
                Feature feature = GTHelper.createFeature("0", geometry, featureType);

                SimpleFeatureCollection fOut = DefaultFeatureCollections.newCollection();
                fOut.add((SimpleFeature) feature);

                HashMap<String, IData> result = new HashMap<String, IData>();
                result.put("polygons", new GTVectorDataBinding(fOut));
                return result;
        }

        @Override
        public Class getInputDataType(String identifier) {
                if (identifier.equalsIgnoreCase("FEATURES")) {
                        return GTVectorDataBinding.class;
                }
                return null;
        }

        @Override
        public Class getOutputDataType(String identifier) {
                if (identifier.equalsIgnoreCase("polygons")) {
                        return GTVectorDataBinding.class;
                }
                return null;
        }

        @Override
        public List<String> getInputIdentifiers() {
                List<String> list = new ArrayList<String>();
                list.add("FEATURES");
                return list;
        }

        @Override
        public List<String> getOutputIdentifiers() {
                List<String> list = new ArrayList<String>();
                list.add("polygons");
                return list;
        }

}
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

soshi
actually, I import all source code for 52north wps in eclipse, so all library should be appeared in eclipse, another process that use these classes haven't got the errors, but the class that I added to it have got errors..........
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

BenjaminPross
In reply to this post by soshi
Hi,

Try to add the following dependency to your project:

        <dependency>
                <groupId>org.n52.wps</groupId>
                <artifactId>52n-wps-io-geotools</artifactId>
                <version>your-wps-version</version>
        </dependency>

Hope this helps.

Cheers,

Benjamin
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

BenjaminPross
In reply to this post by soshi
Did you import the WPS as a Maven project?
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

soshi
Yes,
it works...
Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

soshi
Hi again,
when I run program, it will face error:

SEVERE: Servlet.service() for servlet [wpsServlet] in context with path [/52n-wps-webapp] threw exception [Servlet execution threw an exception] with root cause
java.lang.NoClassDefFoundError: org/n52/wps/io/data/binding/complex/GTVectorDataBinding
        at org.n52.wps.demo.ConvexHullDemo.getInputDataType(ConvexHullDemo.java:110)
        at org.n52.wps.server.AbstractSelfDescribingAlgorithm.initializeDescription(AbstractSelfDescribingAlgorithm.java:85)
        at org.n52.wps.server.AbstractAlgorithm.getDescription(AbstractAlgorithm.java:103)
        at org.n52.wps.server.AbstractAlgorithm.processDescriptionIsValid(AbstractAlgorithm.java:110)
        at org.n52.wps.server.LocalAlgorithmRepository.loadAlgorithm(LocalAlgorithmRepository.java:104)
        at org.n52.wps.server.LocalAlgorithmRepository.getAlgorithm(LocalAlgorithmRepository.java:75)
        at org.n52.wps.server.LocalAlgorithmRepository.getProcessDescription(LocalAlgorithmRepository.java:141)
        at org.n52.wps.server.RepositoryManager.getProcessDescription(RepositoryManager.java:288)
        at org.n52.wps.server.CapabilitiesConfiguration.initProcessOfferings(CapabilitiesConfiguration.java:261)
        at org.n52.wps.server.CapabilitiesConfiguration.initSkeleton(CapabilitiesConfiguration.java:245)
        at org.n52.wps.server.CapabilitiesConfiguration.getInstance(CapabilitiesConfiguration.java:221)
        at org.n52.wps.server.CapabilitiesConfiguration.getInstance(CapabilitiesConfiguration.java:200)
        at org.n52.wps.server.response.CapabilitiesResponse.getAsStream(CapabilitiesResponse.java:61)
        at org.n52.wps.server.handler.RequestHandler.handle(RequestHandler.java:365)
        at org.n52.wps.server.WebProcessingService.doGet(WebProcessingService.java:245)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
        at org.n52.wps.server.WebProcessingService.service(WebProcessingService.java:362)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
        at org.apache.catalina.filters.CorsFilter.handleNonCORS(CorsFilter.java:410)
        at org.apache.catalina.filters.CorsFilter.doFilter(CorsFilter.java:169)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
        at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:169)
        at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:232)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1096)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:760)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1480)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:745)
 
could you help me? please...
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

BenjaminPross
As I wrote in the other thread, it is important to know, whether you downloaded the WPS or compiled it yourself. If you downloaded it, did you add the GeoTools package? If you compiled it yourself, did you use the profile with-geotools?
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

soshi
I didn't catch that,
I just added a dependency with artifactid (52n-wps-io-geotools) as you said, because the convexhulldemo class got error. when I added dependency to pom file, the class have no error. and when I compiled program with install goal, it was succeeded build. but while I run program by server (apache tomcat), the error happend. and GetCapabilities response didn't show anything and the error as mentioned early post is showed in console.
what should I do exactly?  
could you explain clearly, please...
thanks
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

BenjaminPross
Supposing that you build the WPS, you will have to activate the profile with-geotools (see here for how to do it in Eclipse: http://czetsuya-tech.blogspot.com/2011/11/how-to-activate-maven-profile-inside.html)

If you run Maven install via the console, you will have to add -Pwith-geotools.
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

soshi
thanks dear BenjaminPross,
Get Capabilities dosen't have any problem, but it dosen't show convexhulldemo process that I added to project.
should I write client for convexhulldemo in sub module (52n.wps.client.lib) project in order to see the process into Getcapabilities response?am i right?
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

soshi
I also added the process into wps_config.xml:
 
<Property name="Algorithm" active="true">org.n52.wps.server.algorithm.SimpleBufferAlgorithm</Property>

and then build the project again, but it dosen't exist into GetCapabilities response.
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

BenjaminPross
Try to add:

<Property name="Algorithm" active="true">org.n52.wps.demo.ConvexHullDemo</Property>
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

soshi
I definitely added it but it dosen't work.

<Repository name="LocalAlgorithmRepository"
                        className="org.n52.wps.server.LocalAlgorithmRepository" active="true">
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.JTSConvexHullAlgorithm</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.test.DummyTestClass</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.test.LongRunningDummyTestClass</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.test.MultipleComplexInAndOutputsDummyTestClass</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.test.MultiReferenceInputAlgorithm</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.test.MultiReferenceBinaryInputAlgorithm</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.test.EchoProcess</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.process.ExtensionAlgorithm</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.process.JTSBufferAlgorithm</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.demo.ConvexHullDemo</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.SimpleBufferAlgorithm</Property>
                </Repository>
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

BenjaminPross
Right, I forgot to mention that you need to use the wps_config_geotools.xml. So add the line:

<Property name="Algorithm" active="true">org.n52.wps.demo.ConvexHullDemo</Property>

to the LocalAlgorithmRepository in the wps_config_geotools.xml file.
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

soshi
I also added it in wps_confige_geotools,
but it didnt' happen anything,

<Repository name="LocalAlgorithmRepository"
                        className="org.n52.wps.server.LocalAlgorithmRepository" active="true">
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.SimpleBufferAlgorithm</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.JTSConvexHullAlgorithm</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.coordinatetransform.CoordinateTransformAlgorithm</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.simplify.DouglasPeuckerAlgorithm</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.intersection.IntersectionAlgorithm</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.convexhull.ConvexHullAlgorithm</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.raster.AddRasterValues</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.spatialquery.IntersectsAlgorithm</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.spatialquery.TouchesAlgorithm</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.test.DummyTestClass</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.test.LongRunningDummyTestClass</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.test.MultipleComplexInAndOutputsDummyTestClass</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.test.MultiReferenceInputAlgorithm</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.test.MultiReferenceBinaryInputAlgorithm</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.test.EchoProcess</Property>
                        <Property name="Algorithm" active="true">org.n52.wps.demo.ConvexHullDemo</Property>
                </Repository>
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

BenjaminPross
In which sub module did you add the ConvexHullDemo process?
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

soshi
sub mosule: 52n.wps.algorithm
package:org.n52.wps
subfolder: demo (i created it)
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

BenjaminPross
And you did use the profile with-geotools when building the WPS, right?
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

soshi
definitely yes, should i have a client for that?
Reply | Threaded
Open this post in threaded view
|

Re: error in library for ConvexHullDemo process

BenjaminPross
The image is too small, I am afraid. Anyway, how do you start the service? Out of eclipse with Run as -> Run on Server? Also, make sure that you are not using -Pwith-geotools in Eclipse, just with-geotools.
123