WPS Code Snippets
In this section you can find some useful code snippets.
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()));
CoordinateReferenceSystem crs = feature.getFeatureType().getCoordinateReferenceSystem();
if(crs == null && geometry.getUserData() instanceof CoordinateReferenceSystem){
crs = ((CoordinateReferenceSystem) geometry.getUserData());
}
String uuid = UUID.randomUUID().toString();
SimpleFeatureType featureType = GTHelper.createFeatureType(geometry, uuid, crs);
GTHelper.createGML3SchemaForFeatureType(featureType);
Feature feature = GTHelper.createFeature(id, geometry, featureType);
SimpleFeature createdFeature = (SimpleFeature) GTHelper.createFeature("ID"+new Double(i).intValue(),geometry,(SimpleFeatureType) featureType,anotherFeature.getProperties());