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 ...
随机推荐
- Java进阶(二十四)Java List集合add与set方法原理简介
Java List集合add与set方法原理简介 add方法 add方法用于向集合列表中添加对象. 语法1 用于在列表的尾部插入指定元素.如果List集合对象由于调用add方法而发生更改,则返回 tr ...
- Android必知必会--NinePatch图片制作
本文为CSDN学院免费课程<NinePatch图片制作从入门到精通>的笔记,建议新手先观看视频,整理此笔记是为了便于自己复习,有NinePatch基础的朋友可以直接观看第四部分.--[转载 ...
- spring揭秘 读书笔记 六 bean的一生
我们知道,Spring容器具有对象的BeanDefinition来保存该对象实例化时需要的数据. 对象通过container.getBean()方法是才会初始化该对象. BeanFactory 我们知 ...
- android 开源图表库MPChart最简单使用方法示例教程Demo--折线图 柱状图
转载请注明本文出处:http://blog.csdn.net/wingichoy/article/details/50428246 MPChart是android上一款强大的图表开源库,他可以轻松的绘 ...
- 2、Libgdx配置你的开发环境(Eclipse,Intellij IDEA,NetBeans)
Libgdx 项目使用 Gradle管理依赖,构建过程和IDE整合.这使得你可以使用你喜欢的开发环境开发你的应用.不要提交跟IDE的特定文件到你的源码控制系统中. 配置Eclipse 要想通过Ecli ...
- 【Android 应用开发】分析各种Android设备屏幕分辨率与适配 - 使用大量真实安卓设备采集真实数据统计
.主要是为了总结一下 对这些概念有个直观的认识; . 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/198 ...
- 使用GDAL工具对FY3系列卫星数据进行校正
本文档主要对如何使用GDAL提供的工具对FY3系列卫星数据进行校正处理.FY3系列卫星提供的数据一般是以HDF5格式下发,一个典型的FY3A和FY3B的数据文件名如下: FY3A_MERSI_GBAL ...
- Git添加文件改动时出错
原来的主文件夹中替换了3个子文件夹,每个子文件夹有若干同名文件,总共替换了大概200多个文件吧. 然后在git主文件夹中使用git add .指令出现如下错误: apple@kissAir: iOS$ ...
- Android官方技术文档翻译——IntelliJ 项目迁移
本文译自Android官方技术文档<Migrating from IntelliJ Projects>,原文地址:http://tools.android.com/tech-docs/ne ...
- Java基本数据类型和长度
转自:http://lysongfei.iteye.com/blog/602546 java数据类型 字节 表示范围 byte(字节型) 1 -128-127 short(短整型 ...