http://blog.sina.com.cn/s/blog_7a3fc90501016qrg.html

/// <summary>
/// 打开ShapeFile文件
/// </summary>
/// <param name="filePath">文件路径</param>
/// <param name="fileName">文件名</param>
/// <returns>IFeatureClass</returns>
public IFeatureClass GetShpFile(string filePath, string fileName)
{
IFeatureWorkspace featureWorkspace;
IFeatureClass featureClass;

featureWorkspace = GetShapeWorkspace(filePath) as IFeatureWorkspace;

try
{
featureClass = featureWorkspace.OpenFeatureClass(fileName);
}
catch
{
featureClass = null;
}

ReleaseAE.ReleaseAEObject(featureWorkspace);

return featureClass;
}

Coverage

Coverage是ArcInfo workstation的原生数据格式。该格式是基于文件夹存储的,是因为在windows资源管理器下,它的空间信息和属性信息是分别存放在两个文件夹里。coverage是一个非常成功的早期地理数据模型,二十多年来深受用户欢迎,很多早期的数据都是coverage格式的。ESRI不公开coverage的数据格式,但是提供了coverage格式转换的一个交换文件(interchange file,即E00),并公开数据格式。但是ESRI为推广其第三代数据模型geodatabase,从ArcGIS 8.3版本开始,屏蔽了对coverage的编辑功能。如果需要使用coverage格式的数据,可以安装ArcInfo workstation,或者将coverage数据转换为其他可编辑的数据格式。Coverage是一个集合,它可以包含一个或多个要素类。 Coverage数据的工作空间也是它所在的文件夹;由于Coverage可以包含多个要素类,得到工作空间后在打开具体的要素类时可以用'Coverage名称:要素类名称',例如下面代码中的'basin:polygon'。
IWorkspaceFactory pFactory = new ArcInfoWorkspaceFactoryClass();
IWorkspace pWorkspace = pFactory.OpenFromFile(@'D:\ArcTutor\TopologyData', 0);
IFeatureWorkspace pFeatWorkspace = pWorkspace as IFeatureWorkspace;
IFeatureClass pFeatureClass = pFeatWorkspace.OpenFeatureClass('basin:polygon');

/// <summary>
/// 打开Raster文件(如果数据格式为是ESRI GRID,fileName不带后缀,若为tiff则带后缀.tif)
/// </summary>
/// <param name="filePath">文件路径</param>
/// <param name="fileName">文件名</param>
/// <returns>IRaster</returns>
public IRaster GetRasterFile(string filePath, string fileName)
{
IRasterWorkspace2 rasterWorkspace;
IRasterDataset rasterDataSet;
IRasterLayer rasterLayer;
IRaster raster;

rasterWorkspace = GetRasterWorkspace(filePath) as IRasterWorkspace2;

try
{
rasterDataSet = rasterWorkspace.OpenRasterDataset(fileName);

rasterLayer = new RasterLayerClass();
rasterLayer.CreateFromDataset(rasterDataSet);

raster = rasterLayer.Raster;

//ReleaseAE.ReleaseAEObject(rasterDataSet);
//ReleaseAE.ReleaseAEObject(rasterLayer);
}
catch
{
raster = null;
}

ReleaseAE.ReleaseAEObject(rasterWorkspace);

return raster;
}

/// <summary>
/// 打开PersonalGeodatabase里的数据要素
/// </summary>
/// <param name="mdbFile">mdb文件(带后缀.mdb)</param>
/// <param name="featureName">要素名</param>
/// <returns></returns>
public IFeatureClass GetPersonalGeodatabase(string mdbFile, string featureName)
{
IFeatureWorkspace featureWorkspace;
IFeatureClass featureClass;

workspaceFactory = new AccessWorkspaceFactoryClass();
featureWorkspace = workspaceFactory.OpenFromFile(mdbFile, 0) as IFeatureWorkspace;
featureClass = featureWorkspace.OpenFeatureClass(featureName);

ReleaseAE.ReleaseAEObject(featureWorkspace);
ReleaseAE.ReleaseAEObject(workspaceFactory);

return featureClass;
}

/// <summary>
/// 打开FileGeodatabase里的数据要素
/// </summary>
/// <param name="gdbFile">gdb文件</param>
/// <param name="featureName">要素名</param>
/// <returns></returns>
public IFeatureClass GetFileGeodatabase(string gdbFile, string featureName)
{
IFeatureWorkspace featureWorkspace;
IFeatureClass featureClass;

workspaceFactory = new FileGDBWorkspaceFactoryClass();
featureWorkspace = workspaceFactory.OpenFromFile(gdbFile, 0) as IFeatureWorkspace;
featureClass = featureWorkspace.OpenFeatureClass(featureName);

ReleaseAE.ReleaseAEObject(featureWorkspace);
ReleaseAE.ReleaseAEObject(workspaceFactory);

return featureClass;
}

