Geomajas Community Documentation

Geomajas end user guide

Geomajas Developers and Geosparc

v1.8.0-SNAPSHOT


1. Introduction
2. Configuration
2.1. GeoTools layer configuration
2.1.1. Configuring a Web Feature Service (WFS) layer
2.1.2. Configuring a database layer (PostGIS, Oracle Spatial, ...)
2.2. Shape in memory layer
2.3. Transaction configuration

This section handles possible configurations using the GeoTools layer. As GeoTools supports a whole range of data formats, not all of them will be covered here.

Apart from a reference to the layer info, you can set the following parameters:


In order to read data from a WFS, a GeoTools layer is required. Currently GeoTools has support for WFS 1.0 and 1.1, and support for WFS-T 1.0. As the GeoTools WFS plug-in is not by default part of the classpath, you must add it to the classpath manually. First things first, the XML configuration. There are 2 ways of configuring a WFS layer through the GeoTools layer. As Geomajas uses a GeoTools DataStore behind the screens, it is possible to configure this DataStore separately, and than attach it to the GeoTools layer. This would have the advantage of re-using the same GeoTools DataStore over multiple layers. Alternatively you can configure the required parameters directly within the Layer configuration.

In general, the following parameters can be configured:

  • WFSDataStoreFactory:GET_CAPABILITIES_URL : URL for the getCapabilities document on the server instance.

  • WFSDataStoreFactory:PROTOCOL : determine which HTTP command use when requesting WFS functionality. Set this value to "true" for POST, "false" for GET or NULL for AUTO.

  • WFSDataStoreFactory:USERNAME : set the user name which should be used to authenticate the connection. This parameter should not be used without the password parameter.

  • WFSDataStoreFactory:PASSWORD : set the password which should be used to authenticate the connection. This parameter should not be used without the user name parameter.

  • WFSDataStoreFactory:TIMEOUT : specify the connection timeout in milliseconds. This parameter has a default value of 3000ms.

  • WFSDataStoreFactory:BUFFER_SIZE : set the buffer size for the features. This parameter has a default value of 10 features.

  • WFSDataStoreFactory:TRY_GZIP : indicate whether the data store should use gzip compression to transfer data if the server supports it. Default is true.

  • WFSDataStoreFactory:LENIENT : indicate whether the data store should do its best to create features from the provided data even if it does not accurately match the schema. Errors will be logged but the parsing will continue if this is true. Default is false.

Note that most of the parameters above are optional. Only the capabilities url is required.

Configuring a WFS layer, with a separate DataStore:

<!-- GeoTools DataStore: connects to a WFS server -->
<bean name="
                        wfsDatastore
                     " class="org.geomajas.layer.geotools.DataStoreFactory" factory-method="create">
   <constructor-arg>
      <map>
         <entry key="WFSDataStoreFactory:GET_CAPABILITIES_URL"
            value="http://www.some-wfs.com/ows?service=WFS&amp;VERSION&#61;1.0.0&amp;request&#61;GetCapabilities" />
         <entry key="WFSDataStoreFactory.TIMEOUT" value="5000" />
      </map>
   </constructor-arg>
</bean>

<!-- Layer definition, that uses the WFS DataStore -->
<bean name="myWfsLayer" class="org.geomajas.layer.geotools.GeoToolsLayer">
   <property name="layerInfo" ref="someLayerInfo" />
   <property name="dataStore" ref="
                        wfsDatastore
                     " />
</bean>

Alternatively, the layer can be configured directly with the required parameters:

<bean name="anotherWfsLayer" class="org.geomajas.layer.geotools.GeoToolsLayer">
   <property name="parameters">
      <list>
         <bean class="org.geomajas.configuration.Parameter">
            <property name="name" value="WFSDataStoreFactory:GET_CAPABILITIES_URL" />
            <property name="value" value="aaaaaaa" />
         </bean>
         <bean class="org.geomajas.configuration.Parameter">
            <property name="name" value="WFSDataStoreFactory:TIMEOUT" />
            <property name="value" value="5000" />
         </bean>
      </list>
   </property>
   <property name="layerInfo" ref="blablaInfo" />
</bean> 

