I am trying to create my own WPS process in Java about overlaying two polygon shapefiles, but I can't figure out how to do it. Here is a code about reading Shapefile and creating buffer around point.

public String overlay(String pointString, double distance) {
    String names = "Object:Area of overlay";
        try {
            //read SHP
            ShapefileDataStore sfdt = new ShapefileDataStore(new URL("file:///_ING/geoserver-2.8.0/data_dir/data/sf/restricted.shp"));
            SimpleFeatureSource sfs = sfdt.getFeatureSource("restricted");

            //double distance 1000.0d;
            GeometryFactory gf = new GeometryFactory ();
            String xy [] = pointString.split(" ");
            Point point = gf.createPoint(new Coordinate(Double.parseDouble(xy[0]), Double.parseDouble(xy[1])));

            Polygon p1 = (Polygon) point.buffer(distance);

            SimpleFeatureIterator sfi = sfs.getFeatures().features();
            while (sfi.hasNext()) {
                SimpleFeature sf = sfi.next();
                MultiPolygon mp2 = (MultiPolygon) sf.getDefaultGeometry();
                Polygon p2 = (Polygon) mp2.getGeometryN(0);
                Polygon p3 = (Polygon) p2.intersection(p1);
                names = names + "\n" + sf.getAttribute("cat") + ": " + p3.getArea();

        }   catch (MalformedURLException ex) {
        Logger.getLogger(Process.class.getName()).log(Level.SEVERE, null, ex);

        } catch (IOException ex2) {
        Logger.getLogger(Process.class.getName()).log(Level.SEVERE, null, ex2);

    return "Objects found: " + names;

Here is implementation into GeoServer

@DescribeProcess (title="overlayWPS", description="Creates buffer around point and overlays it with polygon layer. Returns area of overlay.")
public class OverlayWPS implements GeoServerProcess {

    @DescribeResult(name="result", description="output result")
    public String execute(@DescribeParameter(name="point", description="point") String point, @DescribeParameter(name="distance", description="distance to search") double distance) {
        Process p = new Process();
        return p.overlay(point, distance);

I would like to change it get overlay of two separate shapefiles and get overlaid area as third multi-polygon layer.



As you have figured out there are two distinct steps to building a new WPS process.

  1. Build a GeoTools process to carry out the actual work
  2. Build a GeoServer `WPS wrapper to call that process.

There are two tutorials that walk you through each of those steps, the GeoTools process tutorial and the GeoServer WPS service tutorial.

However for your problem you should be able to achieve the requirement of returning the overlap between two shapefile layers using the existing gs:IntersectionFeatureCollection process provided by default in the WPS plugin.

  • Thanks for tips. And yes, i know there is such a process, but i want to make my own. Its one of the processes i want to chain inside of one "WPS wrapper" – David Feb 21 '17 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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