c#读kml文件

2021-04-26 12:29

阅读:633

标签:http   for   live   bst   void   获取   oms   close   string   

 1           HttpFileCollection xmlfile = null;
 2                 xmlfile = context.Request.Files;
 3                 if (xmlfile != null && xmlfile.Count > 0)
 4                 {
 5                     string guid = Guid.NewGuid().ToString();
 6                     string curDataTime = DateTime.Now.ToString("yyyy-MM月dd日 HH时mm分ss秒");
 7                     string uploadDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//uploadDate
 8                     string save_Path = context.Server.MapPath("../upload/KML/");
 9                     HttpPostedFile file = xmlfile[0];
10                     string newXmlFileName = curDataTime + "-" + guid.ToUpper().Replace("-", "") + "-" + file.FileName;
11                     file.SaveAs(save_Path + newXmlFileName);
12                     //上传成功后,导入到数据库中
13                     {
14                         XmlDocument xmldoc = new XmlDocument();
15                         xmldoc.Load(save_Path + newXmlFileName);
16                         XmlElement root = xmldoc.DocumentElement;
17                         /////规范命名空间
18                         XmlNode _document = root.GetElementsByTagName("Document")[0];
19                         XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmldoc.NameTable);
20                         if (_document.Attributes["xmlns"]==null)
21                         {
22                             nsmgr.AddNamespace("ns", root.Attributes["xmlns"].Value);
23                         }
24                         else
25                         {
26                             nsmgr.AddNamespace("ns", _document.Attributes["xmlns"].Value);
27                         }
28                         XmlNodeList xmlmark = root.GetElementsByTagName("Placemark");
29                         {
30                             int tpid = 0;//踏勘点序号                       
31                             for (int m = 2; m 1; m++)//前两个是起点和终点不插入数据库
32                             {
33                                 tpid = tpid + 1;
34                                 XmlNode nameNode = xmlmark[m].SelectSingleNode("ns:name", nsmgr);
35                                 string nmNode = nameNode.InnerText;
36                                 string note = "";
37                                 if (nmNode.IndexOf(" ") > 0)//存在空格,就说明有备注
38                                 {
39                                     note = nmNode.Substring(nmNode.IndexOf(" ") + 1);
40                                 }
41                                 XmlNodeList divList = xmlmark[m].SelectNodes("ns:description/ns:div", nsmgr);
42 
43                                 string lng = (divList[1].InnerText).Substring(3);
44                                 string lat = (divList[2].InnerText).Substring(3);
45                                 string lnglat = lng + "," + lat;
46                                 string ph = context.Server.MapPath("../upload/");
47                                 string path = curDataTime + "/TankanData/Image" + lng + lat+"/";
48                                 Directory.CreateDirectory(ph + path);
49                                 XmlNodeList a_img = divList[0].SelectNodes("ns:a/ns:img", nsmgr);
50                                 string src = "";
51                                 string path_name = projectName + "-" + fangan + "-" + tpid + "号踏勘点";
52                                 string img_path = "";
53                                 string img_name = "";
54                                 for (int n = 0; n )
55                                 {
56                                     src = a_img[n].Attributes["src"].Value;//photo
57                                     string save_path = path + path_name + "-" + (n + 1) + ".jpg";
58                                     GetImg(src, ph + save_path);//将网上的照片存到本地
59                                     img_name += img_name + path_name + "-" + (n + 1) + ".jpg;";
60                                     img_path = "/upload/" + path + img_name.Remove(img_name.Length-1);
61                                    
62                                 }
63 
64                                 string sql2 = "";
65                                 DBHelper.ExecuteCommand(sql2);
66                             }
67                             //获取轨迹,插入数据库
68                             XmlNodeList node = root.GetElementsByTagName("gx:coord");
69                             string arr = "";
70                             for (int i = 0; i )
71                             {
72                                 string str = node[i].InnerXml;
73                                 string[] pt = str.Split( );
74                                 for (int j = 0; j 1; j++)
75                                 {
76                                     arr += pt[j] + ",";
77                                 }
78                             }
79                             arr = arr.Substring(0, arr.Length - 1);
80                             string sql = "";
81                             string sql5 = "";
82                             string sql1 = "";
83                             DataTable dt1 = DBHelper.GetDataSet(sql1).Tables[0];
84 
85                                 sql5 = "";
86                                 DBHelper.ExecuteCommand(sql5);
87 
88                         }
89                     }
90                 }
public void GetImg(string url, string path)
    {
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
        req.ServicePoint.Expect100Continue = false;
        req.Method = "GET";
        req.KeepAlive = true;
        req.ContentType = "image/jpeg";//网上的图片格式是jpg
        HttpWebResponse rsp = (HttpWebResponse)req.GetResponse();
        System.IO.Stream stream = null;
        try
        {
            stream = rsp.GetResponseStream();
            System.Drawing.Image.FromStream(stream).Save(path);
        }
        finally
        {
            if (stream != null)
            {
                stream.Close();
            }
            if (rsp != null)
            {
                rsp.Close();
            }
        }

 

c#读kml文件

标签:http   for   live   bst   void   获取   oms   close   string   

原文地址:http://www.cnblogs.com/bowen-yao/p/7891823.html


评论


亲,登录后才可以留言!