Pitney Bowes MapXtreme User Manual

Page 403

Advertising
background image

Chapter 22: Web Feature Service

Creating a Map Layer from a WFS Response

MapXtreme v7.1

410

Developer Guide

Parsing the WFS Response

Parsing the response is not specified in the WFS specification, nor does the specification describe
an exact format for the results of a GetFeature request. The WFS specification only states that the
request must be at least GML2. Since there are many versions of GML2, and in order for the
MapXtreme WFS client to be able to correctly convert the GML2 response from a WFS Server, you
must create a parser to convert the GML2 GetFeature response to a MapXtreme
MapInfo.Data.MultiFeatureCollection. This is done by implementing the IWfsReader interface and
registering that implementation with the MapInfo.Wfs.Client.WfsReaderFactory class. Registration
must occur on a per URL basis, that is, if you want to interact with two WFS Servers that have the
same GetFeature response, the specific IWfsReader implementation must be registered twice for
each server URL. You do not need to implement the entire interface. The
MapInfo.Wfs.Client.WfsReader class may be extended to override the
ReadGetFeature(XmlReader) method. Any of the other methods may be overridden when
interacting with a non-compliant WFS Server.

The following code example illustrates the complete process from requesting features to creating a
map layer and displaying the features in a map. The code for this example is contained in the
WfsClient sample application located in the \Samples folder under your MapXtreme installation.

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Xml.Schema;

using MapInfo.Data;
using MapInfo.Engine;
using MapInfo.Mapping;
using MapInfo.Wfs.Client;

namespace MapInfo.Wfs.Client.Samples {

/// <summary>
/// Simple sample to demonstrate how to register a WfsReader to handle
/// requests from a specific Wfs server, get the capabilities of the

server,

/// get the schema for a feature type located on the server and getting

all

/// of the features from the server.
/// </summary>
class SimpleSample {

private const string URL = "http://www.mapinfo.com/miwfs";

private const string defaultExportFileName = "WfsClient.gif";

[STAThread]
static void Main(string[] args) {

string exportFileName = defaultExportFileName;
if (args.Length > 0 && args[0] != null && args[0].Trim().Length
!= 0) exportFileName = args[0];

Advertising