[FrontPage] [TitleIndex] [WordIndex

How to set up deegree WMS with OpenStreetMap data

This page describes the possibility of using geodata from the OpenStreetMap project with the deegree Web Map Service and iGeoPortal. A complete example portal is presented on testing.deegree.org by clicking on OpenStreetMapNRW.

1. Getting the Data from OpenStreetMap

The data can be downloaded from OpenStreetMap via the export-tab (you will receive the complete data from the chosen bounding box). The download of specific data is possible with the OpenStreetMap XAPI. There are complete planet.osm files for free download at the Geofabrik for several regions of the earth. You have to look for saving the data in OSM-xml-format '*.osm'.

2. Putting the data into the Database

First of all, you need the tool osm2pgsql. Look for the link, there are mirrors and an installation guide for this little tool. Of course you need a postgreSQL database with PostGIS extension. Please click on the links for more information and how to configure your database.

After installing osm2pgsql and configuring the database, the next step is to execute osm2pgsql via console. In the following line, there is an example command to do this:

To understand this line, please use the osm2pgsql help by typing -h into the command line while calling osm2pgsql by it.

This would be the easiest way to get OSM data into a spatial database. An advanced way to geht the data , is to use the slim mode of osm2pgsql. With that you are able to put OSM relations into your database and additional columns with the OSM tags that you want. Therefore you've just got to edit the default.style in the root directory of osm2pgsql. For the layers hikingway and cycleway from the deegree WMS example layers it is required, to activate the corresponding entries in the default.style.

After converting the data into the database, you'll get several database relations. For our intention, the relations _line, _point, _polygon, _roads and, if you used slim mode _relation (for layers hikingway and cycleway), are relevant.

Now your OSM data is organized in a spatial database. You can divide the database relations and reduce the number of attributes of the new relations. This works with the following SQL script:

3. Configure deegree WMS

After setting up the database with the data, the deegree web map service has to be configured. Next to the installation of the wms, you have to define feature types. This happens based on the database relations. In our example it is necessary to define the feature type 'motorway', which owns all attributes of the mentioned database relation. Note: For the default example layers in deegree WMS it is not needed to define featuretype definitions, because the layers make use of database-based datasources. Afterwards there must be a layer definition in the wms_configuration.xml. For our motorway this could look like the following:

<Layer queryable="1" noSubsets="0" fixedWidth="0" fixedHeight="0">
  <Name>motorways</Name>
  <Title>motorways</Title>
  <Abstract>deegree demo WMS</Abstract>
  <KeywordList>
    <Keyword>deegree</Keyword>
    <Keyword>layer</wms:Keyword>
  </KeywordList>
  <deegree:DataSource failOnException="0" queryable="1">
    <deegree:Name>app:Autobahnen</deegree:Name>
    <deegree:GeometryProperty>app:way</deegree:GeometryProperty>
  </deegree:DataSource>
</Layer>

For the database-based default example layers in the deegree WMS, the DataSource part differs from this example.

Considerable is, to type the right geometry property and the right name of the feature type in the DataSource part. There are additional parameters for the configuration of the layer, for example scalehints and bounding boxes. Please refer to the deegree2.3rc1 WMS documentation for details.

Now testing of the WMS is possible.

4. Configure a Style

deegree WMS knows a default style. But to design our WMS more interesting, it is necessary to configure a special style for our motorway layer. There are two possibilities to create the style for our layer. Let's start with the easy way.

You can use one of the style.xml files in the WEB-INF/conf/wms/styles directory of your deegree WMS. Simply add a UserStyle like the following and your motorway layer should work with a black line.

<sld:UserStyle>
 <sld:Name>default:motorway</sld:Name>
 <sld:Title>motorway</sld:Title>
 <sld:IsDefault>1</sld:IsDefault>
 <sld:FeatureTypeStyle>
  <sld:Name>motorway</sld:Name>
  <sld:Rule>
   <sld:Name>motorway</sld:Name>
    <sld:LineSymbolizer>
     <sld:Geometry>
      <ogc:PropertyName>app:way</ogc:PropertyName>
     </sld:Geometry>
     <sld:Stroke>
      <sld:CssParameter name="stroke">#000000</sld:CssParameter>
      <sld:CssParameter name="stroke-opacity">1.0</sld:CssParameter>
      <sld:CssParameter name="stroke-width">1.5</sld:CssParameter>
     </sld:Stroke>
    </sld:LineSymbolizer>
  </sld:Rule>
 </sld:FeatureTypeStyle>
</sld:UserStyle>

Surely there are many additional options to configure the style. For our little example these are less important.

NOTE: Because the deegree WMS exapmple layers use database-based datasources, the deegree namespace of the style files has not to be "app", it has to be "DATABASE".

The advanced style for our motorway layer would be, that there is an outline for our motorways. First you need 2 userstyles. One for the outline, which is just a thick line, lying under the other line, which is the inline.

<sld:UserStyle>
 <sld:Name>default:motorway1</sld:Name>
 <sld:Title>motorway2</sld:Title>
 <sld:IsDefault>1</sld:IsDefault>
 <sld:FeatureTypeStyle>
  <sld:Name>motorway2</sld:Name>
  <sld:Rule>
   <sld:Name>motorway2</sld:Name>
   <sld:LineSymbolizer>
    <sld:Geometry>
     <ogc:PropertyName>app:way</ogc:PropertyName>
    </sld:Geometry>
    <sld:Stroke>
     <sld:CssParameter name="stroke">#000000</sld:CssParameter>
     <sld:CssParameter name="stroke-opacity">1.0</sld:CssParameter>
     <sld:CssParameter name="stroke-width">1.5</sld:CssParameter>
    </sld:Stroke>
   </sld:LineSymbolizer>
  </sld:Rule>
 </sld:FeatureTypeStyle>
</sld:UserStyle>

<sld:UserStyle>
 <sld:Name>default:motorway2</sld:Name>
 <sld:Title>motorway2</sld:Title>
 <sld:IsDefault>1</sld:IsDefault>
 <sld:FeatureTypeStyle>
  <sld:Name>motorway2</sld:Name>
  <sld:Rule>
   <sld:Name>motorway2</sld:Name>
   <sld:LineSymbolizer>
    <sld:Geometry>
     <ogc:PropertyName>app:way</ogc:PropertyName>
    </sld:Geometry>
    <sld:Stroke>
     <sld:CssParameter name="stroke">#ffffff</sld:CssParameter>
     <sld:CssParameter name="stroke-opacity">1.0</sld:CssParameter>
     <sld:CssParameter name="stroke-width">1.5</sld:CssParameter>
    </sld:Stroke>
   </sld:LineSymbolizer>
  </sld:Rule>
 </sld:FeatureTypeStyle>
</sld:UserStyle>

This style definition will create the motorways as white lines with black outlines.

But only with the style definitions this won't work.

You have to create a layerset with 2 sublayer, which call a seperate style. This could be look like the following example:

<Layer queryable="1" noSubsets="0" fixedWidth="0" fixedHeight="0">
 <Name>motorway</Name>
 <Title>motorway</Title>
 <Abstract>deegree demo WMS</Abstract>
 <KeywordList>
  <Keyword>deegree</Keyword>
  <Keyword>layer</Keyword>
 </KeywordList>
 <MinScaleDenominator>0</MinScaleDenominator>
 <MaxScaleDenominator>10000000</MaxScaleDenominator>
  <Layer queryable="1" noSubsets="0" fixedWidth="0" fixedHeight="0">
   <Name>motorway1</Name>
   <Title>motorway1</Title>
   <Abstract>deegree demo WMS</Abstract>
   <KeywordList>
    <Keyword>deegree</Keyword>
    <Keyword>layer</Keyword>
   </KeywordList>
   <deegree:DataSource failOnException="0" queryable="1">
    <deegree:Name>app:Autobahnen</deegree:Name>
    <deegree:GeometryProperty>app:way</deegree:GeometryProperty>
   </deegree:DataSource>
   <Style>
    <Name>default:motorway1</Name>
    <Title>motorway1</Title>
    <deegree:StyleResource>style.xml</deegree:StyleResource>
   </Style>
  </Layer>
  <Layer queryable="1" noSubsets="0" fixedWidth="0" fixedHeight="0">
   <Name>motorway2</Name>
   <Title>motorway2</Title>
   <Abstract>deegree demo WMS</Abstract>
   <KeywordList>
    <Keyword>deegree</Keyword>
    <Keyword>layer</Keyword>
   </KeywordList>
   <deegree:DataSource failOnException="0" queryable="1">
    <deegree:Name>app:Autobahnen</deegree:Name>
    <deegree:GeometryProperty>app:way</deegree:GeometryProperty>
   </deegree:DataSource>
   <Style>
    <Name>default:motorway2</Name>
    <Title>motorway2</Title>
    <deegree:StyleResource>style.xml</deegree:StyleResource>
   </Style>
  </Layer>
</Layer>

5. Configure deegree iGeoPortal

The WMS wouldn't be comfortable enough for the most people. For that, you can set up deegree iGeoPortal. This is a web client for the deegree WMS. After installing iGeoPortal, you have to define a web map context. You can use the example files to look how it works. Anyhow you have to add the following layer definition into the layerpart of a wmc.xml (For the deegree WMS OSM example layers there is a predefined Web Map Context named wmc_osm.xml):

<Layer queryable="1" hidden="1">
  <Server service="OGC:WMS" version="1.1.1" title="deegree Demo WMS">
    <OnlineResource xlink:type="simple" xlink:href="http://localhost:8080/deegree-osm-wms/services?" />
  </Server>
  <Name>motorway</Name>
  <Title>motorway</Title>
  <SRS>EPSG:4326</SRS>
  <FormatList>
    <Format current="1">image/jpeg</Format>
  </FormatList>
  <StyleList>
    <Style current="1">
      <Name>default</Name>
      <Title>default</Title>
    </Style>
  </StyleList>
  <Extension xmlns:deegree="http://www.deegree.org/context">
    <deegree:MasterLayer>false</deegree:MasterLayer>
  </Extension>
</Layer>

Now the motorways layer is available in the portal application. Of Course you can do further configuration at the iGeoPortal files.


CategoryHowTo CategoryDeegree2


2018-04-20 12:04