How To Setup a Basic WFS and WMS

Version Date:
01-05-13
Author:
Arie Kraak
How To Setup a Basic WFS and WMS
This How To describes a way to build a basic WFS and WMS to serve and view data from a single table
available in a database. Hyperlinks refer to background on specific deegree terminolology.
Starting point
Starting point is that data is available in a single PostGIS database table. In this case a table is used from a
Database called “cds_inspire”, Schema name “bron” and Table name “protected_site”.
Note: despite the data base name, this How To describes a general WMS and WFS. Please see the How To
on INSPIRE for building an INSPIRE compliant View and Download Service.
Workflow overview
The following workflow has been followed in this How To. (Text in brackets refer to the menu of the deegree
console).
1.
2.
3.
4.
5.
6.
Fire up the deegree console
Create a new deegree workspace from scratch (general → workspaces)
Create a connection to the database (server connections → jdbc)
Create an SQL feature store (datastores → feature)
Create a new WFS (web services → services)
Create a new WMS
6.1 Create a new WMS configuration (web services → services)
6.2 Create a new layer store (map layers → layers)
6.3 Create a new theme (map layers → themes)
Note: Testing of the WFS and WMS can be done, by sending requests using the console (general → send
requests) and by using a GIS client such as Open Source Quantum GIS (www.qgis.org/). Be sure to
download its WFS 2.0.0 client plugin!
Step by step
1
Fire up the deegree console.
In this case deegree is running in TomCat and can be opened using the URL:
http://127.0.0.1:8081/deegree-webservices-3.2.0
2
Create a new deegree workspace from scratch
1. Go to the .deegree directory on your system
2. Create folder with desired workspace name. In this case “how-to-wfs-wms”
3. In deegree console click “general → workspaces”. You workspace should now be listed under
“Available workspaces”.
4. Click Start. Your workspace is now indicated as Active workspace at the top of the console
interface window.
Note: Use the [Reload] button behind the workspace name to effectuate changes after editing of
workspace files.
3
Create a connection to the database
1. In the deegree console click “server connections → jdbc”
2. Enter a name. In this case “cds-inspire” and click Create new
Figure 1: jdbc
3. Enter the fields according to your settings (see figure 1).
4. Verify by clicking “test connection” and click “Create”. The new jdbc is now listed and indicated as
“On”
4
Create an SQL feature store
1. In the deegree console click datastores → feature
2. Enter a name. In this case `protectedSite`. Choose `SQL` and click Create new.
3. Choose `Create config manually` select right JDBC Connection and click `Next`.
4. Choose Config template `example` and click OK
Note: now you enter the editing mode of the deegree console. Use `Turn on highlighting` (under
editing window) to improve the readability of the XML code. You see a template with example
configuration. We will use the “Config option 5” in the template. So in this case delete all lines after
the element </JDBCCConnID> until <!-- Config option 5: ..>.
In this XML the mapping takes place between database table (columns) and deegree XML. In
this case our database table protectedSite has the following columns:
• id
• job_id
• geometry
• legal_foundation_date
• legal_foundation_document
• inspire_id
• site_name
• site_designation
•
•
site_protection_classification
gfid
5. Add the namespace: “xmlns:ps="urn:tutorial:protectedSite:flat"
Remark on Namespaces:
Every configuration file (XML) starts with definitions of name spaces (xmlns). XML namespaces are
used for providing uniquely named elements and attributes in an XML documents. In general you
may define your own name spaces. INSPIRE requires certain names paces, others are directly
related to deegree and are automatically available when editing the deegree XML. For instance the
preposition “ps” refers to the self choosen namespace "urn:tutorial:protectedSite:flat"
6. Edit the element <JDBCCConnid>. In this case:
<JDBCConnId>cds-inspire</JDBCConnId>
7. Edit the element <FeatureTypeMapping >. This element determines the so called context for every
following element, and links the database queriable (table) name to the XML name of deegree. In
this case:
<FeatureTypeMapping name="ps:ProtectedSite" table="bron.protected_site">.
8.
Edit the element <FIDMapping>. This has to be unique, in this case it is sufficient to use the column
name “id” from the database table:
<FIDMapping>
<Column name="id" />
</FIDMapping>
9. Edit the element <Geometry>. This refers to the geometry column within the context /table
“bron.protected_site”. In this case :
<Geometry path="ps:geometry" mapping="geometry"/>
This maps the column “geometry” from the database schema “bron” and table “protected_site”. The
“path” determines the child name used in the XML schema in relation to its FeatureType (in this case
“ps.ProtectedSite”).
10. And edit <StorageCRS>. This element relates the crs from the database to the srid of deegree
xml. In this case:
<StorageCRS srid="-1">EPSG:28992</StorageCRS>
11. Our SQL feature store file (protectedSite.xml) looks now like:
<SQLFeatureStore configVersion="3.2.0"
xmlns="http://www.deegree.org/datasource/feature/sql"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ps="urn:tutorial:protectedSite:flat"
xsi:schemaLocation="http://www.deegree.org/datasource/feature/sql
http://schemas.deegree.org/datasource/feature/sql/3.2.0/sql.xsd"
>
<JDBCConnId>cds-inspire</JDBCConnId>
<FeatureTypeMapping name="ps:ProtectedSite"
table="bron.protected_site">
<FIDMapping>
<Column name="id" />
</FIDMapping>
<Geometry path="ps:geometry" mapping="geometry">
<StorageCRS srid="-1">EPSG:28992</StorageCRS>
</Geometry>
</FeatureTypeMapping>
</SQLFeatureStore>
12. Click Save. The new feature store is listed and indicated as “On”
5
Create a new WFS
1. In the console click on web services → services.
2. Enter a name for the new WFS. In this case “how-to-wfs”. Choose type “WFS” and click “Create
new”
Note: now you enter the editing mode of the deegree console. Use `Turn on highlighting` (under
editing window) to improve the readability of the XML code. You see a template with example
configuration, which you can adjust.
3. Add <SupportedVersions> . In this case we use Version 2.0.0.
<SupportedVersions>
<Version>2.0.0</Version>
</SupportedVersions>
4. Set <EnableTransactions>. In this case we choose the WFS to only read from the database. So set
this element to “false”.
<EnableTransactions>false</EnableTransactions>
5. Set <DisableResponseBuffering> to “true” to avoid buffering of features
<DisableResponseBuffering>true</DisableResponseBuffering>
6. Add <FeatureStoreId> as chosen above. In this case: “protectedSite”
<FeatureStoreId>protectedSite</FeatureStoreId>
7. Add the <queryCRS> (In this case for The Netherlands: EPSG:28992)
<QueryCRS>urn:ogc:def:crs:EPSG::28992</QueryCRS>
8. Add <QueryMaxFeatures> and set to – 1 (unlimited)
<QueryMaxFeatures>-1</QueryMaxFeatures>
9.
The configuration now looks like:
EXAMPLE: how-to-wfs.xml
<deegreeWFS xmlns="http://www.deegree.org/services/wfs"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" configVersion="3.2.0"
xsi:schemaLocation="http://www.deegree.org/services/wfs
http://schemas.deegree.org/services/wfs/3.2.0/wfs_configuration.xsd">
<SupportedVersions>
<Version>2.0.0</Version>
</SupportedVersions>
<FeatureStoreId>protectedSite</FeatureStoreId>
<EnableTransactions>false</EnableTransactions>
<EnableResponseBuffering>false</EnableResponseBuffering>
<QueryCRS>urn:ogc:def:crs:EPSG::28992</QueryCRS>
<QueryMaxFeatures>-1</QueryMaxFeatures>
</deegreeWFS>
10. Click on Save and [Reload] to activate changes.
To Do: Edit global configuration and metadata
6
Create a new WMS
6.1 Create the WMS configuration file
1. In the console click on web services → services.
2. Enter a name for the new WMS. In this case “how-to-wms”. Choose type “WMS” and click Create
new.
Note: now you enter the editing mode of the deegree console. Use `Turn on highlighting` (under
editing window) to improve the readability of the XML code. You see a template with example
configuration, which you can adjust.
3. Add <SupportedVersions> “Version 1.3.0 “ and “Version 1.1.1”
Note: add version 1.1.1, to be able to use the “see layers” option in the console, which is based on
OpenLayers.
4. Set <MaxFeatures> to “0” so that the number of rendered features is unlimited
5. Introduce a <wms:ThemeId>. In this case `how-to-themes`. The actual layer configuration will be
done step 6.3.
6. The configuration looks like:
EXAMPLE: how-to-wms.xml
<wms:deegreeWMS
xmlns:wms="http://www.deegree.org/services/wms"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:dgws="http://www.deegree.org/webservices"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
configVersion="3.2.0"
xsi:schemaLocation="http://www.deegree.org/services/wms
http://schemas.deegree.org/services/wms/3.2.0/wms_configuration.xsd">
<wms:SupportedVersions>
<wms:Version>1.1.1</wms:Version>
<wms:Version>1.3.0</wms:Version>
</wms:SupportedVersions>
<wms:ServiceConfiguration>
<wms:DefaultLayerOptions>
<wms:MaxFeatures>0</wms:MaxFeatures>
</wms:DefaultLayerOptions>
<wms:ThemeId>how-to-themes</wms:ThemeId>
</wms:ServiceConfiguration>
</wms:deegreeWMS>
7. Click on save and [Reload] to activate changes.
To Do: Edit global configuration and metadata
6.2 Create a new layer store
1. In the console, click on map layers → layers . Enter a name and choose the type “ Feature” . In this
case “how-to-layers”. Click Create new. The template configurations opens.
2. Set the right <FeatureStoreId>. In this case “protectedSite”.
3. We will omit the <Filter> element.
4. Enter a name at the <l:Name> element. In this case “ps.ProtectedSite”.
5. Enter a title at <d:Title>. In this case “ Beschermde Gebieden”.
6. We use a simple configuration, in which we will make use of default styling, by omitting the
<l:StyleRef> element.
7. The configuration looks like:
EXAMPLE how-to-layers.xml
<FeatureLayers xmlns="http://www.deegree.org/layers/feature"
xmlns:ogc='http://www.opengis.net/ogc'
xmlns:ps="urn:x-inspire:specification:gmlas:ProtectedSites:3.0"
xmlns:d="http://www.deegree.org/metadata/description"
xmlns:l="http://www.deegree.org/layers/base"
xmlns:s="http://www.deegree.org/metadata/spatial"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.deegree.org/layers/feature
http://schemas.deegree.org/layers/feature/3.2.0/feature.xsd"
configVersion="3.2.0">
<FeatureStoreId>protectedSite</FeatureStoreId>
<FeatureLayer>
<l:Name>PS.ProtectedSite</l:Name>
<d:Title>Beschermde gebieden</d:Title>
</FeatureLayer>
</FeatureLayers>
8. Click on save and [Reload] to activate changes.
6.3 Create a new Theme
1.
2.
3.
4.
In the console, click on map layers → themes.
Enter a name (In this case “how-to-themes”), choose “Standard” and click Create new.
Set the right <LayerStoreId>. In this case: “how-to-layers” as chosen in step 6.2.
We will configure one theme layer. This has to be nested however in a base theme.Set the
<Identifier>. In this case “ Base”
5. Choose a title <d:Title>: “Beschermde gebieden”.
6. Set the <s:CRS> In this case local CRS for the Netherlands ( EPSG:28992)
7. Add <Theme> with <Identifier>, <d:Title> and <Layer>. The configuration looks in this case like:
EXAMPLE: inspire-how-to-themes.xml
<Themes xmlns="http://www.deegree.org/themes/standard"
xmlns:d="http://www.deegree.org/metadata/description"
xmlns:s="http://www.deegree.org/metadata/spatial"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
configVersion="3.2.0"
xsi:schemaLocation="http://www.deegree.org/themes/standard
http://schemas.deegree.org/themes/3.2.0/themes.xsd">
<LayerStoreId>how-to-layers</LayerStoreId>
<Theme>
<Identifier>Base</Identifier>
<d:Title>Beschermde gebieden</d:Title>
<s:CRS>EPSG:28992</s:CRS>
<Theme>
<Identifier>PS.ProtectedSite</Identifier>
<d:Title>Beschermde gebieden</d:Title>
<Layer>PS.ProtectedSite</Layer>
</Theme>
</Theme>
</Themes>
Additional Remarks
•
•
In the directory datasources (see deegree directory of your workspace on your local system) their
may be a file boundingbox cache. Due to earlier configuration errors, this cache may contain wrong
values. Stop TomCat, delete this file and restart TomCat.