TerraGate SFS 4.5 版本 发布矢量数据使用的Cache数据如何再返回成shapefile文件
TerraGate SFS 4.5 版本 发布矢量数据使用的Cache数据如何再返回成shapefile文件?
两年前帮一个朋友解决过这个问题:
如果原来用4.5版本的时候,在网络环境下,为了提升调用服务器上发布的矢量数据的效率,对一些矢量shapefile格式的数据做了矢量切片,
而后来又弄丢了切片前的原始shapefile数据,当再需要那些原始的shapefile数据的时候,这该怎么办呢?
前几天整理电脑里的资料,刚好看到了这个,就把代码贴出来,分享给大家吧,也许对一些老朋友有用。
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- using System.Xml;
- using TerraExplorerX;
- namespace CacheToSHP
- {
- public partial class FrmMain : Form
- {
- public SGWorld65 sgworld = null;
- IFeatureLayer65 pIFeatureLayer65 = null;
- int ixmlc = ;
- public FrmMain()
- {
- InitializeComponent();
- sgworld = new SGWorld65();
- }
- private void btnSelectPath_Click(object sender, EventArgs e)
- {
- this.folderBrowserDialog1.ShowDialog();
- this.txtCachePath.Text = this.folderBrowserDialog1.SelectedPath;
- this.txtLayerName.Text = "";
- this.txtOutPath.Text = "";
- this.lblTips.Text = "";
- ixmlc = ;
- //清楚dataGridView1项
- if (this.dataGridView1.Rows.Count > )
- {
- this.dataGridView1.DataSource = null;
- }
- }
- private void btnOK_Click(object sender, EventArgs e)
- {
- //清除dataGridView1项
- if (this.dataGridView1.Rows.Count > )
- {
- this.dataGridView1.DataSource = null;
- }
- ixmlc = ;
- this.txtOutPath.Text = "";
- this.lblTips.Text = "";
- this.txtLayerName.Text = GetLayerName(this.txtCachePath.Text);
- this.txtCacheType.Text = GetLayerType(this.txtCachePath.Text + "\\" + this.txtLayerName.Text + ".layer");
- FindFile(GetFSubPath(this.txtCachePath.Text));
- MessageBox.Show("Cache读取完成!");
- }
- // 获取Cache图层类型 赵贺 2015.02.14.
- private String GetLayerType(string dirPathName)
- {
- string sLayerType = null;
- FileStream fs = File.Open(dirPathName, FileMode.Open);
- StreamReader sr = new StreamReader(fs);
- string res = sr.ReadToEnd();
- XmlDocument xml = new XmlDocument();
- xml.LoadXml(res);
- XmlElement root = xml.DocumentElement;
- XmlNodeList childlist = root.ChildNodes;
- sLayerType = childlist[].ChildNodes[].InnerText;
- return sLayerType;
- }
- // 获取Cache图层名称 赵贺 2015.02.14.
- private String GetLayerName(string dirPath)
- {
- string sLayerName = null;
- DirectoryInfo Dir = new DirectoryInfo(dirPath);
- foreach (FileInfo f in Dir.GetFiles("*.layer")) //查找文件
- {
- sLayerName = f.ToString().Substring(,f.ToString().IndexOf('.'));
- }
- return sLayerName;
- }
- // 获取当前文件夹的第一个子文件夹
- private String GetFSubPath(string dirPath)
- {
- DirectoryInfo Dir = new DirectoryInfo(dirPath);
- DirectoryInfo[] d = Dir.GetDirectories();
- return dirPath + "\\" + d[].ToString();
- }
- //解析XML内容,获取属性字段信息 赵贺 2015.02.14.
- private void GetXMLData(string xmlpath)
- {
- try
- {
- FileStream fs = File.Open(xmlpath, FileMode.Open);
- StreamReader sr = new StreamReader(fs);
- string res = sr.ReadToEnd();
- res = res.Substring(res.IndexOf("<wfs"), res.Length - res.IndexOf("<wfs"));//去除XML的无效内容
- XmlDocument xml = new XmlDocument();
- xml.LoadXml(res);
- XmlElement root = xml.DocumentElement;
- XmlNodeList childlist = root.ChildNodes;
- if (ixmlc == )// 根据第一个xml的内容读取shp属性字段名称
- {
- if (this.dataGridView1.Columns.Count > )
- {
- this.dataGridView1.Columns.Clear();
- }
- this.dataGridView1.Columns.Add(childlist[].Attributes[].Name, childlist[].Attributes[].Name);
- for (int j = ; j < childlist[].ChildNodes[].ChildNodes.Count; j++)
- {
- this.dataGridView1.Columns.Add(childlist[].ChildNodes[].ChildNodes[j].Name, childlist[].ChildNodes[].ChildNodes[j].Name);
- }
- ixmlc = ixmlc + ;
- }
- for (int i = ; i < childlist.Count; i++)
- {
- XmlNode node = childlist[i];
- string[] rowtext = new string[node.ChildNodes[].ChildNodes.Count + ];
- rowtext[] = childlist[i].Attributes[].Value;//取第一项FID
- for (int j = ; j < node.ChildNodes[].ChildNodes.Count; j++)
- {
- rowtext[j + ] = node.ChildNodes[].ChildNodes[j].InnerText;
- }
- //this.dataGridView1.Rows.Add(rowtext);
- //去除FID重复项
- if (dataGridView1.DataSource == null)
- {
- DataGridViewRow row = dataGridView1.Rows.Cast<DataGridViewRow>()
- .FirstOrDefault(r => r.Cells[].EditedFormattedValue.Equals(rowtext[]));
- if (row != null) dataGridView1.Rows.Remove(row);
- this.dataGridView1.Rows.Add(rowtext);
- }
- else
- {
- DataTable dt = (DataTable)dataGridView1.DataSource;
- DataRow row = dt.Rows.Cast<DataRow>()
- .FirstOrDefault(r => r[].Equals(rowtext[]));
- if (row != null) dt.Rows.Remove(row);
- this.dataGridView1.Rows.Add(rowtext);
- }
- }
- xml = null;
- }
- catch (Exception ex)
- {
- }
- }
- //遍历指定目录下的XML文件
- public void FindFile(string dirPath) //参数dirPath为指定的目录
- {
- //在指定目录及子目录下查找文件,在listBox1中列出子目录及文件
- DirectoryInfo Dir=new DirectoryInfo(dirPath);
- try
- {
- foreach(DirectoryInfo d in Dir.GetDirectories())//查找子目录
- {
- FindFile(Dir + "\\" + d.ToString());
- }
- foreach(FileInfo f in Dir.GetFiles("*.xml")) //查找文件
- {
- GetXMLData(Dir + "\\"+f.ToString());
- }
- }
- catch(Exception e)
- {
- MessageBox.Show(e.Message);
- }
- }
- private void btnExportSHP_Click(object sender, EventArgs e)
- {
- try
- {
- this.lblTips.Text = "正在输出....";
- if (this.dataGridView1.Rows.Count > )
- {
- if (this.txtCacheType.Text == "Point")
- {
- pIFeatureLayer65 = sgworld.Creator.CreateNewFeatureLayer(this.txtLayerName.Text, LayerGeometryType.LGT_POINT, "FileName=" + this.txtLayerName.Text + ".shp;TEPlugName=OGR;", "");
- }
- else if (this.txtCacheType.Text == "Line")
- {
- pIFeatureLayer65 = sgworld.Creator.CreateNewFeatureLayer(this.txtLayerName.Text, LayerGeometryType.LGT_POLYLINE, "FileName=" + this.txtLayerName.Text + ".shp;TEPlugName=OGR;", "");
- }
- else if (this.txtCacheType.Text == "Polygon")
- {
- pIFeatureLayer65 = sgworld.Creator.CreateNewFeatureLayer(this.txtLayerName.Text, LayerGeometryType.LGT_POLYGON, "FileName=" + this.txtLayerName.Text + ".shp;TEPlugName=OGR;", "");
- }
- //pIFeatureLayer65.DataSourceInfo.Attributes.CreateAttribute("Yaw", AttributeTypeCode.AT_DOUBLE, 0, 20);
- //pIFeatureLayer65.DataSourceInfo.Attributes.CreateAttribute("Pitch", AttributeTypeCode.AT_DOUBLE, 0, 20);
- //pIFeatureLayer65.DataSourceInfo.Attributes.CreateAttribute("Roll", AttributeTypeCode.AT_DOUBLE, 0, 20);
- //pIFeatureLayer65.DataSourceInfo.Attributes.CreateAttribute("Texture", AttributeTypeCode.AT_TEXT, 1024, 20);
- //pIFeatureLayer65.DataSourceInfo.Attributes.CreateAttribute("Radius", AttributeTypeCode.AT_DOUBLE, 0, 20);
- //pIFeatureLayer65.DataSourceInfo.Attributes.CreateAttribute("Length", AttributeTypeCode.AT_DOUBLE, 0, 20);
- for (int i = ; i < this.dataGridView1.Columns.Count - ; i++)
- {
- pIFeatureLayer65.DataSourceInfo.Attributes.CreateAttribute(this.dataGridView1.Columns[i].Name, AttributeTypeCode.AT_TEXT, , );
- }
- for (int i = ; i < this.dataGridView1.Rows.Count - ; i++)
- {
- string rowtext = "";
- for (int j = ; j < this.dataGridView1.Columns.Count - ; j++)
- {
- rowtext = rowtext + this.dataGridView1.Rows[i].Cells[j].Value.ToString() + ";";
- }
- rowtext = rowtext + this.dataGridView1.Rows[i].Cells[this.dataGridView1.Columns.Count - ].Value.ToString();
- if (this.txtCacheType.Text == "Point")
- {
- string x = this.dataGridView1.Rows[i].Cells[this.dataGridView1.Columns.Count - ].Value.ToString().Split(',')[];
- string y = this.dataGridView1.Rows[i].Cells[this.dataGridView1.Columns.Count - ].Value.ToString().Split(',')[];
- IGeometry pIGeometry = sgworld.Creator.GeometryCreator.CreatePointGeometry("Point(" + x + " " + y + ")");
- pIFeatureLayer65.FeatureGroups.Point.CreateFeature(pIGeometry, rowtext);
- }
- else if (this.txtCacheType.Text == "Line")
- {
- IGeometry pIGeometry = sgworld.Creator.GeometryCreator.CreateGeometryFromWKT("LineString (" + this.dataGridView1.Rows[i].Cells[this.dataGridView1.Columns.Count - ].Value.ToString().Replace(" ", ";").Replace(",", " ").Replace(";", ",") + ")");
- pIFeatureLayer65.FeatureGroups.Polyline.CreateFeature(pIGeometry, rowtext);
- }
- else if (this.txtCacheType.Text == "Polygon")
- {
- 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(","));
- string s = this.dataGridView1.Rows[i].Cells[this.dataGridView1.Columns.Count - ].Value.ToString().Replace(" ", ";").Replace(",", " ").Replace(";", ",")+","+p1;
- IGeometry pIGeometry = sgworld.Creator.GeometryCreator.CreateGeometryFromWKT("Polygon((" + this.dataGridView1.Rows[i].Cells[this.dataGridView1.Columns.Count - ].Value.ToString().Replace(" ", ";").Replace(",", " ").Replace(";", ",") + "," + p1 + "))");
- pIFeatureLayer65.FeatureGroups.Polygon.CreateFeature(pIGeometry, rowtext);
- }
- else
- { }
- }
- }
- if (pIFeatureLayer65 != null)
- {
- pIFeatureLayer65.Save();
- pIFeatureLayer65.Reproject = false;// 是否重投影 赵贺 2015.02.14
- 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\"]]";
- pIFeatureLayer65.Load();
- pIFeatureLayer65 = null;
- }
- this.txtOutPath.Text = "" + sgworld.Application.DataPath + "\\FeatureLayers";
- this.lblTips.Text = "完成.";
- pIFeatureLayer65 = null;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- private void btnSOutPath_Click(object sender, EventArgs e)
- {
- this.folderBrowserDialog1.ShowDialog();
- this.txtOutPath.Text = this.folderBrowserDialog1.SelectedPath;
- }
- }
- }
TerraGate SFS 4.5 版本 发布矢量数据使用的Cache数据如何再返回成shapefile文件的更多相关文章
- EQueue 2.3.2版本发布(支持高可用)
前言 前段时间针对EQueue的完善终于告一段落了,实在值得庆祝,自己的付出和坚持总算有了成果.这次新版本主要为EQueue实现了集群功能,基本实现了Broker的高可用.另外还增加了很多实用的功能, ...
- glibc 各版本发布时间以及内核默认glibc版本
最近有些软件要求glibc 2.14+,centos 6.x自带的版本是2.12的,特查了下glibc 各版本发布时间以及与对应的内核,如下: Complete glibc release histo ...
- 比Ansible更吊的自动化运维工具,自动化统一安装部署自动化部署udeploy 1.0 版本发布
新增功能: 逻辑与业务分离,完美实现逻辑与业务分离,业务实现统一shell脚本开发,由框架统一调用. 并发多线程部署,不管多少台服务器,多少个服务,同时发起线程进行更新.部署.启动. 提高list规则 ...
- Beta版本发布说明
发布地址 https://github.com/LongWerLingShi/DataObtainingAndHandling/tree/beta 版本开发背景 首先,应软件工程课程要求,我们小组针对 ...
- 评论alpha版本发布
讲解顺序: 1. 新蜂:俄罗斯方块 俄罗斯方块已经完成了核心的游戏部分,可以流畅的进行游戏,经验值功能也已经完成,目前进度很好:不足之处主要有:后续的显示内容还没完成,所以界面空出来很多板块,alp ...
- 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 ...
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V2.8 版本发布
(新年巨献) RDIFramework.NET ━ .NET快速信息化系统开发框架 V2.8 版本发布 历时数月,RDIFramework.NET V2.8版本发布了,感谢大家的支持. RDIFram ...
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V2.7 版本发布
历时数月,RDIFramework.NET V2.7 版本发布了,感谢大家的支持. RDIFramework.NET,基于.NET的快速信息化系统开发.整合框架,为企业或个人在.NET环境下快速开发系 ...
- Spring.Net.FrameworkV3.0 版本发布了,感谢大家的支持
Spring.Net.FrameworkV3.0 版本发布了,感谢大家的支持. Spring.Net.Framework,基于.NET的快速信息化系统开发.整合框架,为企业或个人在.NET环境下快速开 ...
随机推荐
- JQuery的事件委托;jQuery注册事件;jQuery事件解绑
一.事件 ①事件委托:就是给子元素的父元素或者祖先元素注册一个事件,但是事件的执行者是子元素,委托事件的好处是能够给动态创建出来时元素也加上事件. ②简单事件:就是给自己注册事件自己执行动态创建出来的 ...
- csharp: mappings using Dapper-Extensions+Dapper.net.
sql: CREATE TABLE [PotoUsers] ( [UserID] INT IDENTITY(1,1) PRIMARY KEY, [UserName] NVARCHAR(50), [Fi ...
- ArcGIS地图文档优化 mxdPerfstat工具使用体验
经常有客户会咨询到如何提高地图的显示性能.为何ArcMap刷新地图那么缓慢.为何地图服务响应要等待10多秒? 诸如这些问题,虽然它们的表象都是相似的,但是往往在分析排查问题的时候,我们发现背后的原因是 ...
- NFS共享权限挂载
mount -t nfs 192.168.2.203:/data/lys /lys -o proto=tcp -o nolock mount 172.16.2.18:/home/arcgisserve ...
- Expo大作战(二十九)--expo sdk api之registerRootComponent(注册跟组件),ScreenOrientation(屏幕切换),SecureStore,
简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...
- NB-IOT模块 M5310-A接入百度开放云IOT Hub MQTT
目录 1.登陆百度开放云,在产品服务中选择IOT HUB 2 2.选择 创建计费套餐,目前1百万条/每月是免费的 2 3.点击管理控制台进入项目列表 4 4. 点击创建项目,项目类型选择数据型 4 5 ...
- Apache POI导出excel表格
项目中我们经常用到导出功能,将数据导出以便于审查和统计等.本文主要使用Apache POI实现导出数据. POI中文文档 简介 ApachePOI是Apache软件基金会的开放源码函式库,POI提供A ...
- Asp.net 中ViewState,cookie,session,application,cache的比较
Asp.net 中的状态管理维护包含ViewState,cookie,session,application,cache五种方式,以下是它们的一些比较: 1.存在于客户端还是服务端 客户端: view ...
- python第六十五天--python操作mysql
pymysql模块对mysql进行 import pymysql # 创建连接 conn = pymysql.connect(host='127.0.0.1', port=3306, user='ro ...
- 利用RSACryptoServiceProvider进行RSA加密解密
前言: 本文只介绍How to use,对于加密算法的研究不予讨论. 关于私钥的存储,微软给的建议是使用windows自带的秘钥容器,相见文档. 为了直观看到私钥和公钥,本文直接将其存入XML文件中. ...