WFS 2.0 XML Data Binding  - Nuget packge LiquidTechnologies.XmlObjects.WFS2-0 WFS 2.0 XML Data Binding - Nuget packge LiquidTechnologies.XmlObjects.WFS2-0

Home > XML Data Binding Nuget Packages > WFS 2.0

 

OGC Web Feature Service

The OpenGIS Web Feature Service Interface Standard (WFS) defines an interface for specifying requests for retrieving geographic features across the Web using platform-independent calls. The WFS standard defines interfaces and operations for data access and manipulation on a set of geographic features.

NuGet Package ID LiquidTechnologies.XmlObjects.WFS2-0
Description An object model for the WFS 2.0 standard providing strongly typed classes that can be serialized/deserializsed to XML.
Documentation Liquid XML Objects API
Schema Documentation https://schemas.liquid-technologies.com/WFS/2.0/
Official Schema Site http://www.opengeospatial.org/standards/wfs
License EULA
Supported Platforms
  • .Net Standard 2.0 and above
  • .Net Core 2.0 and above
  • .Net Framework 4.0 and above

The following code shows how to create an XML document using the WFS nuget.

First the object is constructed and populated, then the LxSerializer is used to convert the object representation into XML.

using System;
using System.Numerics;
using System.IO;
using System.Text;
using LiquidTechnologies.XmlObjects;
using LiquidTechnologies.XmlObjects.WFS20;
using System.Xml.Linq;
using LiquidTechnologies.XmlObjects;

