I am pretty new to Geoserver and programming processes for it. I having trouble to find the information I need. Is it possible to call a existing function inside my own WPS class? I want to clip some polygons but don't want to import the whole clipping sourcecode into my project. Do I need some special imports or is it possible to access other WPS processes directly? Would be some sort of process chaining I guess. I can only find examples for this using the WPS builder and XML files but I don't want to go this way, insted do this directly in Java.

1 Answer 1


It's fairly easy to call a GeoTools process from within your code:

Name name = new NameImpl("TableJoin", "joinTables");
org.geotools.process.Process process = Processors.createProcess(name);

ProcessExecutor engine = Processors.newProcessExecutor(2);

// quick map of inputs
String sname = statesDS.getTypeNames()[0];
String iname = stateUnempDS.getTypeNames()[0];
String typeName = statesDS.getSchema(sname).getTypeName();
Join j = new Join(typeName, ECQL.toFilter("strToLowerCase(\"A.STATE_NAME\") = strToLowerCase(\"STATE_NAME\")"));
QueryType query = Wfs20Factory.eINSTANCE.createQueryType();


WFSConfiguration configuration = new org.geotools.wfs.v2_0.WFSConfiguration();
org.geotools.xml.Encoder encoder = new org.geotools.xml.Encoder(configuration);

// create an output stream
ByteArrayOutputStream xml = new ByteArrayOutputStream();

// encode
encoder.encode(query, org.geotools.wfs.v2_0.WFS.Query, xml);

String jxml = xml.toString("UTF-8");
Map<String, Object> input = new KVP("target", statesDS.getFeatureSource(sname).getFeatures(), "source",
    stateUnempDS.getFeatureSource(iname).getFeatures(), "join", jxml);

Progress working = engine.submit(process, input);

Map<String, Object> result = working.get(); // get is BLOCKING
SimpleFeatureCollection out = (SimpleFeatureCollection) result.get("result");

Don't worry too much about the XML encoding of the query element that is just if you need to pass an XML string in. Most processes are more likely to take a featureCollection and a few primitives. The easiest way to see how to call an existing process is to check out it's test class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.