/// <summary>
/// 打开TIN文件
/// </summary>
/// <param name="tinFile">文件路径</param>
/// <param name="fileName">文件名</param>
/// <returns>Tin</returns>
public ITin GetTinFile(string tinFile, string fileName)
{
ITinWorkspace pTinWorkspace;
ITin pTin;
workspaceFactory = new TinWorkspaceFactoryClass();
pTinWorkspace = workspaceFactory.OpenFromFile(tinFile, 0) as ITinWorkspace;
pTin = pTinWorkspace.OpenTin(fileName);

ReleaseAE.ReleaseAEObject(pTinWorkspace);
ReleaseAE.ReleaseAEObject(workspaceFactory);

return pTin;
}

/// <summary>
/// 打开CAD文件(featurename要带扩展名)
/// </summary>
/// <param name="cadFile">文件路径</param>
/// <param name="featureName">文件名</param>
/// <returns>featureClass</returns>
//public IFeatureClass GetCADFile(string cadFile, string featureName)
//{
// //IFeatureWorkspace featureWorkspace;
// //IFeatureClass featureClass;

// //workspaceFactory = new CadWorkspaceFactoryClass();
// //featureWorkspace = workspaceFactory.OpenFromFile(cadFile, 0) as IFeatureWorkspace;
// //featureClass = featureWorkspace.OpenFeatureClass(featureName);
// //return featureClass;
//}

/// <summary>
/// 打开数据表格
/// </summary>
/// <param name="connectionString">连接数据库字符串</param>
/// <param name="tableName">表名</param>
/// <returns>table</returns>
public ITable GetRDBMS(string connectionString, string tableName)
{
IFeatureWorkspace featureWorkspace;

workspaceFactory = new OLEDBWorkspaceFactoryClass();
IPropertySet pPropset = new PropertySetClass();
ITable pTable;
pPropset.SetProperties("CONNECTSTRING", connectionString);
featureWorkspace = workspaceFactory.Open(pPropset,0) as IFeatureWorkspace;
pTable = featureWorkspace.OpenTable(tableName);

ReleaseAE.ReleaseAEObject(featureWorkspace);
ReleaseAE.ReleaseAEObject(pPropset);

return pTable;
}

