zoukankan      html  css  js  c++  java
  • 使用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();

  • 相关阅读:
    [转]多个ajax请求时控制执行顺序或全部执行后的操作
    [转]微擎目录结构介绍
    [书目20180702]互联网思维的企业
    [转]Oracle密码过期, 报:ORA-01017: 用户名/口令无效; 登录被拒绝
    [转]VR原理讲解及开发入门
    [转]JS组件系列——Bootstrap组件福利篇:几款好用的组件推荐
    [转]bootstrapValidator.js 做表单验证
    [转]Build beautiful, responsive sites with Bootstrap and ASP.NET Core
    [转]C# Bootstrap table之 分页
    [转]Bootstrap table 分页 In asp.net MVC
  • 原文地址:https://www.cnblogs.com/mazhenyu/p/7472231.html
Copyright © 2011-2022 走看看