Using the OGC Web Processing Service (WPS) to move business logic to the server

Ian Turton, Astun Technology [email protected] @ijturton

Making your Web GIS seem Clever

Ian Turton, Astun Technology [email protected] @ijturton

Web GIS is cool if you want to look at a map and may be query points on it.

But what if I want to do something more complex?

JavaScript can do that

... from the polygons in the WMS base map!

Do Some Analysis?

Oh yes, and...

JavaScript might not cut it any more!

Enter Web Processing Service

Or, in other words, I can write the process in Java (or Python) and run it on my server (hiding the PostGIS credentials) and have my Web GIS access it (asynchronously) via a well known API.

COOL!

GeoServer Processing

Annotations

@DescribeProcess(title = "Pick and Union",
  description = "Return the union of the features that fulfil the provided filter and the geometry passed in.")
@DescribeResult(name = "result",
  description = "The union of the selected features and the geometry", primary = true, type = Geometry.class)

static public Geometry getFeatures(
    @DescribeParameter(name = "collection",
      description = "The features to be searched", min = 1) SimpleFeatureCollection collection,
    @DescribeParameter(name = "filter",
      description = "the filter to be used for the search (CQL or OGC)", min = 1) String filter,
    @DescribeParameter(name = "geometry",
      description = "Optional geometry to union with the results of the filter.", min = 0) Geometry geom,
    @DescribeParameter(name = "subtract",
      description = "If true then the matching geometries are removed from geometry, default false", min = 0)
      Boolean subtract,
    @DescribeParameter(name = "organisation",
      description = "The name of the organisation making the request, default none", min = 0) String organisation) {

Compile, jar and drop in

As if by magic your WPS appears in the list of processes with all of the arguments documented.

<wps:Execute version="1.0.0" service="WPS">
  <ows:Identifier>PickerAndUnion:getFeatures</ows:Identifier>
  <wps:DataInputs>
    <wps:Input>
      <ows:Identifier>collection</ows:Identifier>
      <wps:Reference mimeType="text/xml" xlink:href="http://geoserver/wfs" method="POST">
        <wps:Body>
          <wfs:GetFeature service="WFS" version="1.0.0" outputFormat="GML2" xmlns:astun="http://astuntechnology.com/">
            <wfs:Query typeName="astun:topographicarea"/>
          </wfs:GetFeature>
        </wps:Body>
      </wps:Reference>
    </wps:Input>
    <wps:Input>
      <ows:Identifier>filter</ows:Identifier>
      <wps:Data>
        <wps:LiteralData>INSERT FILTER</wps:LiteralData>
      </wps:Data>
    </wps:Input>
    <wps:Input>
      <ows:Identifier>geometry</ows:Identifier>
      <wps:Data>
        <wps:ComplexData mimeType="application/json">
          <![CDATA[insert json geom]]>
        </wps:ComplexData>
      </wps:Data>
    </wps:Input>
  </wps:DataInputs>
  <wps:ResponseForm>
    <wps:RawDataOutput mimeType="application/json">
      <ows:Identifier>result</ows:Identifier>
    </wps:RawDataOutput>
  </wps:ResponseForm>
</wps:Execute>

PINS Process

  • unpack shapefile and convert to feature/geometry
  • connect to PostGIS database
  • create a filter for each rule
  • extract matching features from 30 layers
  • produce PDF map (WMS call)
  • add a sheet to Excel spreadsheet (Apache POI)
  • finally, zip output up and notify client

Actually, implemented as two WPS processes

  • upload, unpack and copy shapefile to PostGIS
  • Create a report based on that feature (using a preprepared template)

Demo - after upload

Select Site

Select Report

Wait for Report

Download and Unpack

Conclusions

If you are looking for an easy way to make your web map application smarter, without tying yourself down to a back service you can use a WPS to move complex business logic to the server.

SpaceForward
Right, Down, Page DownNext slide
Left, Up, Page UpPrevious slide
GGo to slide number
POpen presenter console
HToggle this help