/// <summary>
/// 创建内存工作空间Name
/// </summary>
/// <param name="workspacename">工作空间名称</param>
/// <returns>工作空间Name</returns>
public IWorkspaceName CreatMemoryWorkspaceName(string workspacename)
{
IWorkspaceName workspaceName;

workspaceFactory = new InMemoryWorkspaceFactoryClass();

workspaceName = workspaceFactory.Create("d:\", workspacename, null, 0);

ReleaseAE.ReleaseAEObject(workspaceFactory);

return workspaceName;
}

/// <summary>
/// 创建内存工作空间
/// </summary>
/// <param name="workspacename">工作空间名称</param>
/// <returns>工作空间类型IWorkspace </returns>
public IWorkspace CreatMemoryWorkspace(string workspacename)
{
IWorkspaceName workspaceName;
IName name;
IWorkspace workspace;

workspaceName = CreatMemoryWorkspaceName(workspacename);

name = workspaceName as IName;
name.NameString = workspacename;
workspace = name.Open() as IWorkspace;

ReleaseAE.ReleaseAEObject(workspaceName);
ReleaseAE.ReleaseAEObject(name);

return workspace;
}

/// <summary>
/// 创建本地磁盘矢量工作空间
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public IWorkspace GetShapeWorkspace(string filePath)
{
IWorkspace workspace;

workspaceFactory = new ShapefileWorkspaceFactoryClass();

workspace = workspaceFactory.OpenFromFile(filePath, 0);

ReleaseAE.ReleaseAEObject(workspaceFactory);
workspaceFactory = null;

return workspace;
}

public IWorkspaceName GetShapeWorkspaceName(string spaceName)
{
IWorkspaceName workspaceName;

workspaceFactory = new ShapefileWorkspaceFactoryClass();

workspaceName = workspaceFactory.Create(Path.GetTempPath(), spaceName, null, 0);

ReleaseAE.ReleaseAEObject(workspaceFactory);

return workspaceName;
}

/// <summary>
/// 创建本地磁盘栅格工作空间
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public IWorkspace GetRasterWorkspace(string filePath)
{
IWorkspace workspace;

workspaceFactory = new RasterWorkspaceFactoryClass();
workspace = workspaceFactory.OpenFromFile(filePath, 0);

ReleaseAE.ReleaseAEObject(workspaceFactory);

return workspace;
}

AE 打开各种格式文件的更多相关文章

  1. 解决win7无法打开chm格式文件的问题

    解决win7无法打开chm格式文件的问题. (一).简单方法(本人用的这个) 1.打开chm2.win7提示安全问题3.chm无法显示内容4.关闭chm5.右键点击chm,点击“解除锁定”,ok  没 ...

  2. 如何将SolidWorks文件另存为.obj文件及如何打开.obj格式文件

    原网站:http://fans.solidworks.com.cn/forum.php?mod=viewthread&tid=40238) OBJ文件是Alias Wavefront公司为它的 ...

  3. 怎样打开.jar格式文件,怎样运行.jar格式文件

    当时第一次看到.jar文件不知道是什么鬼,以为是压缩包,直接就解压了,但是并没有什么用.所以在下为大家详细介绍如何打开.jar文件以及如何运行.jar文件.什么是.jar文件,简单的说就是java压缩 ...

  4. mac打开.caj格式文件

    以为用mac后使用会变得更方便些,写毕设时终于派上用场,可惜啊,mac竟然打不开.caj文件,这意味着什么?相信所有在做毕设的小伙伴们都能懂其中的凄凉.特别是硕士或博士的论文,你得从知网上下上百篇的文 ...

  5. excel打开txt格式文件

  6. 页面打开pdf格式文件的方法

    <embed width=500 height=300 fullscreen=yes src="1.pdf" />

  7. xdg-open命令智能打开各种格式的文件

    在linux中,通常用命令行打开文本文件,比如用命令gedit.more.cat.vim.less.但当需要打开其他格式文件时,比如pdf.jpg.mp3格式文件,咱们通常做法是进入到文件所在的目录, ...

  8. WinDbg调试DMP格式文件

    前言:WinDbg是微软开发的免费源代码级的调试工具.WinDbg可以用于Kernel模式调试和用户模式调试,还可以调试Dump文件.本文的讨论是在安装了Debugging Tools for Win ...

  9. .ipynb格式文件

    ipynb,即ipython notebook,需要用ipython notebook打开,IPython Notebook是web based IPython封装,但是可以展现富文本,使得整个工作可 ...

随机推荐

  1. JS的三种弹框

    <script type="text/javascript"> /*第一种*/ function ale(){ alert("这是第一种");} / ...

  2. Redis系列(三)—— 订阅/发布

    Redis 订阅/发布 参考:http://www.cnblogs.com/mushroom/p/4470006.html,http://www.tuicool.com/articles/ABry2a ...

  3. Linux查看BIOS信息

    http://www.linuxde.net/2013/02/12499.html

  4. QQ一键登录功能的实现过程

    QQ登录的思路: 当qq登陆成功后,QQ会给我们返回一个唯一的用户标识:openId,当用户授权QQ时,判断 if(已经有openId){ 跳转到登陆后的页面. }else if(没有openId){ ...

  5. ipc之消息队列

    消息队列以链表的方式将消息存储于内核中,调用msgsnd,msgrcv函数往消息队列里面投送,取出指定的消息. 创建一个消息队列 生成一个消息队列或者获取已有消息队列id #include <s ...

  6. mysql忘记密码的重置方法

    1. 编辑mysql主配置文件 my.cnfvim /etc/my.cnf在[mysqld]字段下的位置添加参数skip-grant保存退出2. 重启数据库服务service mysqld resta ...

  7. [转]jquery Fancybox丰富的弹出层效果

    本文转自:http://www.helloweba.com/view-blog-65.html Fancybox是一款优秀的jquery插件,它能够展示丰富的弹出层效果.前面我们有文章介绍了facyb ...

  8. 使用LVS实现负载平衡之Windows Server 2008配置

    LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目之一.承载于 II ...

  9. UESTC 923 稳住GCD DP + GCD

    定义:dp[i][j] 表示 在前i个数中,使整个gcd值为j时最少取的数个数. 则有方程: gg = gcd(a[i],j) gg == j : 添加这个数gcd不变,不添加,  dp[i][j] ...

  10. Loadrunner:场景运行较长时间后报错:Message id [-17999] was not saved - Auto Log cache is too small to contain the message.

    loadrunner运行时间较长后,跑数据过程老是失败,有如下error: Message id [-17999] was not saved - Auto Log cache is too smal ...