use of org.geotoolkit.wps.client.process.WPSProcessingRegistry in project geotoolkit by Geomatys.
the class WPSClientDemo method main.
public static void main(String[] args) throws Exception {
// force loading all image readers/writers
ImageIO.scanForPlugins();
// global initialization
Setup.initialize(null);
// Instantiate client :
final URL wpsURL = new URL(SERVICE_URL);
final WebProcessingClient wpsClient = new WebProcessingClient(wpsURL, WPSVersion.v100.getCode());
// Once initialized, we can ask a description of wanted process, using its id.
final WPSProcessingRegistry registry = new WPSProcessingRegistry(wpsClient);
ProcessDescriptor desc = registry.getDescriptor(PROCESS_ID);
// We can check process input & output.
ParameterDescriptorGroup inputDesc = desc.getInputDescriptor();
ParameterDescriptorGroup outputDesc = desc.getOutputDescriptor();
// Iterate on wanted parameters. If one is missing, an exception is raised.
LOGGER.log(Level.INFO, "INPUT : \n");
for (INPUT in : INPUT.values()) {
final GeneralParameterDescriptor current = inputDesc.descriptor(in.name);
LOGGER.log(Level.INFO, "Parameter : " + current.getName().getCode() + " : \n\t" + current.getRemarks());
}
LOGGER.log(Level.INFO, "OUTPUT : \n");
for (OUTPUT out : OUTPUT.values()) {
final GeneralParameterDescriptor current = outputDesc.descriptor(out.name);
LOGGER.log(Level.INFO, "Parameter : " + current.getName().getCode() + " : \n\t" + current.getRemarks());
}
GeometryFactory factory = org.geotoolkit.geometry.jts.JTS.getFactory();
Geometry geometry = factory.toGeometry(new Envelope(1.0, 2.0, 43.3, 43.9));
geometry.setUserData(CommonCRS.WGS84.geographic());
final double bufDistance = 0.5;
// Instantiate inputs. Those objects get the same behaviour that the descriptors. If we cannot find a specific
// parameter, an exception is thrown.
ParameterValueGroup input = inputDesc.createValue();
input.parameter(INPUT.geom.name).setValue(geometry);
input.parameter(INPUT.distance.name).setValue(bufDistance);
// Process execution. It's synchronous here (talking only of client side, WPS can execute asynchronous process).
// For asynchronous execution, we must execute it in a thread, using a process listener to get process state.
org.geotoolkit.process.Process toExecute = desc.createProcess(input);
toExecute.addListener(new NullProgressListener());
ParameterValueGroup output = toExecute.call();
// Get output values :
for (OUTPUT out : OUTPUT.values()) {
LOGGER.log(Level.INFO, String.format("%s parameter value : %s", out.name(), output.parameter(out.name).getValue()));
}
}
Aggregations