一、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之间的数据导入与导出的更多相关文章

  1. SQL Server 之 在数据库之间进行数据导入导出

    1.同一服务器上数据库之间进行数据导入导出 (1).使用 SELECT INTO 导出数据 在SQL Server中使用最广泛的就是通过SELECT INTO语句导出数据,SELECT INTO语句同 ...

  2. 通过 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.修 ...

  3. 数据分析(7):pandas介绍和数据导入和导出

    前言 Numpy Numpy是科学计算的基础包,对数组级的运算支持较好 pandas pandas提供了使我们能够快速便捷地处理结构化数据的大量数据结构和函数.pandas兼具Numpy高性能的数组计 ...

  4. Hadoop Hive概念学习系列之HDFS、Hive、MySQL、Sqoop之间的数据导入导出(强烈建议去看)

    Hive总结(七)Hive四种数据导入方式 (强烈建议去看) Hive几种数据导出方式 https://www.iteblog.com/archives/955 (强烈建议去看) 把MySQL里的数据 ...

  5. sqoop学习2(数据导入与导出)

    最近学习了下这个导数据的工具,但是在export命令这里卡住了,暂时排不了错误.先记录学习的这一点吧 sqoop是什么 sqoop(sql-on-hadoop):是用来实现结构型数据(如关系型数据库) ...

  6. SQL Server 数据导入与导出

    1. BCP 命令 用法: bcp {dbtable | query} {in | out | queryout | format} 数据文件 [-m 最大错误数] [-f 格式化文件] [-e 错误 ...

  7. Python全栈 MySQL 数据库 (索引、数据导入、导出)

    ParisGabriel              每天坚持手写  一天一篇  决定坚持几年 为了梦想为了信仰    开局一张图     表字段重命名(change)   alter table 表名 ...

  8. Hawk 5.1 数据导入和导出

    除了一般的数据库导入导出,Hawk还支持从文件导入和导出,支持的文件类型包括: Excel CSV(逗号分割文本文件) TXT (制表符分割文本文件) Json xml Excel 目前来看,Exce ...

  9. MySQL学习笔记十一:数据导入与导出

    数据导入 1.mysqlimport命令行导入数据 在使用mysqlimport命令导入数据时,数据来源文件名要和目标表一致,不想改文件名的话,可以复制一份创建临时文件,示例如下. 建立一个文本use ...

随机推荐

  1. (NO.00003)iOS游戏简单的机器人投射游戏成形记(十一)

    机器人发射子弹已经完成了,下面看看怎么给玩家设置障碍. 大家从上篇的图可以看到,在机器和篮筐直接有若干障碍物.我们先看如何实现它们. 打开SpriteBuilder,在Sprites文件夹中新建Sma ...

  2. C语言之任意进制的转换

    我们都知道转换进制是一个让人比较头疼的事情,下面我的代码不是最好的,也就仅仅是一个思路而已,至少我认为使用栈来进行进制转换是比较合适的一种方法,好了,不多叙述了. #include<stdio. ...

  3. Linux 学习笔记_12_文件共享服务_3_NFS网络文件服务

    NFS网络文件服务 NFS---- Network File System 用于UNIX/Linux[UNIX类操作系统]系统间通过网络进行文件共享,用户可以把网络中NFS服务器提供的共享目录挂载到本 ...

  4. java缓存系统

    第一版 package cache; import java.util.HashMap; import java.util.Map; public class Cache1 { private Map ...

  5. Graph Cut and Its Application in Computer Vision

    Graph Cut and Its Application in Computer Vision 原文出处: http://lincccc.blogspot.tw/2011/04/graph-cut- ...

  6. 谈谈java虚拟机

    本文可作为北京圣思元深入java虚拟机的课堂笔记. 先看一个令人dan teng的面试题 public class Singleton { public static Singleton s=new ...

  7. Shell编程入门(第二版)(下)

    ... ... command n done #select把关键字中的每一项做成类似表单,以交互的方式执行do和done之间的命令 示例-select.sh [python] view plainc ...

  8. utl_file包的使用

    首先看一下oracle 脚本 /* # $Header: HTMomse12.sql 12.0.4 20121015 Support $ #+============================= ...

  9. Linux系统下常用的快捷键

    快捷键 ctrl +  shift + '+'   将当前的终端放大 ctrl +  '-'           将当前的终端放小 ctrl +  l             清屏 ctrl +  u ...

  10. obj-c编程06:反射与元编程初步

    我们知道对于现如今的动态语言比如ruby而言,反射和元编程以及支持的非常灵活了,你完全可以跳过常规的手段,而利用反射来查询或调用对象的私有方法.而obj-c对反射的支持略显小繁琐,而且在开了ARC后同 ...