[FrontPage] [TitleIndex] [WordIndex

How to work with GML in deegree 3

Collection of code snippets for working with the GML subsystem of deegree 3.

NOTE: This is subject to change as the GML API has not been stabilized yet.

1. Load a GML FeatureCollection

When loading a feature collection, the feature type information (ApplicationSchema) must be known, so deegree knows which feature types exist and which properties they allow for. The feature type information can be derived automatically from the xsi:schemaLocation attribute of the document's root element (implicitly, the application schema is loaded and analyzed) or provide the schema manually. The latter variant is especially useful if the document does not contain a valid xsi:schemaLocation reference to a GML application schema or you want to load multiple instance documents that use the same feature types (as loading and analyzing of the schema may be expensive).

1.1. Automatic feature type analysis

import java.net.URL;

import org.deegree.feature.FeatureCollection;
import org.deegree.gml.GMLInputFactory;
import org.deegree.gml.GMLStreamReader;
import org.deegree.gml.GMLVersion;

public class LoadGML {

    public static FeatureCollection readFC() throws Exception {
        URL url = new URL ("http://demo.deegree.org/deegree-wfs/services?service=WFS&version=1.1.0&request=GetFeature&typename=app:Place&namespace=xmlns%28app=http://www.deegree.org/app%29&outputformat=text%2Fxml%3B+subtype%3Dgml%2F3.1.1");
        GMLStreamReader gmlStreamReader = GMLInputFactory.createGMLStreamReader( GMLVersion.GML_31, url );
        FeatureCollection fc = gmlStreamReader.readFeatureCollection();
        return fc;
    }

    public static void main( String[] args ) throws Exception {
        FeatureCollection fc = readFC();
        // now you can work with the feature collection, e.g. access the members
        System.out.println (fc.size());
    }
}

1.2. Specifying the schema manually

import java.net.URL;

import org.deegree.feature.FeatureCollection;
import org.deegree.feature.types.ApplicationSchema;
import org.deegree.gml.GMLInputFactory;
import org.deegree.gml.GMLStreamReader;
import org.deegree.gml.GMLVersion;
import org.deegree.gml.feature.schema.ApplicationSchemaXSDDecoder;

public class LoadGML {

    public static ApplicationSchema readSchema() throws Exception {
        String schemaURL = "http://demo.deegree.org/deegree-wfs/services?SERVICE=WFS&VERSION=1.1.0&REQUEST=DescribeFeatureType&TYPENAME=app:Place&NAMESPACE=xmlns(app=http://www.deegree.org/app)";
        String wfsSchemaURL = "http://schemas.opengis.net/wfs/1.1.0/wfs.xsd";
        ApplicationSchemaXSDDecoder decoder = new ApplicationSchemaXSDDecoder( GMLVersion.GML_31, null, schemaURL, wfsSchemaURL );
        return decoder.extractFeatureTypeSchema();
    }

    public static FeatureCollection readFC() throws Exception {
        URL url = new URL ("http://demo.deegree.org/deegree-wfs/services?service=WFS&version=1.1.0&request=GetFeature&typename=app:Place&namespace=xmlns%28app=http://www.deegree.org/app%29&outputformat=text%2Fxml%3B+subtype%3Dgml%2F3.1.1");
        GMLStreamReader gmlStreamReader = GMLInputFactory.createGMLStreamReader( GMLVersion.GML_31, url );
        gmlStreamReader.setApplicationSchema( readSchema() );
        FeatureCollection fc = gmlStreamReader.readFeatureCollection();
        return fc;
    }

    public static void main( String[] args ) throws Exception {
        FeatureCollection fc = readFC();
        // now you can work with the feature collection, e.g. access the members
        System.out.println (fc.size());
    }
}


CategoryDeegree3 CategoryHowTo


2018-04-20 12:05