📄 capabilities.cs
字号:
// Copyright 2005, 2006 - Morten Nielsen (www.iter.dk)
//
// This file is part of SharpMap.
// SharpMap is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SharpMap is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public License
// along with SharpMap; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace SharpMap.Web.Wms
{
/// <summary>
/// Class for generating the WmsCapabilities Xml
/// </summary>
public class Capabilities
{
/// <summary>
/// The Wms Service Description stores metadata parameters for a WMS service
/// </summary>
public struct WmsServiceDescription
{
/// <summary>
/// Initializes a WmsServiceDescription object
/// </summary>
/// <param name="title">Mandatory Human-readable title for pick lists</param>
/// <param name="onlineResource">Top-level web address of service or service provider.</param>
public WmsServiceDescription(string title, string onlineResource)
{
Title = title;
OnlineResource = onlineResource;
Keywords = null;
Abstract = "";
ContactInformation = new WmsContactInformation();
Fees = "";
AccessConstraints = "";
LayerLimit = 0;
MaxWidth = 0;
MaxHeight = 0;
}
/// <summary>
/// Mandatory Human-readable title for pick lists
/// </summary>
public string Title;
/// <summary>
/// Optional narrative description providing additional information
/// </summary>
public string Abstract;
/// <summary>
/// Optional list of keywords or keyword phrases describing the server as a whole to help catalog searching
/// </summary>
public string[] Keywords;
/// <summary>
/// Mandatory Top-level web address of service or service provider.
/// </summary>
public string OnlineResource;
/// <summary>
/// Optional WMS contact information
/// </summary>
public WmsContactInformation ContactInformation;
/// <summary>
/// The optional element "Fees" may be omitted if it do not apply to the server. If
/// the element is present, the reserved word "none" (case-insensitive) shall be used if there are no
/// fees, as follows: "none".
/// </summary>
public string Fees;
/// <summary>
/// <para>The optional element "AccessConstraints" may be omitted if it do not apply to the server. If
/// the element is present, the reserved word "none" (case-insensitive) shall be used if there are no
/// access constraints, as follows: "none".</para>
/// <para>When constraints are imposed, no precise syntax has been defined for the text content of these elements, but
/// client applications may display the content for user information and action.</para>
/// </summary>
public string AccessConstraints;
/// <summary>
/// Maximum number of layers allowed (0=no restrictions)
/// </summary>
public uint LayerLimit;
/// <summary>
/// Maximum width allowed in pixels (0=no restrictions)
/// </summary>
public uint MaxWidth;
/// <summary>
/// Maximum height allowed in pixels (0=no restrictions)
/// </summary>
public uint MaxHeight;
}
/// <summary>
/// Stores contact metadata about WMS service
/// </summary>
public struct WmsContactInformation
{
/// <summary>
/// Primary contact person
/// </summary>
public ContactPerson PersonPrimary;
/// <summary>
/// Position of contact person
/// </summary>
public string Position;
/// <summary>
/// Address
/// </summary>
public ContactAddress Address;
/// <summary>
/// Telephone
/// </summary>
public string VoiceTelephone;
/// <summary>
/// Fax number
/// </summary>
public string FacsimileTelephone;
/// <summary>
/// Email address
/// </summary>
public string ElectronicMailAddress;
/// <summary>
/// Information about a contact person for the service.
/// </summary>
public struct ContactPerson
{
/// <summary>
/// Primary contact person
/// </summary>
public string Person;
/// <summary>
/// Organisation of primary person
/// </summary>
public string Organisation;
}
/// <summary>
/// Information about a contact address for the service.
/// </summary>
public struct ContactAddress
{
/// <summary>
/// Type of address (usually "postal").
/// </summary>
public string AddressType;
/// <summary>
/// Contact address
/// </summary>
public string Address;
/// <summary>
/// Contact City
/// </summary>
public string City;
/// <summary>
/// State or province of contact
/// </summary>
public string StateOrProvince;
/// <summary>
/// Zipcode of contact
/// </summary>
public string PostCode;
/// <summary>
/// Country of contact address
/// </summary>
public string Country;
}
}
private const string wmsNamespaceURI = "http://www.opengis.net/wms";
private const string xlinkNamespaceURI = "http://www.w3.org/1999/xlink";
/// <summary>
/// Generates a capabilities file from a map object for use in WMS services
/// </summary>
/// <remarks>The capabilities document uses the v1.3.0 OpenGIS WMS specification</remarks>
/// <param name="map">The map to create capabilities for</param>
/// <param name="serviceDescription">Additional description of WMS</param>
/// <returns>Returns XmlDocument describing capabilities</returns>
public static XmlDocument GetCapabilities(SharpMap.Map map, WmsServiceDescription serviceDescription)
{
XmlDocument capabilities = new XmlDocument();
//Set XMLSchema
//capabilities.Schemas.Add(GetCapabilitiesSchema());
//Instantiate an XmlNamespaceManager object.
//System.Xml.XmlNamespaceManager xmlnsManager = new System.Xml.XmlNamespaceManager(capabilities.NameTable);
//xmlnsManager.AddNamespace(xlinkNamespaceURI, "urn:Books");
//Insert XML tag
capabilities.InsertBefore(capabilities.CreateXmlDeclaration("1.0", "UTF-8", string.Empty), capabilities.DocumentElement);
capabilities.AppendChild(capabilities.CreateComment("Capabilities generated by SharpMap v. " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()));
//Create root node
XmlNode RootNode = capabilities.CreateNode(XmlNodeType.Element, "WMS_Capabilities", wmsNamespaceURI);
RootNode.Attributes.Append(CreateAttribute("version", "1.3.0", capabilities));
XmlAttribute attr = capabilities.CreateAttribute("xmlns", "xsi", "http://www.w3.org/2000/xmlns/");
attr.InnerText = "http://www.w3.org/2001/XMLSchema-instance";
RootNode.Attributes.Append(attr);
RootNode.Attributes.Append(CreateAttribute("xmlns:xlink", xlinkNamespaceURI, capabilities));
XmlAttribute attr2 = capabilities.CreateAttribute("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance");
attr2.InnerText = "http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd";
RootNode.Attributes.Append(attr2);
//Build Service node
RootNode.AppendChild(GenerateServiceNode(ref serviceDescription, capabilities));
//Build Capability node
RootNode.AppendChild(GenerateCapabilityNode(map, capabilities));
capabilities.AppendChild(RootNode);
//TODO: Validate output against schema
return capabilities;
}
private static XmlNode GenerateServiceNode(ref WmsServiceDescription serviceDescription, XmlDocument capabilities)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -