TerraGate SFS 4.5 版本 发布矢量数据使用的Cache数据如何再返回成shapefile文件?

两年前帮一个朋友解决过这个问题:

如果原来用4.5版本的时候,在网络环境下,为了提升调用服务器上发布的矢量数据的效率,对一些矢量shapefile格式的数据做了矢量切片,

而后来又弄丢了切片前的原始shapefile数据,当再需要那些原始的shapefile数据的时候,这该怎么办呢?

前几天整理电脑里的资料,刚好看到了这个,就把代码贴出来,分享给大家吧,也许对一些老朋友有用。

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using System.Xml;
  11. using TerraExplorerX;
  12.  
  13. namespace CacheToSHP
  14. {
  15. public partial class FrmMain : Form
  16. {
  17. public SGWorld65 sgworld = null;
  18. IFeatureLayer65 pIFeatureLayer65 = null;
  19. int ixmlc = ;
  20.  
  21. public FrmMain()
  22. {
  23. InitializeComponent();
  24.  
  25. sgworld = new SGWorld65();
  26. }
  27.  
  28. private void btnSelectPath_Click(object sender, EventArgs e)
  29. {
  30. this.folderBrowserDialog1.ShowDialog();
  31. this.txtCachePath.Text = this.folderBrowserDialog1.SelectedPath;
  32. this.txtLayerName.Text = "";
  33. this.txtOutPath.Text = "";
  34. this.lblTips.Text = "";
  35. ixmlc = ;
  36. //清楚dataGridView1项
  37. if (this.dataGridView1.Rows.Count > )
  38. {
  39. this.dataGridView1.DataSource = null;
  40. }
  41. }
  42.  
  43. private void btnOK_Click(object sender, EventArgs e)
  44. {
  45. //清除dataGridView1项
  46. if (this.dataGridView1.Rows.Count > )
  47. {
  48. this.dataGridView1.DataSource = null;
  49. }
  50. ixmlc = ;
  51. this.txtOutPath.Text = "";
  52. this.lblTips.Text = "";
  53. this.txtLayerName.Text = GetLayerName(this.txtCachePath.Text);
  54. this.txtCacheType.Text = GetLayerType(this.txtCachePath.Text + "\\" + this.txtLayerName.Text + ".layer");
  55. FindFile(GetFSubPath(this.txtCachePath.Text));
  56. MessageBox.Show("Cache读取完成!");
  57. }
  58.  
  59. // 获取Cache图层类型 赵贺 2015.02.14.
  60. private String GetLayerType(string dirPathName)
  61. {
  62. string sLayerType = null;
  63. FileStream fs = File.Open(dirPathName, FileMode.Open);
  64. StreamReader sr = new StreamReader(fs);
  65. string res = sr.ReadToEnd();
  66.  
  67. XmlDocument xml = new XmlDocument();
  68. xml.LoadXml(res);
  69. XmlElement root = xml.DocumentElement;
  70. XmlNodeList childlist = root.ChildNodes;
  71. sLayerType = childlist[].ChildNodes[].InnerText;
  72. return sLayerType;
  73. }
  74.  
  75. // 获取Cache图层名称 赵贺 2015.02.14.
  76. private String GetLayerName(string dirPath)
  77. {
  78. string sLayerName = null;
  79. DirectoryInfo Dir = new DirectoryInfo(dirPath);
  80. foreach (FileInfo f in Dir.GetFiles("*.layer")) //查找文件
  81. {
  82. sLayerName = f.ToString().Substring(,f.ToString().IndexOf('.'));
  83. }
  84. return sLayerName;
  85. }
  86.  
  87. // 获取当前文件夹的第一个子文件夹
  88. private String GetFSubPath(string dirPath)
  89. {
  90. DirectoryInfo Dir = new DirectoryInfo(dirPath);
  91. DirectoryInfo[] d = Dir.GetDirectories();
  92. return dirPath + "\\" + d[].ToString();
  93. }
  94.  
  95. //解析XML内容,获取属性字段信息 赵贺 2015.02.14.
  96. private void GetXMLData(string xmlpath)
  97. {
  98. try
  99. {
  100. FileStream fs = File.Open(xmlpath, FileMode.Open);
  101. StreamReader sr = new StreamReader(fs);
  102. string res = sr.ReadToEnd();
  103. res = res.Substring(res.IndexOf("<wfs"), res.Length - res.IndexOf("<wfs"));//去除XML的无效内容
  104.  
  105. XmlDocument xml = new XmlDocument();
  106. xml.LoadXml(res);
  107. XmlElement root = xml.DocumentElement;
  108. XmlNodeList childlist = root.ChildNodes;
  109. if (ixmlc == )// 根据第一个xml的内容读取shp属性字段名称
  110. {
  111. if (this.dataGridView1.Columns.Count > )
  112. {
  113. this.dataGridView1.Columns.Clear();
  114. }
  115. this.dataGridView1.Columns.Add(childlist[].Attributes[].Name, childlist[].Attributes[].Name);
  116. for (int j = ; j < childlist[].ChildNodes[].ChildNodes.Count; j++)
  117. {
  118. this.dataGridView1.Columns.Add(childlist[].ChildNodes[].ChildNodes[j].Name, childlist[].ChildNodes[].ChildNodes[j].Name);
  119. }
  120. ixmlc = ixmlc + ;
  121. }
  122.  
  123. for (int i = ; i < childlist.Count; i++)
  124. {
  125. XmlNode node = childlist[i];
  126. string[] rowtext = new string[node.ChildNodes[].ChildNodes.Count + ];
  127. rowtext[] = childlist[i].Attributes[].Value;//取第一项FID
  128. for (int j = ; j < node.ChildNodes[].ChildNodes.Count; j++)
  129. {
  130. rowtext[j + ] = node.ChildNodes[].ChildNodes[j].InnerText;
  131. }
  132. //this.dataGridView1.Rows.Add(rowtext);
  133. //去除FID重复项
  134. if (dataGridView1.DataSource == null)
  135. {
  136. DataGridViewRow row = dataGridView1.Rows.Cast<DataGridViewRow>()
  137. .FirstOrDefault(r => r.Cells[].EditedFormattedValue.Equals(rowtext[]));
  138. if (row != null) dataGridView1.Rows.Remove(row);
  139. this.dataGridView1.Rows.Add(rowtext);
  140. }
  141. else
  142. {
  143. DataTable dt = (DataTable)dataGridView1.DataSource;
  144. DataRow row = dt.Rows.Cast<DataRow>()
  145. .FirstOrDefault(r => r[].Equals(rowtext[]));
  146. if (row != null) dt.Rows.Remove(row);
  147. this.dataGridView1.Rows.Add(rowtext);
  148. }
  149. }
  150.  
  151. xml = null;
  152. }
  153. catch (Exception ex)
  154. {
  155.  
  156. }
  157. }
  158.  
  159. //遍历指定目录下的XML文件
  160. public void FindFile(string dirPath) //参数dirPath为指定的目录
  161. {
  162. //在指定目录及子目录下查找文件,在listBox1中列出子目录及文件
  163. DirectoryInfo Dir=new DirectoryInfo(dirPath);
  164. try
  165. {
  166. foreach(DirectoryInfo d in Dir.GetDirectories())//查找子目录
  167. {
  168. FindFile(Dir + "\\" + d.ToString());
  169. }
  170. foreach(FileInfo f in Dir.GetFiles("*.xml")) //查找文件
  171. {
  172. GetXMLData(Dir + "\\"+f.ToString());
  173. }
  174. }
  175. catch(Exception e)
  176. {
  177. MessageBox.Show(e.Message);
  178. }
  179. }
  180.  
  181. private void btnExportSHP_Click(object sender, EventArgs e)
  182. {
  183. try
  184. {
  185. this.lblTips.Text = "正在输出....";
  186. if (this.dataGridView1.Rows.Count > )
  187. {
  188. if (this.txtCacheType.Text == "Point")
  189. {
  190. pIFeatureLayer65 = sgworld.Creator.CreateNewFeatureLayer(this.txtLayerName.Text, LayerGeometryType.LGT_POINT, "FileName=" + this.txtLayerName.Text + ".shp;TEPlugName=OGR;", "");
  191. }
  192. else if (this.txtCacheType.Text == "Line")
  193. {
  194. pIFeatureLayer65 = sgworld.Creator.CreateNewFeatureLayer(this.txtLayerName.Text, LayerGeometryType.LGT_POLYLINE, "FileName=" + this.txtLayerName.Text + ".shp;TEPlugName=OGR;", "");
  195. }
  196. else if (this.txtCacheType.Text == "Polygon")
  197. {
  198. pIFeatureLayer65 = sgworld.Creator.CreateNewFeatureLayer(this.txtLayerName.Text, LayerGeometryType.LGT_POLYGON, "FileName=" + this.txtLayerName.Text + ".shp;TEPlugName=OGR;", "");
  199. }
  200. //pIFeatureLayer65.DataSourceInfo.Attributes.CreateAttribute("Yaw", AttributeTypeCode.AT_DOUBLE, 0, 20);
  201. //pIFeatureLayer65.DataSourceInfo.Attributes.CreateAttribute("Pitch", AttributeTypeCode.AT_DOUBLE, 0, 20);
  202. //pIFeatureLayer65.DataSourceInfo.Attributes.CreateAttribute("Roll", AttributeTypeCode.AT_DOUBLE, 0, 20);
  203. //pIFeatureLayer65.DataSourceInfo.Attributes.CreateAttribute("Texture", AttributeTypeCode.AT_TEXT, 1024, 20);
  204. //pIFeatureLayer65.DataSourceInfo.Attributes.CreateAttribute("Radius", AttributeTypeCode.AT_DOUBLE, 0, 20);
  205. //pIFeatureLayer65.DataSourceInfo.Attributes.CreateAttribute("Length", AttributeTypeCode.AT_DOUBLE, 0, 20);
  206. for (int i = ; i < this.dataGridView1.Columns.Count - ; i++)
  207. {
  208. pIFeatureLayer65.DataSourceInfo.Attributes.CreateAttribute(this.dataGridView1.Columns[i].Name, AttributeTypeCode.AT_TEXT, , );
  209. }
  210.  
  211. for (int i = ; i < this.dataGridView1.Rows.Count - ; i++)
  212. {
  213. string rowtext = "";
  214. for (int j = ; j < this.dataGridView1.Columns.Count - ; j++)
  215. {
  216. rowtext = rowtext + this.dataGridView1.Rows[i].Cells[j].Value.ToString() + ";";
  217. }
  218. rowtext = rowtext + this.dataGridView1.Rows[i].Cells[this.dataGridView1.Columns.Count - ].Value.ToString();
  219. if (this.txtCacheType.Text == "Point")
  220. {
  221. string x = this.dataGridView1.Rows[i].Cells[this.dataGridView1.Columns.Count - ].Value.ToString().Split(',')[];
  222. string y = this.dataGridView1.Rows[i].Cells[this.dataGridView1.Columns.Count - ].Value.ToString().Split(',')[];
  223. IGeometry pIGeometry = sgworld.Creator.GeometryCreator.CreatePointGeometry("Point(" + x + " " + y + ")");
  224. pIFeatureLayer65.FeatureGroups.Point.CreateFeature(pIGeometry, rowtext);
  225. }
  226. else if (this.txtCacheType.Text == "Line")
  227. {
  228. IGeometry pIGeometry = sgworld.Creator.GeometryCreator.CreateGeometryFromWKT("LineString (" + this.dataGridView1.Rows[i].Cells[this.dataGridView1.Columns.Count - ].Value.ToString().Replace(" ", ";").Replace(",", " ").Replace(";", ",") + ")");
  229. pIFeatureLayer65.FeatureGroups.Polyline.CreateFeature(pIGeometry, rowtext);
  230. }
  231. else if (this.txtCacheType.Text == "Polygon")
  232. {
  233. string p1 = this.dataGridView1.Rows[i].Cells[this.dataGridView1.Columns.Count - ].Value.ToString().Replace(" ", ";").Replace(",", " ").Replace(";", ",").Substring(,this.dataGridView1.Rows[i].Cells[this.dataGridView1.Columns.Count - ].Value.ToString().Replace(" ", ";").Replace(",", " ").Replace(";", ",").IndexOf(","));
  234. string s = this.dataGridView1.Rows[i].Cells[this.dataGridView1.Columns.Count - ].Value.ToString().Replace(" ", ";").Replace(",", " ").Replace(";", ",")+","+p1;
  235. IGeometry pIGeometry = sgworld.Creator.GeometryCreator.CreateGeometryFromWKT("Polygon((" + this.dataGridView1.Rows[i].Cells[this.dataGridView1.Columns.Count - ].Value.ToString().Replace(" ", ";").Replace(",", " ").Replace(";", ",") + "," + p1 + "))");
  236. pIFeatureLayer65.FeatureGroups.Polygon.CreateFeature(pIGeometry, rowtext);
  237. }
  238. else
  239. { }
  240. }
  241. }
  242. if (pIFeatureLayer65 != null)
  243. {
  244. pIFeatureLayer65.Save();
  245.  
  246. pIFeatureLayer65.Reproject = false;// 是否重投影 赵贺 2015.02.14
  247. pIFeatureLayer65.CoordinateSystem.WellKnownText = "PROJCS[\"Beijing 1954 / 3-degree Gauss-Kruger Zone 37N\",GEOGCS[\"Beijing 1954\",DATUM[\"Beijing_1954\",SPHEROID[\"Krassowsky 1940\",6378245,298.3,AUTHORITY[\"EPSG\",\"7024\"]],TOWGS84[15.8,-154.4,-82.3,0,0,0,0],AUTHORITY[\"EPSG\",\"6214\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4214\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",111],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"X\",NORTH],AXIS[\"Y\",EAST],AUTHORITY[\"EPSG\",\"2434\"]]";
  248. pIFeatureLayer65.Load();
  249. pIFeatureLayer65 = null;
  250. }
  251. this.txtOutPath.Text = "" + sgworld.Application.DataPath + "\\FeatureLayers";
  252. this.lblTips.Text = "完成.";
  253.  
  254. pIFeatureLayer65 = null;
  255. }
  256. catch (Exception ex)
  257. {
  258. MessageBox.Show(ex.ToString());
  259. }
  260. }
  261.  
  262. private void btnSOutPath_Click(object sender, EventArgs e)
  263. {
  264. this.folderBrowserDialog1.ShowDialog();
  265. this.txtOutPath.Text = this.folderBrowserDialog1.SelectedPath;
  266. }
  267. }
  268. }

TerraGate SFS 4.5 版本 发布矢量数据使用的Cache数据如何再返回成shapefile文件的更多相关文章

  1. EQueue 2.3.2版本发布(支持高可用)

    前言 前段时间针对EQueue的完善终于告一段落了,实在值得庆祝,自己的付出和坚持总算有了成果.这次新版本主要为EQueue实现了集群功能,基本实现了Broker的高可用.另外还增加了很多实用的功能, ...

  2. glibc 各版本发布时间以及内核默认glibc版本

    最近有些软件要求glibc 2.14+,centos 6.x自带的版本是2.12的,特查了下glibc 各版本发布时间以及与对应的内核,如下: Complete glibc release histo ...

  3. 比Ansible更吊的自动化运维工具,自动化统一安装部署自动化部署udeploy 1.0 版本发布

    新增功能: 逻辑与业务分离,完美实现逻辑与业务分离,业务实现统一shell脚本开发,由框架统一调用. 并发多线程部署,不管多少台服务器,多少个服务,同时发起线程进行更新.部署.启动. 提高list规则 ...

  4. Beta版本发布说明

    发布地址 https://github.com/LongWerLingShi/DataObtainingAndHandling/tree/beta 版本开发背景 首先,应软件工程课程要求,我们小组针对 ...

  5. 评论alpha版本发布

    讲解顺序: 1.  新蜂:俄罗斯方块 俄罗斯方块已经完成了核心的游戏部分,可以流畅的进行游戏,经验值功能也已经完成,目前进度很好:不足之处主要有:后续的显示内容还没完成,所以界面空出来很多板块,alp ...

  6. Percona Server 5.6.13-61.0 首个 GA 版本发布

    Percona Server 5.6 的首个 GA 版本发布了,版本号是 5.6.13-61.0 ,该版本基于 MySQL 5.6.13 改进内容包括: New Features: Percona S ...

  7. RDIFramework.NET ━ .NET快速信息化系统开发框架 V2.8 版本发布

    (新年巨献) RDIFramework.NET ━ .NET快速信息化系统开发框架 V2.8 版本发布 历时数月,RDIFramework.NET V2.8版本发布了,感谢大家的支持. RDIFram ...

  8. RDIFramework.NET ━ .NET快速信息化系统开发框架 V2.7 版本发布

    历时数月,RDIFramework.NET V2.7 版本发布了,感谢大家的支持. RDIFramework.NET,基于.NET的快速信息化系统开发.整合框架,为企业或个人在.NET环境下快速开发系 ...

  9. Spring.Net.FrameworkV3.0 版本发布了,感谢大家的支持

    Spring.Net.FrameworkV3.0 版本发布了,感谢大家的支持. Spring.Net.Framework,基于.NET的快速信息化系统开发.整合框架,为企业或个人在.NET环境下快速开 ...

