Skip to main content
  1. Projects/

Software Development: Web Feature Service Connector

358 words·2 mins·
Adian Dawuda
Master’s student in Applied Geoinformatics focused on earth observation and spatial data science

The following showcases a Java program that retrieves and parses features from a Web Feature Service (WFS) using GeoTools. The chosen data source is the city of Vienna’s WFS for open data.

The first step is to create a WFSDataStoreFactory object. This factory is used to create a WFSDataStore object, which is the main class used to interact with the WFS service. In order to create the WFSDataStore object, a HashMap with the connection parameters is needed. These parameters are then passed to the createDataStore method of the WFSDataStoreFactory object. With a working WFSDataStore object, it is possible to retrieve and print all of the feature type names that are available from the WFS service.

Next all of the public transport stops for the bus line 99A (an arbitrary example) are to be selected. To do this the features of type ogdwien:OEFFHALTESTOGD are retrieved and parsed. The features are represented as SimpleFeature objects, which contain properties such as HLINIEN (bus line)and HTXTK (stop name).

The code can be found below:

import java.util.HashMap;

import org.opengis.feature.Feature;

public class WFSConnector {

    public static void main(String[] args)
        // define the getCapabilities request
        String wfsGetCapabilitiesURL = "";

        // create WFSDataStoreFactory object
        WFSDataStoreFactory wfsDSF = new WFSDataStoreFactory();

        // create HashMap and fill it with connection parameters
        HashMap connectionParameters = new HashMap();
        connectionParameters.put(WFSDataStoreFactory.URL.key, wfsGetCapabilitiesURL);
        connectionParameters.put(WFSDataStoreFactory.TIMEOUT.key, 10000);
        connectionParameters.put(WFSDataStoreFactory.ENCODING.key, "UTF-8");

        // create a DataStore object
        try {

            WFSDataStore wfsDS = wfsDSF.createDataStore(connectionParameters);

            String[] typeNames = wfsDS.getTypeNames();

            for(int i=0; i<typeNames.length; i++)
                System.out.println("typeName[" + i + "]:" + typeNames[i]);

            String typeName = "ogdwien:OEFFHALTESTOGD";

            // retrieve the features from the service
            SimpleFeatureSource featureSource = wfsDS.getFeatureSource(typeName);

            // parse the result/features
            SimpleFeatureCollection featureCollection = featureSource.getFeatures();

            SimpleFeatureIterator featureIterator = featureCollection.features();

                // print the features to the screen
                Feature currentFeature =;


                // for type name ogdwien:OEFFHALTESTOGD
                String line = currentFeature.getProperty("HLINIEN").getValue().toString();
                String stop = currentFeature.getProperty("HTXTK").getValue().toString();

                // print stops of desired line
                if (line.equals("99A"))
                    System.out.println(line + ": " + stop);
        } catch (IOException e) {