namespace LiquidTechnologies.Samples
{
    public class XmlGeneratorSample
    {
        public static string CreateXml()
        {
            #region Writing
            var createStoredQueryElm = new Wfs.CreateStoredQueryElm();
            var storedQueryDefinitions = new Wfs.StoredQueryDescriptionTypeCt();
            {
                storedQueryDefinitions.Id = "urn:StoredQueries:FeaturesInPolygon";
                var titles = new Wfs.TitleElm();
                {
                    titles.Value = "Features In Polygon";
                    storedQueryDefinitions.Titles.Add(titles);
                }
                var abstracts = new Wfs.Abstract_Elm();
                {
                    abstracts.Value = "Find all the features in a Polygon.";
                    storedQueryDefinitions.Abstracts.Add(abstracts);
                }
                var parameters = new Wfs.ParameterExpressionTypeCt();
                {
                    parameters.Name = "AreaOfInterest";
                    parameters.Type = "gml:Polygon";
                    storedQueryDefinitions.Parameters.Add(parameters);
                }
                var queryExpressionTexts = new Wfs.QueryExpressionTextTypeCt();
                {
                    queryExpressionTexts.Add(new XAttribute("returnFeatureTypes", "myns:Parks myns:Lakes myns:Rivers"));
                    queryExpressionTexts.Add(new XAttribute("language", "urn:ogc:def:queryLanguage:OGC-WFS::WFS_QueryExpression"));
                    queryExpressionTexts.Add(new XAttribute("isPrivate", "false"));
                    queryExpressionTexts.Add(new XText("\n         "));
                    queryExpressionTexts.Add(new XElement("{http://www.opengis.net/wfs/2.0}Query",
                        new XAttribute("typeNames", "myns:Parks"),
                        new XText("\n            "),
                        new XElement("{http://www.opengis.org/fes/2.0}Filter",
                            new XText("\n               "),
                            new XElement("{http://www.opengis.org/fes/2.0}Within",
                                new XText("\n                  "),
                                new XElement("{http://www.opengis.org/fes/2.0}ValueReference", "geometry"),
                                new XText("\n                  ${AreaOfInterest}\n               ")),
                            new XText("\n            ")),
                        new XText("\n         ")));
                    queryExpressionTexts.Add(new XText("\n         "));
                    queryExpressionTexts.Add(new XElement("{http://www.opengis.net/wfs/2.0}Query",
                        new XAttribute("typeNames", "myns:Lakes"),
                        new XText("\n            "),
                        new XElement("{http://www.opengis.org/fes/2.0}Filter",
                            new XText("\n               "),
                            new XElement("{http://www.opengis.org/fes/2.0}Within",
                                new XText("\n                  "),
                                new XElement("{http://www.opengis.org/fes/2.0}ValueReference", "region"),
                                new XText("\n                  ${AreaOfInterest}\n               ")),
                            new XText("\n            ")),
                        new XText("\n         ")));
                    queryExpressionTexts.Add(new XText("\n         "));
                    queryExpressionTexts.Add(new XElement("{http://www.opengis.net/wfs/2.0}Query",
                        new XAttribute("typeNames", "myns:Rivers"),
                        new XText("\n            "),
                        new XElement("{http://www.opengis.org/fes/2.0}Filter",
                            new XText("\n               "),
                            new XElement("{http://www.opengis.org/fes/2.0}Within",
                                new XText("\n                  "),
                                new XElement("{http://www.opengis.org/fes/2.0}ValueReference", "region"),
                                new XText("\n                  ${AreaOfInterest}\n               ")),
                            new XText("\n            ")),
                        new XText("\n         ")));
                    queryExpressionTexts.Add(new XText("\n      "));
                    storedQueryDefinitions.QueryExpressionTexts.Add(queryExpressionTexts);
                }
                createStoredQueryElm.StoredQueryDefinitions.Add(storedQueryDefinitions);
            }
            createStoredQueryElm.Service = "WFS";
            createStoredQueryElm.Version = "2.0.2";


            var serializer = new LxSerializer<Wfs.CreateStoredQueryElm>();
            using (StringWriter writer = new StringWriter())
            {
                serializer.Serialize(writer, createStoredQueryElm);
                return writer.ToString();
            }
            #endregion
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<wfs:CreateStoredQuery xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:fes="http://www.opengis.org/fes/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:myns="http://www.someserver.example.com/myns" xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd" service="WFS" version="2.0.2">
   <wfs:StoredQueryDefinition id="urn:StoredQueries:FeaturesInPolygon">
      <wfs:Title>Features In Polygon</wfs:Title>
      <wfs:Abstract>Find all the features in a Polygon.</wfs:Abstract>
      <wfs:Parameter name="AreaOfInterest" type="gml:Polygon"/>
      <wfs:QueryExpressionText returnFeatureTypes="myns:Parks myns:Lakes myns:Rivers" language="urn:ogc:def:queryLanguage:OGC-WFS::WFS_QueryExpression" isPrivate="false">
         <wfs:Query typeNames="myns:Parks">
            <fes:Filter>
               <fes:Within>
                  <fes:ValueReference>geometry</fes:ValueReference>
                  ${AreaOfInterest}
               </fes:Within>
            </fes:Filter>
         </wfs:Query>
         <wfs:Query typeNames="myns:Lakes">
            <fes:Filter>
               <fes:Within>
                  <fes:ValueReference>region</fes:ValueReference>
                  ${AreaOfInterest}
               </fes:Within>
            </fes:Filter>
         </wfs:Query>
         <wfs:Query typeNames="myns:Rivers">
            <fes:Filter>
               <fes:Within>
                  <fes:ValueReference>region</fes:ValueReference>
                  ${AreaOfInterest}
               </fes:Within>
            </fes:Filter>
         </wfs:Query>
      </wfs:QueryExpressionText>
   </wfs:StoredQueryDefinition>
</wfs:CreateStoredQuery>

The following code shows how to create an XML document using the WFS nuget.

First the object is constructed and populated, then the LxSerializer is used to convert the object representation into XML.

using System;
using System.Numerics;
using System.IO;
using System.Text;
using LiquidTechnologies.XmlObjects;
using LiquidTechnologies.XmlObjects.WFS20;
using System.Xml.Linq;
using LiquidTechnologies.XmlObjects;

namespace LiquidTechnologies.Samples
{
    public class XmlGeneratorSample
    {
        public static string CreateXml()
        {
            #region Writing
            var getFeatureElm = new Wfs.GetFeatureElm();
            getFeatureElm.OutputFormat = "application/gml+xml; version=3.2";
            var abstractQueryExpressions = new Wfs.QueryElm();
            {
                abstractQueryExpressions.TypeNames = new NsA.TypeNamesTypeUnion[] { new NsA.TypeNamesTypeUnion("myns:InWaterA_1M")};
                {
                    var abstractSelectionClause = new Fes.FilterElm();
                    var ids = new Fes.ResourceIdElm();
                    {
                        ids.Rid = "InWaterA_1M.1234";
                        abstractSelectionClause.Ids.Add(ids);
                    }
                    abstractQueryExpressions.AbstractSelectionClause = abstractSelectionClause;
                }
                getFeatureElm.AbstractQueryExpressions.Add(abstractQueryExpressions);
            }
            getFeatureElm.Service = "WFS";
            getFeatureElm.Version = "2.0.2";


            var serializer = new LxSerializer<Wfs.GetFeatureElm>();
            using (StringWriter writer = new StringWriter())
            {
                serializer.Serialize(writer, getFeatureElm);
                return writer.ToString();
            }
            #endregion
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
This example fetches a specific instance of the feature type
InWaterA_1M identified by the feature identifier "InWaterA_1M.1234".
-->
<wfs:GetFeature service="WFS" version="2.0.2" outputFormat="application/gml+xml; version=3.2" xmlns:myns="http://www.someserver.example.com/myns" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd">
   <wfs:Query typeNames="myns:InWaterA_1M">
      <fes:Filter>
         <fes:ResourceId rid="InWaterA_1M.1234"/>
      </fes:Filter>
   </wfs:Query>
</wfs:GetFeature>

Video Tutorial

This video tutorial demonstrates the basic usage of the XML Objects tool, showing how to generate code from an XSD, read an XML document into the object model, modify the data and write out the XML.

Try Liquid Studio and see how we can help you today Free Trial