随机推荐

  1. canvas-star6-drawMoon.html

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 51Nod 最小公倍数之和V3

    这题公式真tm难推……为了这题费了我一个草稿本…… woc……在51Nod上码LaTeX码了两个多小时…… 一开始码完了前半段,刚码完后半段突然被51Nod吃了,重新码完后半段之后前半段又被吃了,吓得 ...

  3. Spark jdbc postgresql数据库连接和写入操作源码解读

    概述:Spark postgresql jdbc 数据库连接和写入操作源码解读,详细记录了SparkSQL对数据库的操作,通过java程序,在本地开发和运行.整体为,Spark建立数据库连接,读取数据 ...

  4. Sqlserver精简安装选项

  5. sql server alwayson 可用性组 只读路由的设置

    昨天晚上学习了[SQL Server 2012实施与管理实战指南]的第三章,于是今天想在前段时间建的那个alwayson 可用性组测试环境上也配置一下只读路由,尝试实现读写分离. 按照书中的方法,执行 ...

  6. 减少MySQL主从延迟的神器--并行复制大揭密

    1. 简介 MySQL 5.6引入了基于schema的并行复制,即如果binlog events操作的是不同schema的对象,不是DDL,且操作的对象没有对其他schema的foreign key关 ...

  7. LCD显示异常分析——撕裂(tear effect)【转】

    转自:LCD显示异常分析--撕裂(tear effect) 概述 在上一篇<LCD显示异常分析--开机闪现花屏>中,我们一起分析了开机花屏的问题,在这一篇中,我将对LCD撕裂(tear e ...

  8. [MapReduce_5] MapReduce 中的 Combiner 组件应用

    0. 说明 Combiner 介绍 &&  在 MapReduce 中的应用 1. 介绍 Combiner: Map 端的 Reduce,有自己的使用场景 在相同 Key 过多的情况下 ...

  9. Centos7使用Docker安装Gogs搭建git服务器

    gihub地址:https://github.com/gogs/gogs gogs官网:https://gogs.io/ gihub官方docker安装gogs方法:https://github.co ...

  10. 解决wordpress上传文件出现http错误问题

    解决wordpress上传文件出现http错误问题 问题现象 今天上传约1.4m大小的gif文件到wordpress的媒体库时失败,提示http错误. 原因 由于之前一直上传图片都是可以的,所以推测最 ...