解析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();

最新文章

  1. Mybatis关联查询和数据库不一致问题分析与解决
  2. CAShaperLayer的应用
  3. webform FileUpload控件实例应用 上传图片
  4. oracle nvl和nvl2的区别
  5. iOS 中的XML解析代码(SAX)
  6. lintcode: 有效的括号序列
  7. SQL Server查询性能优化——创建索引原则(一)
  8. Swift笔记4
  9. 设计师Yoyo:为用户设计产品,让他们生活更美好
  10. Django发HTML邮件
  11. SpringAop注解实现日志的存储
  12. PHP的json_encode不兼容JSON_UNESCAPED_UNICODE的解决方案
  13. Linux基础学习(7)--用户和用户组管理
  14. Python 创建和使用类
  15. java-学习4
  16. Delphi,C语言互通脚本引擎研究
  17. SMTP 通过 ssh 通道发送垃圾邮件
  18. java面试①整体流程
  19. struts2 Action生命周期
  20. asp.net 判断session是否过期

热门文章

  1. pyqt5最简单操作数据库
  2. python的select和epoll
  3. ref:如何在大量jar包中搜索特定字符
  4. [hdu3934] 凸包 旋转卡壳
  5. AppDomain.CurrentDomain.BaseDirectory是什么
  6. Arduino可穿戴教程之第一个程序——选择端口(三)
  7. 获取token
  8. git实现github仓库和本地仓库同步
  9. 顺序存储线性表_ArrayList
  10. java--由一道选择题研究数值越界