博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AE 打开各种格式文件
阅读量:5768 次
发布时间:2019-06-18

本文共 6369 字,大约阅读时间需要 21 分钟。

// <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;

        }

        /// <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;

        }

转载于:https://www.cnblogs.com/linhugh/archive/2012/04/10/2440345.html

你可能感兴趣的文章
mysql
查看>>
2012年电信业八大发展趋势
查看>>
Web日志安全分析工具 v2.0发布
查看>>
JS重载
查看>>
python2和python3同安装在Windows上,切换问题
查看>>
php加速工具xcache的安装与使用(基于LNMP环境)
查看>>
android超链接
查看>>
redhat tomcat
查看>>
统计数据库大小
查看>>
IO流的学习--文件夹下文件的复制
查看>>
第十六章:脚本化HTTP
查看>>
EXCEL表中如何让数值变成万元或亿元
查看>>
Cisco PIX防火墙的安装流程
查看>>
配置系列:ssm中applicationContext-mybatis.xml的简单配置
查看>>
mysql或者mariadb备份脚本
查看>>
extundelete恢复文件
查看>>
电池温度检测原理和示例代码
查看>>
Linux服务器性能评估与优化、监控利器---dstat应用
查看>>
hdu 2842 Chinese Rings 矩阵快速幂
查看>>
Powershell进阶学习(4) Powershell强大的利器“管道”
查看>>