• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
bobird的学习笔记
博客园    首页    新随笔    联系   管理    订阅  订阅
ArcEngine 设置字段的属性域IDomain
1、创建字段的属性域 IDomian。IDomain分为两类CodedValueDomainClass和RangeDomainClass。前者是用来设置枚举型值域的,后者用来设置连续的范围值域。两种属性域的创建方法见下面的例子。

public void IDomain_Example(IWorkspace workspace)
    {
        //The following example shows how the IDomain interface can be used to set properties on 
        //new RangeDomain and CodedValueDomain objects before they are added to the workspace using IDomain::Name ,
        //IDomain::Description , and other properties.
        IWorkspaceDomains workspaceDomains = (IWorkspaceDomains)workspace;

        //create new range domain
        IRangeDomain rangeDomain = new RangeDomainClass();
        rangeDomain.MinValue = 9;
        rangeDomain.MaxValue = 600000;

        //cast for the IDomain interface to set additional properties
        IDomain domain = (IDomain)rangeDomain;
        domain.FieldType = esriFieldType.esriFieldTypeDouble;
        domain.Name = "Area constraint";
        domain.Description = "Constrains the area of buildings";
        domain.MergePolicy = esriMergePolicyType.esriMPTAreaWeighted;
        domain.SplitPolicy = esriSplitPolicyType.esriSPTGeometryRatio;

        workspaceDomains.AddDomain(domain);
        domain = null;

        //create new coded value domain
        ICodedValueDomain codedValueDomain = new CodedValueDomainClass();
        codedValueDomain.AddCode("RES", "Residential");
        codedValueDomain.AddCode("COM", "Commercial");
        codedValueDomain.AddCode("IND", "Industrial");
        codedValueDomain.AddCode("BLD", "Building");
        //to remove an unwanted code from the domain
        //codedValueDomain.DeleteCode("BLD");

        //cast for the IDomain interface to set additional properties
        domain = (IDomain)codedValueDomain;
        domain.FieldType = esriFieldType.esriFieldTypeString;
        domain.Name = "Building Types";
        domain.Description = "Valid building type codes";
        domain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue;
        domain.SplitPolicy = esriSplitPolicyType.esriSPTDuplicate;

        workspaceDomains.AddDomain(domain);
 

        Console.WriteLine("Asking the domain if 'RES' is a member will return true: {0}", domain.MemberOf("RES"));
        Console.WriteLine("Asking the domain if 'ZZZ' is a member will return false: {0}", domain.MemberOf("ZZZ"));

        Console.WriteLine("Asking the domain for its type will return esriDomainType.esriDTCodedValue: {0}", domain.Type.ToString());      
    }

2. 设置字段的Domian属性

 

posted on 2013-07-03 15:56  bobird  阅读(1400)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3