9. WMS server with GeoServer

Now that we have a pl/pgsql wrapper, we will make it available as a WMS layer using GeoServer.

The installation of GeoServer is out of scope of this workshop but if you’re using the OSGeo LiveDVD the server is already installed and only needs to be started.

9.1. Connect to the administration page

In order to create the WMS layer, we need to connect to the administration page of GeoServer. On the OSGeo LiveDVD, open the Applications menu on the desktop and then Geoservers > GeoServer > Start GeoServer.

Once the server is up, the administration page should open, click the Login button and entrer the admin credentials:

  • Username: admin
  • Password: geoserver

9.2. Create the layer

Now that we are logged in as an administrator we can start create our layer. In GeoServer terminology we will create an SQL View (see the official documentation for more info).

The first thing to do is to create a new Workspace for pgrouting: in the left menu of the page, inside the Data section, click Workspaces and then Add new workspace.

Fill the form with:

  • Name: pgrouting
  • Namespace URI: http://pgrouting.org/

Add press the submit button.

Next step: create a new Store linked to the workspace. Still in the left menu, click Stores and then Add new Store. Here we can choose the type of data source to configure. Choose PostGIS.

Fill the form with:

  • Basic Store Info:
  • Workspace (select): pgrouting
  • Data Source Name: pgrouting
  • Connection Parameters:
  • host: localhost
  • port: 5432
  • database: pgrouting-workshop
  • schema: public
  • user: postgres
  • password: blank

The rest of the values can be left untouched.

Finally, our next task is to create the Layer. Click the Layers menu and then Add a new resource. Select the newly created workspace and store pair: pgrouting:pgrouting.

Inside the text, click Configure new SQL view.

Name the view pgrouting and fill the SQL statement with:

SELECT ST_MakeLine(route.geom) FROM (
    SELECT geom FROM pgr_fromAtoB('ways', %x1%, %y1%, %x2%, %y2%
  ) ORDER BY seq) AS route

In the SQL view parameters, click Guess parameters from SQL; the list displayed represents the parameters from the SQL above.

For each parameter:

  • Set the default value to: 0
  • Change the validation regular expression to ^-?[\d.]+$

The regular expression will only match numbers.

In the Attributes list:

  • Hit Refresh, one attribute should appear (called st_makeline)
  • Change the type to LineString and the SRID of the geometry column from -1 to 4326

Save the form.

Finally, we need to setup the rest of the layer.

The only thing to do in this screen is to make sure that the coordinate reference system is correct: the geometries in the database are in EPSG:4326 but we want to display them in EPSG:3857 because the OPenLayers map where the layer will be dispayed is in this projection.

Scoll down to the coordinate reference system section and change the Declared SRS to EPSG:3857 and the SRS handling to Reproject native to declared.

Click the Compute from data and Compute from native bounds link to automatically set the layer bounds. Click the Save at the bottom of the page to create the layer.

Table Of Contents

Previous topic

8. Writing a pl/pgsql Wrapper

Next topic

10. OpenLayers 3 Browser Client


This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License.

Creative Commons License