The Web Feature Service (WFS) is an implementation around Views and Drupal-stored geodata.

WFS is useful for users who must display many points on an OpenLayers map or complex data that would be poorly rendered by browsers. Essentially, GeoServer can pull node data from Drupal via WFS and display the points as a rendered image. Then the user can interact with the map by clicking and making WFS queries for point information.

This page goes into detail about how to setup the WFS module. It documents the specific use-case where:

  1. WFS module reads spatial features from Drupal database (nodes) and serves them using WFS protocol
  2. GeoServer reads the WFS protocol, renders features to raster images and serves these using WMS protocol
  3. OpenLayers module reads both WFS and WMS data; WMS (raster) is used for display, whereas WFS is just to know feature locations so that users can click on them (this is achieved using virtualhover and virtualclick behaviors provided by WFS module)

One can also use the WFS module just to serve WFS, without using GeoServer or OpenLayers; in this case only a subset of the following steps is needed.

Install GeoServer

This is out of the scope of this documentation, but there is plenty of documentation at http://geoserver.org/

Install WFS Module

  1. Install like any other Drupal module.
  2. OpenLayers has an outstanding bug for CDATA in WFS which will prevent this module from working unless it is fixed there, or you use a patched OpenLayers library. A patched library is included with this module in js/OpenLayers.js. Update OpenLayers Library API setting at admin/build/openlayers to sites/all/modules/wfs/js/OpenLayers.js (assuming this is where the WFS module is installed).

Data and Views

The next step will be to set up a View that provides a WFS feed.

  1. You'll have to create some sort of data structure. This can be done with the OpenLayers WKT CCK field. You'll also want to add some sample or real data.
  2. Create a new View at /admin/build/views/add, more than likely this will be a Node view, but this is not necessary.
  3. Create a new WFS display in your View.
  4. At the very least, you'll need to add some fields.
    • If you are using the OpenLayers WKT CCK field, then you will want to add this.
    • Or you could use arbitrary latitude and longitude, maybe provided by Location.
    • Some sort of ID field, this is mostly likely the Node ID.
    • Whatever other data that seems appropriate to be provided to the WFS feed.
  5. Choose the WFS Feed style for the display. Then choose your ID and data fields appropriately.
  6. Choose a path for the feed, such as wfs_drupal_data.
  7. Save.

Set up GeoServer

The details of GeoServer are not in the scope of the documentation, but the following should be enough to get your WFS served.

  1. Create a new workspace with the following values:
    • Name: This is a unique identifier with no space, such as wfs_example
    • Namespace URI: This has to be http://drupal.org/project/wfs
  2. Create a new data store with the following values:
    • Workspace: This is the unique identifier of the workspace defined above, such as wfs_example
    • Data source name: This is a title, such as My WFS Data Store
    • Description: Description of data source.
    • WFS GetCapabilities URL: This is the full URL from your view in your Drupal site formatted like so: http://example.com/wfs_drupal_data?request=GetCapabilities
    • The rest of the values can be blank as the defaults will be used.
  3. Add Layer ...

OpenLayers Virtual Vector Layer

  1. Add new Virtual Vector layer at /admin/build/openlayers/layers/add/wfs_layer_type_virtualvector
  2. Fill in the following values:
    • URL: This is based on where your GeoServer is set up, for example: http://localhost:8080/geoserver/wfs. Please note that this needs to be an absolute URL, or you will need to make sure your OpenLayers is using some sort of proxy. See Proxy module for a Drupal implementation.
    • The type name should be the name of your view, like wfs_drupal_view
    • Geometry name: keep as geometry
    • Name, Title, and Description are all just basic layer data.
  3. Save.

OpenLayers Map Preset

You will now build a map that utilizes the WFS feed via the GeoServer. This map preset can be displayed with Views. The scope of this document does not fully cover all the options available in the OpenLayers module, just the key settings to get a map to work with WFS.

  1. Under General Information, we need to update a few things to take into account some limitations described above.
    • Because you are using a patched version of the OpenLayers.js library (see above), you need to change the Image Path. To use the hosted version, simply set to http://openlayers.org/api/img/. It is recommended to use a locally hosted set of images for performance.
    • For the same reason as the Image Path, you need to update the CSS Path. The hosted version would be http://openlayers.org/api/theme/default/style.css
    • A proxy path will need to be set if you are using a GeoServer that is on a different domain. If using the Proxy module, set this to: l/proxy?request=
  2. Under Layer and Styles you will need to add the layer to the map.
    • Under the Overlays section, enable the layer that you create above.
  3. Behaviors
    • Something how to set up virtual click.
  4. Styles
    • Something about defining styles

Comments

vikashtalanki’s picture

I have done everything that is given in this page, But the markers are not visible, I am not getting any errors in both firefox or chrome. I really don't understand what the problem is.... Can anyone help me, I am using openlayers-2.10, is there any problem with this version??

ulim’s picture

Note that you can also deliver WFS and WMS from Drupal using the GeoServer module. This module will require slightly more initial work to have GeoServer and Drupal play together than the steps described above. In the end it will allow to manage most GeoServer settings right from within Drupal, without ever touching the GeoServer user interface. Moreover it allows to promote all data access privileges defined for Drupal content types to the respective OGC webservices. The GeoServer module works best with true geospatial data types like you have it for example in a PostGIS database.