Chaining process – selecting features contained in a polygon

In the previous recipe, you started working with geoprocessing requests. Looking at the supported operations, you see that it is a very long one. There are several different operations you can perform on the data. Most of these operations are quite simple, while in a real-world use case, you often need more complex ones. So, how can you translate a real-world use case into a task that GeoServer is able to execute? The elegant and efficient answer is chaining processes.

WPS lets you use the result of an operation as an input to another operation. While this may seem very simple, it offers you an incredible flexibility and power. By using the built-in operations as building blocks, you can create very complex geoprocessing tasks. The WPS process builder will let us try out this powerful idea.

In this recipe, your target is to find all populated places located inside Switzerland.

How to do it…

  1. Open the GeoServer administrative interface and open the WPS process builder page.
  2. Select gs:Clip from the processes' list. The Input feature collection is the layer from where we want to extract the data, so select NaturalEarth:populatedplaces.
    How to do it…
  3. Scroll down to the section where you have to define the clipping geometry. This time, you won't input a geometry. You're going to use the result from another operation. To build the chain, select SUBPROCESS from the list.
    How to do it…
  4. Press the Define/Edit link; a new panel shows up where you can define the parameters for the new process that will be executed. Select the gs:CollectGeometries operation and again choose SUBPROCESS as the input for you operation.
    How to do it…
  5. You're at the last step of this geoprocessing task. Select Define/Edit and select gs:Query task. The input for this query is the NaturalEarth.EuropeCountries layer. In the filter section, you can choose the CQL syntax, which is easier to type. You will then apply filter on the admin field.

    Tip

    CQL was originally used for catalog systems, GeoServer uses an extension to CQL allowing the full representation of OGC filters in text form. This extension is called Extended Common Query Language (ECQL).

    How to do it…
  6. Now, press the Apply button to return to the previous operation. You will need to press it once more in order to apply all the chained operations. Eventually, you will land on the WPS process builder page with a huge XML code in the clip geometry textbox.
    How to do it…
  7. Press the Execute Process button, a new panel shows and after a while, it is populated with the GML code for the populated places list. Your extraction was successful!
    How to do it…

How it works…

You created a relatively complex task by using three simple operations exposed by WPS.

Your target is to select all point features inside an area, that is, Switzerland. The first step is to set the geometry of Switzerland. You can input it by typing a WKT description, of course, but this may work only for a really simple and small geometry. In a real-world scenario, you'll have to type hundreds or thousands of vertices, which is also error-prone and time-consuming.

We already have a detailed representation of Switzerland boundaries in the EuropeCountries layer, so the first step is to filter it with the gs:Query operation.

The query made use of a CQL filter to select Switzerland and resulted in an XML document containing the description of the extracted feature. The XML included the values of geometrical and alphanumerical attributes.

You only need the geometry part and in a form suitable to work as an input for a gs:Clip operation. This transformation is what gs:CollectGeometries performs.

You can try to build a simpler task by just using the gs:Query and gs:CollectGeometries operations. The result is an XML fragment shown in the following snippet:

<gml:MultiPolygon srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
    <gml:polygonMember>
        <gml:Polygon>
            <gml:outerBoundaryIs>
                <gml:LinearRing>
                    <gml:coordinates>8.617437378000076,47.757318624000085 8.62983972100005,47.76279632600007 
                      …
                      8.607618856000105,47.76225372300012 8.617437378000076,47.757318624000085</gml:coordinates>
                </gml:LinearRing>
            </gml:outerBoundaryIs>
        </gml:Polygon>
    </gml:polygonMember>
</gml:MultiPolygon>

This is exactly the input that gs:Clip expects as clip geometry.

You can chain many different processes to fit your requirements. Of course, you can interact with WPS from an external app as we are going to see in the next recipe.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.163.13