SDE与shapefile之间的数据导入与导出
一、SDE要素导出到shapefile中。
1、创建一个新的shapefile文件。
private bool CreateShapefile(string filepath, string name)
{
bool isSuccssed = false;
try
{
IFeatureWorkspace pFWS = null;
IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
pFWS = pWSF.OpenFromFile(filepath, ) as IFeatureWorkspace; IFields pFields;
IFieldsEdit pFieldsEdit;
pFields = new FieldsClass();
pFieldsEdit = pFields as IFieldsEdit;
IField pField;
IFieldEdit pFieldEdit;
pField = new FieldClass();
pFieldEdit = pField as IFieldEdit;
pFieldEdit.Name_2 = "Shape";
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
IGeometryDef pGeomDef;
IGeometryDefEdit pGeomDefEdit;
pGeomDef = new GeometryDefClass();
pGeomDefEdit = pGeomDef as IGeometryDefEdit;
pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
pGeomDefEdit.SpatialReference_2 = new UnknownCoordinateSystemClass();
pFieldEdit.GeometryDef_2 = pGeomDef;
pFieldsEdit.AddField(pField);
IFeatureClass pFeatureClass;
pFeatureClass = pFWS.CreateFeatureClass(name, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
isSuccssed = true;
}
catch
{
isSuccssed = false;
}
return isSuccssed;
}
2、从SDE中读取要素,得到Geometry图形。
private IWorkspace GetSdeWorkspace(string Server, string Instance, string database, string user, string password, string version)
{
IWorkspace pWS = null;
IWorkspaceFactory pWSF = null;
IPropertySet pPropertySet = new PropertySet();
//sde数据库连接的各个参数
pPropertySet.SetProperty("Server", Server);
pPropertySet.SetProperty("Instance", Instance);
pPropertySet.SetProperty("Database", database);
pPropertySet.SetProperty("user", user);
pPropertySet.SetProperty("password", password);
pPropertySet.SetProperty("version", version);
try
{
pWSF = new SdeWorkspaceFactory();
pWS = pWSF.Open(pPropertySet, );
}
catch
{
}
finally
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(pPropertySet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(pWSF);
pPropertySet = null;
pWSF = null;
}
return pWS;
}
private List<IGeometry> GetGeometryFromSde(string pFeaClassName,string objectid)
{
List<IGeometry> pGeometryList = new List<IGeometry>();
IWorkspace pWS = null;
IFeatureWorkspace pFWS = null;
IFeatureCursor pFeatCursor = null;
IFeature pFeature = null;
IFeatureClass pFeatClss = null;
IQueryFilter pQueryFilter =new QueryFilterClass();
pWS = GetSdeWorkspace("192.168.121.110", "", "server110_SDE", "sde", "sde2014", "DEFAULT");
try
{
pFWS = pWS as IFeatureWorkspace;
pFeatClss = pFWS.OpenFeatureClass(pFeaClassName);
pQueryFilter.WhereClause = "OBJECTID=" + objectid;
IFeatureCursor featureCursor = pFeatClss.Search(pQueryFilter, false);
while ((pFeature = featureCursor.NextFeature()) != null)
{
if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
{
pGeometryList.Add(pFeature.ShapeCopy);
}
}
}
catch
{
}
finally
{
if (pFeatCursor != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatCursor);
pFeatCursor = null;
}
if (pWS != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(pWS);
}
}
return pGeometryList;
}
3、将sde中获得的要素,加到shapefile中。
private void AddFeature2Shapefile(IGeometry geometry, string filepath, string name)
{
IFeatureWorkspace pFWS = null;
IFeatureClass pFeaCls = null;
IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
pFWS = pWSF.OpenFromFile(filepath, ) as IFeatureWorkspace;
pFeaCls = pFWS.OpenFeatureClass(name);
IDataset dataset = pFeaCls as IDataset;
IWorkspace workspace = dataset.Workspace;
IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;
workspaceEdit.StartEditing(true);
workspaceEdit.StartEditOperation();
IFeatureBuffer featureBuffer = pFeaCls.CreateFeatureBuffer();
IFeatureCursor featureCursor = pFeaCls.Insert(true);
featureBuffer.Shape = geometry;
featureCursor.InsertFeature(featureBuffer);
featureCursor.Flush();
Marshal.ReleaseComObject(featureCursor);
workspaceEdit.StopEditOperation();
workspaceEdit.StopEditing(true);
}
二、将一个shapefile中的要素加到另一个shapefile中方法与上面类似。只是获得的要素源不同。
private IGeometry GetGeometryFromShapefile(string filepath, string name)
{
IGeometry pGeometry = null;
IFeatureWorkspace pFWS = null;
IFeatureClass pFeaCls = null;
IFeature pFeature = null;
IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
pFWS = pWSF.OpenFromFile(filepath, ) as IFeatureWorkspace;
pFeaCls = pFWS.OpenFeatureClass(name);
IFeatureCursor featureCursor = pFeaCls.Search(null, false);
while ((pFeature = featureCursor.NextFeature()) != null)
{
pGeometry = pFeature.ShapeCopy;
}
return pGeometry;
}
SDE与shapefile之间的数据导入与导出的更多相关文章
- SQL Server 之 在数据库之间进行数据导入导出
1.同一服务器上数据库之间进行数据导入导出 (1).使用 SELECT INTO 导出数据 在SQL Server中使用最广泛的就是通过SELECT INTO语句导出数据,SELECT INTO语句同 ...
- 通过 Sqoop1.4.7 将 Mysql5.7、Hive2.3.4、Hbase1.4.9 之间的数据导入导出
目录 目录 1.什么是 Sqoop? 2.下载应用程序及配置环境变量 2.1.下载 Sqoop 1.4.7 2.2.设置环境变量 2.3.设置安装所需环境 3.安装 Sqoop 1.4.7 3.1.修 ...
- 数据分析(7):pandas介绍和数据导入和导出
前言 Numpy Numpy是科学计算的基础包,对数组级的运算支持较好 pandas pandas提供了使我们能够快速便捷地处理结构化数据的大量数据结构和函数.pandas兼具Numpy高性能的数组计 ...
- Hadoop Hive概念学习系列之HDFS、Hive、MySQL、Sqoop之间的数据导入导出(强烈建议去看)
Hive总结(七)Hive四种数据导入方式 (强烈建议去看) Hive几种数据导出方式 https://www.iteblog.com/archives/955 (强烈建议去看) 把MySQL里的数据 ...
- sqoop学习2(数据导入与导出)
最近学习了下这个导数据的工具,但是在export命令这里卡住了,暂时排不了错误.先记录学习的这一点吧 sqoop是什么 sqoop(sql-on-hadoop):是用来实现结构型数据(如关系型数据库) ...
- SQL Server 数据导入与导出
1. BCP 命令 用法: bcp {dbtable | query} {in | out | queryout | format} 数据文件 [-m 最大错误数] [-f 格式化文件] [-e 错误 ...
- Python全栈 MySQL 数据库 (索引、数据导入、导出)
ParisGabriel 每天坚持手写 一天一篇 决定坚持几年 为了梦想为了信仰 开局一张图 表字段重命名(change) alter table 表名 ...
- Hawk 5.1 数据导入和导出
除了一般的数据库导入导出,Hawk还支持从文件导入和导出,支持的文件类型包括: Excel CSV(逗号分割文本文件) TXT (制表符分割文本文件) Json xml Excel 目前来看,Exce ...
- MySQL学习笔记十一:数据导入与导出
数据导入 1.mysqlimport命令行导入数据 在使用mysqlimport命令导入数据时,数据来源文件名要和目标表一致,不想改文件名的话,可以复制一份创建临时文件,示例如下. 建立一个文本use ...
随机推荐
- 《.NET最佳实践》与Ext JS/Touch的团队开发
概述 持续集成 编码规范 测试 小结 概述 有不少开发人员都问过我,Ext JS/Touch是否支持团队开发?对于这个问题,我可以毫不犹豫的回答:支持.原因是在Sencha官网博客中客户示例中,有不少 ...
- R12中注册客户化应用为多组织应用
Oralce EBS R12中引入了MOAC的控制,所有多OU的表对象都添加了数据库VPD的控制策略,需要访问这些对象中的数据,首先需要进行多组织环境的初始化,但是如果客户化的应用中也需要具备多OU的 ...
- Android之BaseAdapter的优雅实现
在android的开发过程中,我们不可避免的要使用ListView来展示我们的Activity上面的内容.你可以使用很多种方式来实现这一功能,但是如何优雅快速的来实现呢?这就是我要写的了,既为了大家共 ...
- Leetcode_104_Maximum Depth of Binary Tree
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41964475 Maximum Depth of Binar ...
- Python的time(时间戳与时间字符串互相转化)
strptime("string format")字符串如"20130512000000"格式的 输入处理函数 localtime(float a)时间戳的输入 ...
- 理解WebKit和Chromium: Chromium的多进程资源加载机制
转载请注明原文地址:http://blog.csdn.net/milado_nju ##概述 前面介绍了WebKit中的资源加载机制,其实它只是一个框架性的东西,实际的资源加载依赖于各个WebKit移 ...
- 【56】java本地文件File类详解
1.java类的介绍 public class File extends Object implements Serializable, Comparable<File> 文件和目录路径名 ...
- Leetcode_223_Rectangle Area
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/46868363 Find the total area co ...
- C语言之实现随机数产生算法
随机数,也就是在不同的时刻产生不同的数值.在UNIX操作系统和window的操作系统上,我们知道有一个函数rand,它就是用来产生随机数的函数API接口,那么它的原理如何实现? 如果约定a1=f(se ...
- 存储引擎-Buffered tree
Buffered-tree 也称为COLA,即cache-oblivious,可以不需要知道具体内存大小和一个块的大小,使用一套逻辑进行处理,因此内存大小可知,内存可能被临时占用去做其它事情. Buf ...