arcEngine classic code(3)

简介:

1. 在ArcEngine中创建内存图层

 

arcEngine9.2中新增了一个新的特征,允许创建内存工作空间。当你需要一个这样的图层时,这个图层的属性数据或者几何数据需要频繁的更新,而又不希望因此而带来效率上的问题,你就可以考虑使用内存图层。
        内存图层的创建分为五步:
      1、设置属性字段
      2、设置空间参考和几何字段
      3、创建内存工作空间
      4、在内存工作空间中创建特征类
      5、创建特征图层,并将上一步创建的特征类设置为这个特征的图层的特征类

请看以下完整的示例代码

        ///


        /// 在内存中创建图层
        ///

        /// 
        /// 
        /// 
        /// 
        /// 
        /// IfeatureLayer
        public static IFeatureLayer CreateFeatureLayerInmemeory(string DataSetName, string AliaseName, ISpatialReference SpatialRef, esriGeometryType GeometryType, IFields PropertyFields)
        {
            IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();
            ESRI.ArcGIS.Geodatabase.IWorkspaceName workspaceName = workspaceFactory.Create("", "MyWorkspace", null, 0);
            ESRI.ArcGIS.esriSystem.IName name = (IName)workspaceName;
            ESRI.ArcGIS.Geodatabase.IWorkspace inmemWor = (IWorkspace)name.Open();

            IField oField = new FieldClass();
            IFields oFields = new FieldsClass();
            IFieldsEdit oFieldsEdit = null;
            IFieldEdit oFieldEdit = null;
            IFeatureClass oFeatureClass = null;
            IFeatureLayer oFeatureLayer = null;

            try
            {
                oFieldsEdit = oFields as IFieldsEdit;
                oFieldEdit = oField as IFieldEdit;

                for (int i = 0; i < PropertyFields.FieldCount; i++)
                {
                    oFieldsEdit.AddField(PropertyFields.get_Field(i));
                }

                IGeometryDef geometryDef = new GeometryDefClass();
                IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
                geometryDefEdit.AvgNumPoints_2 = 5;
                geometryDefEdit.GeometryType_2 = GeometryType;
                geometryDefEdit.GridCount_2 = 1;
                geometryDefEdit.HasM_2 = false;
                geometryDefEdit.HasZ_2 = false;
                geometryDefEdit.SpatialReference_2 = SpatialRef;

                oFieldEdit.Name_2 = "SHAPE";
                oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                oFieldEdit.GeometryDef_2 = geometryDef;
                oFieldEdit.IsNullable_2 = true;
                oFieldEdit.Required_2 = true;
                oFieldsEdit.AddField(oField);

                oFeatureClass = (inmemWor as IFeatureWorkspace).CreateFeatureClass(DataSetName, oFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                (oFeatureClass as IDataset).BrowseName = DataSetName;

                oFeatureLayer = new FeatureLayerClass();
                oFeatureLayer.Name = AliaseName;
                oFeatureLayer.FeatureClass = oFeatureClass;
            }
            catch
            {
            }
            finally
            {
                try
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oField);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oFields);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oFieldsEdit);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oFieldEdit);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(name);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(workspaceFactory);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(workspaceName);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(inmemWor);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oFeatureClass);
                }
                catch { }

                GC.Collect();
            }
            return oFeatureLayer;
        }

      返回来的这个特征图层就是我们所需要的结果,操作这个内存图层方式和操作物理图层方式完全一样。




    本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/xiexiaokui/archive/2008/07/25/1251672.html,如需转载请自行联系原作者

相关文章
|
8月前
|
JavaScript 前端开发 API
Visual Studio Code Active File in StatusBar 扩展以及 Extension API 概述
Visual Studio Code Active File in StatusBar 扩展以及 Extension API 概述
38 0
|
C语言 Android开发 Windows
解决windows下eclipse创建project时没有include导致出现“unresolved inclusion: &lt;stdio.h&gt;”错误的方法
解决windows下eclipse创建project时没有include导致出现“unresolved inclusion: &lt;stdio.h&gt;”错误的方法
解决windows下eclipse创建project时没有include导致出现“unresolved inclusion: &lt;stdio.h&gt;”错误的方法
clion中cpp文件显示This file does not belong to any project ,code insight features might not work【解决方案】
clion中cpp文件显示This file does not belong to any project ,code insight features might not work【解决方案】
clion中cpp文件显示This file does not belong to any project ,code insight features might not work【解决方案】
|
7月前
|
存储 安全 程序员
2000条你应知的WPF小姿势 基础篇<34-39 Unhandled Exceptions和Resource>
2000条你应知的WPF小姿势 基础篇<34-39 Unhandled Exceptions和Resource>
16 0
2000条你应知的WPF小姿势 基础篇<34-39 Unhandled Exceptions和Resource>
|
8月前
|
Go
SAP UI5 Smart Table 和 Smart Filter Bar 的联合使用方法介绍试读版
SAP UI5 Smart Table 和 Smart Filter Bar 的联合使用方法介绍试读版
38 0
|
8月前
|
XML 搜索推荐 数据格式
SAP UI5 Smart Table 和 Smart Filter Bar 的联合使用方法介绍
SAP UI5 Smart Table 和 Smart Filter Bar 的联合使用方法介绍
31 0
SAP UI5 Smart Table 和 Smart Filter Bar 的联合使用方法介绍试读版(1)
SAP UI5 Smart Table 和 Smart Filter Bar 的联合使用方法介绍试读版
SAP UI5 Smart Table 和 Smart Filter Bar 的联合使用方法介绍试读版(2)
SAP UI5 Smart Table 和 Smart Filter Bar 的联合使用方法介绍试读版
Visual Studio Code 保存代码时报Applying code action Organize Imports
Visual Studio Code 保存代码时报Applying code action Organize Imports
Visual Studio Code 保存代码时报Applying code action Organize Imports
|
开发框架 .NET
SAP Cloud for Customer CLR(Code List Restriction)的一种高级用法
SAP Cloud for Customer CLR(Code List Restriction)的一种高级用法
137 0
SAP Cloud for Customer CLR(Code List Restriction)的一种高级用法