使用C# + httpWebRequest 解析WMTS服务元数据
解析http://219.142.81.86/igserver/ogc/kvp/TAS10R52000J49/WMTSServer服务的元数据
// 测试httpWebRequest读取 wmts元数据
string address = "http://219.142.81.86/igserver/ogc/kvp/TAS10R52000J49/WMTSServer";
var request = (HttpWebRequest)WebRequest.Create(address);
var response = (HttpWebResponse)request.GetResponse();
var stream = response.GetResponseStream();
if (stream == null) return;
var xmlReader = new XmlTextReader(stream);
var xmlDocument = new XmlDocument();
xmlDocument.Load(xmlReader);
string namespace_uri = xmlDocument.DocumentElement.NamespaceURI;
var nsmgr = new XmlNamespaceManager(xmlDocument.NameTable);
nsmgr.AddNamespace("wmts", namespace_uri);
XmlNode node = xmlDocument.SelectSingleNode("//wmts:Layer", nsmgr);
if (node == null) return;
string LowerCorner, UpperCorner;
// 得到layer节点的所有子节点
XmlNodeList xnl = node.ChildNodes;
double west = 0;
double east = 0;
double south = 0;
double north = 0;
foreach (XmlNode xn1 in xnl)
{
if (xn1.Name == "ows:BoundingBox" || xn1.Name == "ows:WGS84BoundingBox")
{
XmlElement xe = (XmlElement)xn1;
//得到crs属性
string crs = xe.GetAttribute("crs").ToString();
// 得到BoundBox节点的所有子节点
XmlNodeList xn10 = xn1.ChildNodes;
LowerCorner = xn10.Item(0).InnerText;
UpperCorner = xn10.Item(1).InnerText;
string[] cc = LowerCorner.Split(' ');
west = Convert.ToDouble(cc[0]);
south = Convert.ToDouble(cc[1]);
string[] uu = UpperCorner.Split(' ');
east = Convert.ToDouble(uu[0]);
north = Convert.ToDouble(uu[1]);
}
// 将节点转换为元素,便于得到节点的属性值
//XmlElement xe = (XmlElement)xn1;
// 得到Type和ISBN两个属性的属性值
//string type = xe.GetAttribute("ows:Type").ToString(); //<book Type="必修课" ISBN="7-111-19149-2">
}
XmlNodeList nodes = xmlDocument.SelectNodes("//wmts:TileMatrixSet", nsmgr);
if (nodes.Count <= 0) return;
Dictionary<int, _tileMatrix> tileMatrixSet = new Dictionary<int,_tileMatrix>();
int minLevel = 9999;
int maxLevel = -9999;
foreach (XmlNode xn1 in nodes)
{
if (xn1.ParentNode == null || xn1.ParentNode.Name != "Contents")
continue;
XmlNodeList xn11 = xn1.ChildNodes;
foreach (XmlNode xn110 in xn11)
{
if (xn110.Name == "TileMatrix")
{
XmlNodeList xn10 = xn110.ChildNodes;
string strlevel = xn10.Item(0).InnerText;
string[] temp = strlevel.Split(':');
int cn = temp.Count();
int level = 0;
if (cn == 1)
level = Convert.ToInt32(temp[0]);
else
level = Convert.ToInt32(temp[cn-1]);
double ScaleDenominator = Convert.ToDouble(xn10.Item(1).InnerText);
string[] TopLeftCorner = xn10.Item(2).InnerText.Split(' ');
double top = Convert.ToDouble(TopLeftCorner[0]);
double left = Convert.ToDouble(TopLeftCorner[1]);
int TileWidth = Convert.ToInt32(xn10.Item(3).InnerText);
int TileHeight = Convert.ToInt32(xn10.Item(4).InnerText);
int cols = Convert.ToInt32(xn10.Item(5).InnerText);
int rows = Convert.ToInt32(xn10.Item(6).InnerText);
_tileMatrix ts = new _tileMatrix();
ts.level = level;
ts.cornerTop = top;
ts.cornerLeft = level;
ts.tileWidth = TileWidth;
ts.tileHeight = TileHeight;
ts.tileCols = cols;
ts.tileRows = rows;
tileMatrixSet.Add(level, ts);
minLevel = Math.Min(minLevel, level);
maxLevel = Math.Max(maxLevel, level);
}
}
}
xmlReader.Close();
最新文章
- Mybatis关联查询和数据库不一致问题分析与解决
- CAShaperLayer的应用
- webform FileUpload控件实例应用 上传图片
- oracle nvl和nvl2的区别
- iOS 中的XML解析代码(SAX)
- lintcode: 有效的括号序列
- SQL Server查询性能优化——创建索引原则(一)
- Swift笔记4
- 设计师Yoyo:为用户设计产品,让他们生活更美好
- Django发HTML邮件
- SpringAop注解实现日志的存储
- PHP的json_encode不兼容JSON_UNESCAPED_UNICODE的解决方案
- Linux基础学习(7)--用户和用户组管理
- Python 创建和使用类
- java-学习4
- Delphi,C语言互通脚本引擎研究
- SMTP 通过 ssh 通道发送垃圾邮件
- java面试①整体流程
- struts2 Action生命周期
- asp.net 判断session是否过期