WPS Code Snippets

In this section you can find some useful code snippets.

Extract Parameter in your algorithm

The

        public Map<String, IData>   run(Map<String, List<IData>> inputData){

method has one parameter containing all input parameters as key value pairs. The key is the identifier defined in ProcessDescription Document, the value a list of IData objects. In case the ProcessDescription allows multiple input parameters with the same identifier, then the list will contain more then one element. The IData Interface has implementations for specific datastructures. The implementation we are using in this example comes from Geotools as the internal datastructure (GTVectorDataBinding).

        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();

Update the percentage in your algorithm

Your process class must implement IAlgorithm and ISubject or inherit from a class that inherits from both interfaces. See an overview here.

You only need to use the following snippet:

        this.update(new Integer(percentage.intValue()));

Extract the Coordinate Reference System from a Geotools Feature

        CoordinateReferenceSystem crs = feature.getFeatureType().getCoordinateReferenceSystem();
        if(crs == null && geometry.getUserData() instanceof CoordinateReferenceSystem){
                crs = ((CoordinateReferenceSystem) geometry.getUserData());
        }

Create Geotools FeatureType

        String uuid = UUID.randomUUID().toString();
        SimpleFeatureType featureType = GTHelper.createFeatureType(geometry, uuid, crs);

Create GML3 Schema for Geotools FeatureType

        GTHelper.createGML3SchemaForFeatureType(featureType);

Create Geotools Feature for given FeatureType

        Feature feature = GTHelper.createFeature(id, geometry, featureType);

Create a new Geotools feature with all attributes from another feature

        SimpleFeature createdFeature = (SimpleFeature) GTHelper.createFeature("ID"+new Double(i).intValue(),geometry,(SimpleFeatureType) featureType,anotherFeature.getProperties());
Topic revision: r2 - 14 Jun 2013, BenjaminPross
Legal Notice | Privacy Statement


This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Wiki? Send feedback