ArcEngine创建内存FeatureClass

创建内存FeatureClass的方式有很多种 

最简单的一种就是根据模板要素图层的FeatureClass的IFields创建

这样创建创建的内存FeatureClass得需要模板要素图层得IFields属性   如果模板图层是polygon那么内存FeatueClass也是

比如:

        public static IFeatureClass CreateMemoryFeatureClass(IFields pFields, string name = "Temp")
        {
            // 创建内存工作空间  
            IWorkspaceFactory pWorkspaceFactory = new InMemoryWorkspaceFactoryClass();
            IWorkspaceName pWorkspaceName = pWorkspaceFactory.Create("", name, null, 0);
            IName pName = (IName)pWorkspaceName;
            IWorkspace pWorkspace = (IWorkspace)pName.Open();
            //创建内存要素类  
            IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
            IFeatureClass pFeatureClass = pFeatureWorkspace.CreateFeatureClass(name, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
            return pFeatureClass;
        }

上面的方法必须需要一个模板图层来创建不够灵活  下面用官方提供的例子创建内存FeatureClass

注意:下面暂时只能创建面要素内存图层   点和线图层需要修改geometry字段类型

       public static IFeatureClass CreateMemoryFeatureClass(string name = "Temp")
        {
            // 创建内存工作空间  
            IWorkspaceFactory pWorkspaceFactory = new InMemoryWorkspaceFactoryClass();
            IWorkspaceName pWorkspaceName = pWorkspaceFactory.Create("", name, null, 0);
            IName pName = (IName)pWorkspaceName;
            IWorkspace pWorkspace = (IWorkspace)pName.Open();
            IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
            //UID
            UID CLSID = new UIDClass();
            CLSID.Value = "esriGeoDatabase.Feature";
            IFields pFields = null;
            IObjectClassDescription objectClassDescription = new FeatureClassDescriptionClass();
            //创建必须的字段
            pFields = objectClassDescription.RequiredFields;
            //对字段进行检查
            IFieldChecker fieldChecker = new FieldCheckerClass();
            IEnumFieldError enumFieldError = null;
            IFields validatedFields = null;
            fieldChecker.ValidateWorkspace = (IWorkspace)pWorkspace;
            fieldChecker.Validate(pFields, out enumFieldError, out validatedFields);
            IFeatureClass pFeatureClass = pFeatureWorkspace.CreateFeatureClass(name, validatedFields, CLSID, null, esriFeatureType.esriFTSimple, "SHAPE", "");
            return pFeatureClass;
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值