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:
- WFS module reads spatial features from Drupal database (nodes) and serves them using WFS protocol
- GeoServer reads the WFS protocol, renders features to raster images and serves these using WMS protocol
- 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
- Install like any other Drupal module.
- 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 atadmin/build/openlayers
tosites/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.
- 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.
- Create a new View at
/admin/build/views/add
, more than likely this will be a Node view, but this is not necessary. - Create a new WFS display in your View.
- 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.
- Choose the WFS Feed style for the display. Then choose your ID and data fields appropriately.
- Choose a path for the feed, such as
wfs_drupal_data
. - 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.
- 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
- Name: This is a unique identifier with no space, such as
- 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.
- Workspace: This is the unique identifier of the workspace defined above, such as
- Add Layer ...
OpenLayers Virtual Vector Layer
- Add new Virtual Vector layer at
/admin/build/openlayers/layers/add/wfs_layer_type_virtualvector
- 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.
- URL: This is based on where your GeoServer is set up, for example:
- 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.
- 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=
- 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
- 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.
- Behaviors
- Something how to set up virtual click.
- Styles
- Something about defining styles
Comments
Markers not visible
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??
Alternatives for serving WFS
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.