原文 ArcEngine中打开各种数据源(WorkSpace)的连接(SDE、personal/File、ShapeFile、CAD数据、影像图、影像数据集)

ArcEngine 可以接受多种数据源。在开发过程中我们使用了如下几种数据源

1.企业数据库(SDE

企业数据库需要使用SDE来管理,所以需要使用SDE的Workspace来表示连接。在AE接口中,Workspace是由Factory打开的。代码如下: // //准备连接参数

ESRI.ArcGIS.esriSystem.IPropertySet pPropSet=new PropertySetClass();

pPropSet.SetProperty("server","服务器机器名" );

pPropSet.SetProperty("instance","SDE运行的端口号");

pPropSet.SetProperty("user","用户名");

pPropSet.SetProperty("password","口令" );

pPropSet.SetProperty("version","版本");

SdeWorkspaceFactory sdeWkspFact=new SdeWorkspaceFactoryClass();

IFeatureWorkspace pFeaWksp=(IFeatureWorkspace)sdeWkspFact.Open(pPropSet,0);

其中唯一需要解释的可能就是版本(version).对于没有使用版本或者第一次连接(没有建立空间数据库,当然没有版本了). 该处使用sde.DEFAULT这个版本。这是默认的版本。

iPropertySet:: setProperty

public void setProperty(string name,object value)

2.个人数据库(PersonalGeodatabaseFileGeodatabase)

ArcEngine中个人数据库为Access。

string filePath="E:\\tt.mdb";

AccessWorkspaceFactory fac=new AccessWorkspaceFactoryClass();

IFeatureWorkspace space=(IFeatureWorkspace)fac.OpenFromFile(filePath,0); 这是用的最多的一种方式.

如果是FileGeodatabasse,则将

FileGDBWorkspaceFactory pWSF = New FileGDBWorkspaceFactory;

IFeatureWorkspace pWS1= pWSF.OpenFromFile(sPath, 0);

如果用IPropertySet。如下:

//Personal Geodatabase e.g., database = "C:\\myData\\mypGDB.mdb"

public IWorkspace open_pGDB_Workspace(string database)

{

IPropertySet propertySet = new PropertySetClass();

propertySet.SetProperty("DATABASE", database);

IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();

return workspaceFactory.Open(propertySet, 0);

}

3.Shapefile文件

Shapefile和Access的打开方式有一点相同。也有差异。

//这是Shape所在的目录(注意:是目录)

string spacePath="E:\\shapefile";

IShapefileWorkspaceFactory fac=new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace space=(IFeatureWorkspace)fac.OpenFromFile(spacePath,0);

IFeatureClass fc=space.openFeatureClass(“china”);

4.AutoCAD dwg文件

AutoCAD文件和一般的ESRI格式不同。所以代码会有一点点奇怪。假设有一个dwg文件为E:\\cad\\107.dwg 下面是打开的代码:

CadWorkspaceFactoryClass fac=new CadWorkspaceFactoryClass ();

String filePath="E:\\cad";

IFeatureWorkspace space=fac.OpenFromFile(filePath,0) as IFeatureWorkspace ;

下面是打开FeatureClass的代码:

//线

IFeatureClass polyline =space.OpenFeatureClass("107.dwg:Polyline");

IFeatureLayer layer=new CadFeatureLayerClass ();

layer.FeatureClass =polyline;

//点

IFeatureClass point=space.OpenFeatureClass ("107.dwg:Point");

layer=new CadFeatureLayerClass ();

layer.FeatureClass =point;

//面

IFeatureClass polygon=space.OpenFeatureClass ("107.dwg:Polygon");

layer=new CadFeatureLayerClass();

layer.FeatureClass =polygon;

//注记

IFeatureClass anno=space.OpenFeatureClass ("107.dwg:Annotation"); layer=new CadAnnotationLayerClass();

layer.FeatureClass =anno;

5.影像图文件

//文件路径

string filePath="E:\\image\\117.tif";

IRasterLayer rasterLayer=new RasterLayerClass();

rasterLayer.CreateFromFilePath(filePath );

6.数据库中的影像数据集。

//数据库连接

IWorkspace space=OpenSpace();

//打开数据库的方式

IRasterWorkspaceEx rasterSpace=(IRasterWorkspaceEx)space;

IRasterDataset rasterDataset=rasterSpace.OpenRasterDataset (setName.Name );

IRasterLayer rasLayer=new RasterLayerClass();

rasLayer.CreateFromDataset(rasterDataset);

IRasterWorkspaceEx:提供创建和打开栅格目录或栅格数据集的方法。

但是IRasterWorkspaceEx,IRasterWorkspace, IRasterWorkspace2都有OpenRasterDataset。IRasterWorkspace经常也可用于打开栅格数据,如:

pWorkspaceFactory = new RasterWorkspaceFactoryClass();

pRasterWorkspace = (IRasterWorkspace)pWorkspaceFactory.OpenFromFile(filePath, 0);

IRasterDataset pRasterDataset = (IRasterDataset)pRasterWorkspace.OpenRasterDataset(fileName);

IRasterLayer pRasterLayer = new RasterLayerClass();

pRasterLayer.CreateFromDataset(pRasterDataset);

[转] ArcEngine中打开各种数据源(WorkSpace)的连接的更多相关文章

  1. ArcEngine中打开各种数据源(WorkSpace)的连接(转)

    ArcEngine中打开各种数据源(WorkSpace)的连接 (SDE.personal/File.ShapeFile.CAD数据.影像图.影像数据集) ArcEngine 可以接受多种数据源.在开 ...

  2. ArcEngine中打开各种数据源(WorkSpace)的连接http://www.cnblogs.com/feilong3540717/archive/2011/08/07/2129906.html

    ArcEngine中打开各种数据源(WorkSpace)的连接 ArcEngine中打开各种数据源(WorkSpace)的连接 (SDE.personal/File.ShapeFile.CAD数据.影 ...

  3. ArcEngine中打开各种数据源(WorkSpace)的连接

    (SDE.personal/File.ShapeFile.CAD数据.影像图.影像数据集) ArcEngine 可以接受多种数据源.在开发过程中我们使用了如下几种数据源 1.企业数据库(SDE) 企业 ...

  4. ArcEngine中打开各种数据源(WorkSpace)的连接 (SDE、personal/File、ShapeFile、CAD数据、影像图、影像数据集)

    ArcEngine 可以接受多种数据源.在开发过程中我们使用了如下几种数据源 1.企业数据库(SDE) 企业数据库需要使用SDE来管理,所以需要使用SDE的Workspace来表示连接.在AE接口中, ...

  5. C#+ArcEngine中com对象的释放问题

    1.问题描述 最近在写C#下AE的开发,在循环获取数据并修改时碰到了两个问题"超出系统资源"和"超出打开游标最大数":在网上看了一些资料,发现都是说在循环中没有 ...

  6. Spring MVC 使用tomcat中配置的数据源

    Spring MVC 使用tomcat中配置的数据源 配置tomcat数据源 打开tomcat目录下的conf目录,编辑sever.xml目录.在<GlobalNamingResources&g ...

  7. 在ArcEngine中使用Geoprocessing工具-执行工具

    转自原文在ArcEngine中使用Geoprocessing工具-执行工具 来解析一下Geoprocessor类的Execute方法,他有两种重载,Execute(IGPProcess, ITrack ...

  8. ArcEngine中最短路径的实现

    原文 ArcEngine中最短路径的实现 最短路径分析属于ArcGIS的网络分析范畴.而ArcGIS的网络分析分为两类,分别是基于几何网络和网络数据集的网络分析.它们都可以实现最短路径功能.下面先介绍 ...

  9. SQL Server中配置ODBC数据源

    单击“开始→windows系统→控制面板”,打开控制面板 单击“管理工具→ODBC数据源(32位)”打开ODBC数据源配置对话框 在数据源配置对话框中单击“系统DSN”选项卡下的“添加”按钮,创建数据 ...

随机推荐

  1. @properties指针说明

    在iOS开发过程中,属性的定义往往与retain, assign, copy有关,我想大家都很熟悉了,在此我也不介绍,网上有很多相关文章. 现在我们看看iOS5中新的关键字strong, weak, ...

  2. EXTJS 4.2 资料 控件之Grid 那些事

    最近在学习Extjs4.2 ,积累文章,看得不错,再此留年: //表格数据最起码有列.数据.转换原始数据这3项 Ext.onReady(function(){ //定义列 var columns = ...

  3. UITableView自定义单元格

    随手笔记: RootViewController代码 #import "RootViewController.h" #import "AddressContact.h&q ...

  4. 在 Windows 8 或 8.1 上安装 .NET Framework 3.5 安装错误:0x800f0906、0x800F081F

    昨天给一天新装Windows 8.1的PC装.NET Framework 3.5 发现联网速度很慢,并且在长久等待过后直接报错了:0x800f0906 经过Bing,发现了解决方案: 如果根据需要安装 ...

  5. 2326: [HNOI2011]数学作业 - BZOJ

    首先是DP,分段DP(按位数讨论) 然后每一段构造出它对应的矩阵,用矩阵快速幂加速 type matrix=..,..]of int64; var n,m:int64; a,b,c,d:matrix; ...

  6. 破解之API断点法

    上回给大家做的破解教程,地址是http://www.52pojie.net/thread-52719-1-1.html,用的是“调用堆栈”方法.今天给新手提供另一种方法“API函数断点”,这种方法要求 ...

  7. HeadFirst设计模式之迭代器模式

    一. 1.迭代器模式是对遍历集合元素的抽象 2.The Iterator Pattern provides a way to access the elements of an aggregate o ...

  8. JavaScript基本程序结构

    条件判断 JavaScript使用if () { ... } else { ... }来进行条件判断.例如,根据年龄显示不同内容,可以用if语句实现如下: var age = 20; if (age ...

  9. POJ2253——Frogger(Floyd变形)

    Frogger DescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fi ...

  10. 最短路径算法之四——SPFA算法

    SPAF算法 求单源最短路的SPFA算法的全称是:Shortest Path Faster Algorithm,该算法是西南交通大学段凡丁于1994年发表的. 它可以在O(kE)的时间复杂度内求出源点 ...