As said in the beginning of this section, the GeoTools WFS library needs to be added as a dependency in your project. When using Maven, you can add the following dependency:

<dependency>
  <groupId>org.geotools</groupId>
  <artifactId>gt-wfs</artifactId>
  <version>${geotools-version}</version>
</dependency>

Warning

The configurations in this section still need to be doublechecked! If you find errors, please post it on the forum.

Configuring a GeoTools layer that makes use of a PostGis database, is again a question of using the correct parameters. As with other examples of using a GeoTools layer, there is the choice of configuring the GetoTools DataStore separately or not. By configuring the DataStore separately, it can be used by multiple layers. In the case of a database, this method would almost always be preferable.

In general, the following parameters can be configured:

  • namespace : The namespace of the database (i.e. "postgis")

  • dbtype : The type of database: (i.e. "postgis")

  • database : The name of the database.

  • user : The user name to log in with.

  • passwd : The user's password.

  • host : The hostname or IP address of the machine where the database is located.

  • port : The port where the database runs (default for PostGIS is 5432).

Configuring a database layer, with a separate DataStore:

<!-- GeoTools DataStore: connects to a PostGIS database -->
<bean name="
                        postGisDatastore
                     " class="org.geomajas.layer.geotools.DataStoreFactory" factory-method="create">
   <constructor-arg>
      <map>
         <entry key="namespace" value="postgis" />
         <entry key="dbtype" value="postgis" />
         <entry key="database" value="some_database" />
         <entry key="user" value="some_user" />
         <entry key="passwd" value="some_password" />
         <entry key="host" value="localhost" />
         <entry key="port" value="5432" />
      </map>
   </constructor-arg>
</bean>

<!-- Layer definition, that uses the DataStore -->
<bean name="myPostGisLayer" class="org.geomajas.layer.geotools.GeoToolsLayer">
   <property name="layerInfo" ref="someLayerInfo" />
   <property name="dataStore" ref="
                        postGisDatastore
                     " />
</bean>

Alternatively one can configure the layer directly with the required parameters:

<bean name="myPostGisLayer" class="org.geomajas.layer.geotools.GeoToolsLayer">
   <property name="parameters">
      <list>
         <bean class="org.geomajas.configuration.Parameter">
            <property name="name" value="namespace" />
            <property name="value" value="postgis" />
         </bean>
         <bean class="org.geomajas.configuration.Parameter">
            <property name="name" value="dbtype" />
            <property name="value" value="postgis" />
         </bean>
         <bean class="org.geomajas.configuration.Parameter">
            <property name="name" value="database" />
            <property name="value" value="some_database" />
         </bean>
         <bean class="org.geomajas.configuration.Parameter">
            <property name="name" value="user" />
            <property name="value" value="some_user" />
         </bean>
         <bean class="org.geomajas.configuration.Parameter">
            <property name="name" value="passwd" />
            <property name="value" value="some_password" />
         </bean>
         <bean class="org.geomajas.configuration.Parameter">
            <property name="name" value="host" />
            <property name="value" value="localhost" />
         </bean>
         <bean class="org.geomajas.configuration.Parameter">
            <property name="name" value="port" />
            <property name="value" value="5432" />
         </bean>
      </list>
   </property>
   <property name="layerInfo" ref="blablaInfo" />
</bean> 

Don't forget to also add the necessary database driver libraries to your project. Here is an example that adds PostGIS drivers and GeoTools PostGIS plug-in to the pom.xml (when using Maven):

<dependency>
   <groupId>org.postgis</groupId>
   <artifactId>postgis-jdbc</artifactId>
   <version>1.1.6</version>
</dependency>
<dependency>
   <groupId>postgresql</groupId>
   <artifactId>postgresql</artifactId>
   <version>8.1-407.jdbc3</version>
</dependency>
<dependency>
   <groupId>org.geotools</groupId>
   <artifactId>gt-postgis</artifactId>
   <version>${geotools-version}</version>
</dependency>

Note

When configuring the general layer information (and attribute information), the value may differ, depending on the kind of database that you use. For example, column names in a PostGIS database all have lower cases, and so the Geomajas attribute configuration should reflect this. If you are using Oracle Spatial on the other hand all column names are uppercase, so your configuration should contain uppercases for the attribute names.