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属性
浙公网安备 33010602011771号