public static List <CodedValue> GetCodedValueList( [NotNull] ICodedValueDomain domain, CodedValueSortOrder sortOrder = CodedValueSortOrder.Original) { Assert.ArgumentNotNull(domain, nameof(domain)); var list = new List <CodedValue>(domain.CodeCount); int codeCount = domain.CodeCount; for (var index = 0; index < codeCount; index++) { list.Add(new CodedValue(domain.Value[index], domain.Name[index])); } switch (sortOrder) { case CodedValueSortOrder.Original: break; case CodedValueSortOrder.Value: list.Sort(CompareCodedValues); break; case CodedValueSortOrder.Name: list.Sort(CompareCodedValueNames); break; default: throw new ArgumentOutOfRangeException(nameof(sortOrder)); } return(list); }
private string method_6(IFeature ifeature_0, int int_0) { try { IDomain domain = ifeature_0.Fields.get_Field(int_0).Domain; if (domain == null) { return(ifeature_0.get_Value(int_0).ToString()); } if (domain.Type != esriDomainType.esriDTCodedValue) { return(ifeature_0.get_Value(int_0).ToString()); } ICodedValueDomain domain2 = domain as ICodedValueDomain; int codeCount = domain2.CodeCount; for (int i = 0; i < codeCount; i++) { if (domain2.get_Value(i) == ifeature_0.get_Value(int_0)) { return(domain2.get_Name(i)); } } } catch { } return(""); }
/// <summary> /// Initializes a new instance of the <see cref="FieldLookupSubtypeDomain"/> class. /// </summary> /// <param name="objectClass">The object class.</param> /// <param name="fieldIndex">Index of the field.</param> public FieldLookupSubtypeDomain([NotNull] IObjectClass objectClass, int fieldIndex) : base(fieldIndex) { Assert.ArgumentNotNull(objectClass, nameof(objectClass)); IField field = objectClass.Fields.Field[fieldIndex]; var classSubtypes = (ISubtypes)objectClass; _subtypeFieldIndex = classSubtypes.SubtypeFieldIndex; IList <Subtype> subtypes = DatasetUtils.GetSubtypes(objectClass); foreach (Subtype subtype in subtypes) { ICodedValueDomain domain = (ICodedValueDomain)classSubtypes.Domain[subtype.Code, field.Name] ?? (ICodedValueDomain)field.Domain; Dictionary <object, string> namesByValue = GetCodedValueMap(domain); _displayValueMap.Add(subtype.Code, namesByValue); } // get default domain values _nameByValueDefaultDomain = GetCodedValueMap( (ICodedValueDomain)field.Domain); }
public string GetDomainDisplay(string domain, object domainValu) { List <String> listDomains = new List <string>(); IDataset dataset = (IDataset)GetWorkspace; IWorkspaceDomains2 domains = (IWorkspaceDomains2)dataset; ICodedValueDomain dom = null; try { dom = (ICodedValueDomain)domains.get_DomainByName(domain); for (int i = 0; i <= dom.CodeCount - 1; i++) { if (dom.get_Value(i).Equals(domainValu)) { return(dom.get_Name(i)); } } } catch (Exception ex) { //_log.Error("Ocorreu um problema ao tentar carregar os domínios do componente SegmentListComponent."); } finally { //if (domains != null) // Marshal.ReleaseComObject(domains); //if (dom != null) // Marshal.ReleaseComObject(dom); //Marshal.ReleaseComObject(dataset); } return(""); }
public static string GetDomainValueOfFieldValue(IFeatureClass pFeatureClass, string strFieldName, string strFieldValue) { string strValue = strFieldValue; try { // IDataset dataset = pFeatureClass as IDataset; //IWorkspace workspace = dataset.Workspace; // IWorkspaceDomains workspaceDomains = (IWorkspaceDomains)workspace; int indexfield = pFeatureClass.Fields.FindField(strFieldName); IField pField = pFeatureClass.Fields.get_Field(indexfield); IDomain requestDomain = pField.Domain; ICodedValueDomain codedValueDomain = (ICodedValueDomain)requestDomain; if (codedValueDomain != null) { for (int i = 0; i < codedValueDomain.CodeCount; i++) { string strTmpFieldValue = codedValueDomain.get_Value(i).ToString(); if (strTmpFieldValue.Equals(strFieldValue)) { strValue = codedValueDomain.get_Name(i); break; } } } } catch { } return(strValue); }
///// <summary> ///// 批量专题导出Excel ///// </summary> ///// <param name="pFeatureClass"></param> ///// <param name="listFileName"></param> ///// <param name="TypeName"></param> //public void BatchSubjectExport(IFeatureClass pFeatureClass, IList<string> listFileName, string TypeName, string fieldName) //{ // flag = 1; // result = folderBrowerDialog.ShowDialog(); // for (int i = 0; i < listFileName.Count; i++) // { // Export(pFeatureClass, listFileName[i], TypeName, fieldName); // } // flag = 0; //} ///// <summary> ///// 批量导出该行政去内各种类型Excel ///// </summary> ///// <param name="ListFeatureClass"></param> ///// <param name="VillageName">行政区名称</param> ///// <param name="fieldName">统计字段名称</param> //public void BatchStatisticalChart(IList<IFeatureClass> ListFeatureClass, string VillageName, string fieldName) //{ // flag = 1; // result = folderBrowerDialog.ShowDialog(); // for (int i = 0; i < ListFeatureClass.Count; i++) // { // ExportByFeartureClassName(ListFeatureClass[i], VillageName, fieldName); // } // flag = 0; //} ///// <summary> ///// 根据FeatureClass别名进行统计导出Excel表 ///// </summary> ///// <param name="pFeatureClass"></param> ///// <param name="VillageName"></param> ///// <param name="fieldName"></param> //private void ExportByFeartureClassName(IFeatureClass pFeatureClass, string VillageName, string fieldName) //{ // switch (pFeatureClass.AliasName) // { // case "DATASYS.DATONG_LDGH": // string fileName = VillageName + "镇(乡)林地规划统计表"; // Export(pFeatureClass, fileName, "林地类型", fieldName); // fileName = ""; // break; // case "DATASYS.DATONG_LYYDFB": // fileName = VillageName + "镇(乡)林业用地分布统计表"; // Export(pFeatureClass, fileName, "类型", fieldName); // fileName = ""; // break; // case "DATASYS.DATONG_BAOHU_DJ": // fileName = VillageName + "镇(乡)林地保护等级分布统计表"; // Export(pFeatureClass, fileName, "林地保护等级级别", fieldName); // fileName = ""; // break; // case "DATASYS.DATONG_ZDGNQ": // fileName = VillageName + "镇(乡)林地主导功能区分布统计表"; // Export(pFeatureClass, fileName, "主导功能区类型", fieldName); // fileName = ""; // break; // case "DATASYS.DATONG_LDLY": // fileName = VillageName + "镇(乡)林地利用现状统计表"; // Export(pFeatureClass, fileName, "林地利用现状类型", fieldName); // fileName = ""; // break; // case "DATASYS.DATONG_LDJG": // fileName = VillageName + "镇(乡)林地结构现状统计表"; // Export(pFeatureClass, fileName, "林地结构类型", fieldName); // fileName = ""; // break; // case "DATASYS.DATONG_ZHILIANG_DJ": // fileName = VillageName + "镇(乡)林地质量等级现状统计表"; // Export(pFeatureClass, fileName, "林地质量等级类型", fieldName); // fileName = ""; // break; // case "DATASYS.DATONG_LC": // fileName = VillageName + "镇(乡)林场统计表"; // Export(pFeatureClass, fileName, "林场名称", fieldName); // fileName = ""; // break; // } //} /// <summary> /// 得到属性域的值 /// </summary> /// <param name="TypeName">表字段名称</param> /// <param name="pFeatureClass">特征类</param> /// <returns>属性域字段</returns> private IList <string> GetDomainsName(string fieldName, IFeatureClass pFeatureClass) { IList <string> newList = new List <string>(); newList = listString; IDataset dataset = pFeatureClass as IDataset; IWorkspace workspace = dataset.Workspace; IWorkspaceDomains workspaceDomains = (IWorkspaceDomains)workspace; int indexField = pFeatureClass.Fields.FindField(fieldName); IField pField = pFeatureClass.Fields.get_Field(indexField); IDomain domain = pField.Domain; ICodedValueDomain codeDomain = (ICodedValueDomain)domain; for (int i = 0; i < codeDomain.CodeCount; i++) { for (int j = 0; j < listString.Count; j++) { if (listString[j] == codeDomain.get_Value(i).ToString()) { newList[j] = codeDomain.get_Name(i).ToString(); } } } return(newList); }
/// <summary> /// This method is responsible for translanting between coded domain names /// and their values, setting into UnderlyingObject the correct value. /// </summary> /// <remarks> /// Imagine a ICodedDomain like: /// 1 = "Alphanumeric" /// 2 = "Geographic" /// /// This method will aways set the value to 1 when passed /// "Alphanumeric" /// </remarks> /// <exception cref="ActiveRecrdAttributeException"></exception> /// <param name="wrapper"></param> /// <param name="propertyName"></param> /// <param name="displayValue"></param> /// <returns></returns> private static void SetDisplayValue(this IActiveRecord wrapper, FieldAttribute fieldAtt, string displayValue) { if (wrapper.UnderlyingObject == null) { FetchUnderlyingObject(wrapper); } if (!(fieldAtt is DomainFieldAttribute)) { throw new ActiveRecordAttributeException(wrapper.GetType(), "O atributo não é tipo domínio."); } DomainFieldAttribute domainField = fieldAtt as DomainFieldAttribute; ICodedValueDomain domain = wrapper.UnderlyingObject.Fields.get_Field(domainField.Index).Domain as ICodedValueDomain; if (domain == null) { throw new ActiveRecordAttributeException(wrapper.GetType(), "Não foi possível localizar o domínio."); } for (var i = 0; i <= domain.CodeCount - 1; i++) { if (domain.get_Name(i) == displayValue) { object codedValue = domain.get_Value(i); wrapper.UnderlyingObject.set_Value(domainField.Index, codedValue); } } }
//获得阀门的属性字段和信息 private void GetValves(IFeature pFeature, out string var1, out string var2, out string var3) { IFields pFields = pFeature.Fields; ISubtypes pWaterPtSubtypes = pFeatLayerValves.FeatureClass as ISubtypes; var1 = pFeature.get_Value(pFields.FindField("WATER_ID")).ToString(); var2 = pFeature.get_Value(pFields.FindField("PWV_TYPE")).ToString(); var3 = pFeature.get_Value(pFields.FindField("PWSHEETNO")).ToString(); IRowSubtypes pRowSubtypes = pFeature as IRowSubtypes; if (pRowSubtypes != null) { IDomain pDomain = pWaterPtSubtypes.get_Domain(pRowSubtypes.SubtypeCode, "PWV_TYPE"); if (pDomain != null) { ICodedValueDomain pCodedValDomain = pDomain as ICodedValueDomain; for (int i = 0; i <= pCodedValDomain.CodeCount - 1; i++) { if (pCodedValDomain.get_Value(i).ToString() == var2) { var2 = pCodedValDomain.get_Name(i).ToString(); } } } } }
private object GetFieldValueByIndex(IFeature feature, int index) { object obj = null; if (index == -1) { return(null); } IDomain domain = feature.Fields.get_Field(index).Domain; if (domain != null && domain.Type == esriDomainType.esriDTCodedValue) { ICodedValueDomain pCD = domain as ICodedValueDomain; for (int i = 0; i < pCD.CodeCount; i++) { if (object.Equals(pCD.get_Value(i), feature.get_Value(index))) { obj = pCD.get_Name(i); } } } else { obj = feature.get_Value(index).ToString(); } return(obj); }
//获得管线的属性字段和信息 private void GetWaterLineValue(out string var1, out string var2, out string var3, out string var4, out string var5) { IFields pFields = pFeatureWaterLine.Fields; var1 = pFeatureWaterLine.get_Value(pFields.FindField("WATER_ID")).ToString(); var2 = pFeatureWaterLine.get_Value(pFields.FindField("PIPEUSE_CODE")).ToString(); var3 = pFeatureWaterLine.get_Value(pFields.FindField("SHAPE_LENGTH")).ToString(); var4 = pFeatureWaterLine.get_Value(pFields.FindField("PWDIAM")).ToString(); var5 = pFeatureWaterLine.get_Value(pFields.FindField("PWMATERIAL")).ToString(); //根据子类型代码获得子类型名称 ISubtypes pWaterLineSubtypes = pFeatLayerWaterLines.FeatureClass as ISubtypes; IRowSubtypes pRowSubtypes = pFeatureWaterLine as IRowSubtypes; if (pRowSubtypes != null) { var2 = pWaterLineSubtypes.get_SubtypeName(pRowSubtypes.SubtypeCode); //获取属性域 IDomain pDomain = pWaterLineSubtypes.get_Domain(pRowSubtypes.SubtypeCode, "PWMATERIAL"); if (pDomain != null) { ICodedValueDomain pCodedValDomain = pDomain as ICodedValueDomain; for (int i = 0; i <= pCodedValDomain.CodeCount - 1; i++) { if (pCodedValDomain.get_Value(i) == var5) { var5 = pCodedValDomain.get_Name(i); } } } } }
public static string DecorateWhereClasuse(IFeatureClass fc) { string fValue = "2"; int index = GetIndex(fc, "Upordown"); if (index == -1) { return(""); } IDomain pDomain = fc.Fields.get_Field(index).Domain; if (pDomain != null && pDomain.Type == esriDomainType.esriDTCodedValue) { ICodedValueDomain pCD = pDomain as ICodedValueDomain; for (int j = 0; j < pCD.CodeCount; j++) { if (pCD.get_Name(j) == "地下") { fValue = pCD.get_Value(j).ToString(); } } } string whereClause = "UPORDOWN = " + fValue + " And "; return(whereClause); }
private void UpdateGrid() { IFields fields = this.m_pObject.Fields; ISubtypes subtypes = this.m_pObject.Class as ISubtypes; IDomain domain = null; ICodedValueDomain domain2 = null; for (int i = 0; i < fields.FieldCount; i++) { IField field = fields.get_Field(i); if (((((field.Type != esriFieldType.esriFieldTypeGeometry) && (field.Type != esriFieldType.esriFieldTypeOID)) && (field.Type != esriFieldType.esriFieldTypeRaster)) && field.Editable) && (subtypes.SubtypeFieldName != field.Name)) { domain = subtypes.get_Domain((this.m_pObject as IRowSubtypes).SubtypeCode, field.Name); if (domain is ICodedValueDomain) { IList list = new ArrayList(); domain2 = domain as ICodedValueDomain; if (field.IsNullable) { list.Add("<空>"); } for (int j = 0; j < domain2.CodeCount; j++) { list.Add(domain2.get_Name(j)); } this.m_pVertXtraGrid.ChangeItem(i, (Common.ControlExtend.ColumnAttribute)ColumnAttribute.CA_COMBOBOX, list, 0.0, 0.0); } else if ((((field.Type == esriFieldType.esriFieldTypeSmallInteger) || (field.Type == esriFieldType.esriFieldTypeSingle)) || (field.Type == esriFieldType.esriFieldTypeDouble)) || (field.Type == esriFieldType.esriFieldTypeInteger)) { double minValue = 0.0; double maxValue = 0.0; if (domain is IRangeDomain) { minValue = (double)(domain as IRangeDomain).MinValue; maxValue = (double)(domain as IRangeDomain).MaxValue; this.m_pVertXtraGrid.ChangeItem(i, (Common.ControlExtend.ColumnAttribute)ColumnAttribute.CA_SPINEDIT, null, 0.0, 0.0); } else { this.m_pVertXtraGrid.ChangeItem(i, (Common.ControlExtend.ColumnAttribute)ColumnAttribute.CA_TEXTEDIT, null, 0.0, 0.0); } } else { this.m_pVertXtraGrid.ChangeItem(i, (Common.ControlExtend.ColumnAttribute)ColumnAttribute.CA_TEXTEDIT, null, 0.0, 0.0); } } } }
/// <summary> /// Finds the description in the domain that matches the specified <paramref name="value" /> /// </summary> /// <param name="source">The source.</param> /// <param name="value">The value.</param> /// <returns>Returns a <see cref="string" /> representing the name (or description) otherwise <c>null</c>.</returns> public static string GetDescription(this ICodedValueDomain source, object value) { if ((source == null) || (value == null) || Convert.IsDBNull(value)) { return(null); } return((from entry in source.AsEnumerable() where entry.Value.Equals(value.ToString()) select entry.Key).FirstOrDefault()); }
private void BuildFeatureListDataSouce() { _treeRecords = new List <TreeRecord>(); if (_lineFeature1 == null) { return; } if (_lineFeature2 == null) { return; } for (int i = 0; i < _lineFeature1.Fields.FieldCount; i++) { IField pField = _lineFeature1.Fields.Field[i]; if (pField.Type == esriFieldType.esriFieldTypeOID || pField.Type == esriFieldType.esriFieldTypeGeometry || pField.Type == esriFieldType.esriFieldTypeRaster || pField.Editable == false) { continue; } TreeRecord pRecord = new TreeRecord(); if (pField.Domain == null) { pRecord = new TreeRecord(false, pField.Type, pField.AliasName, _lineFeature1.Value[i], null, i, -1, _lineFeature2.Value[i], ""); } else { IDomain pDomain = pField.Domain; if (pDomain is CodedValueDomain) { ICodedValueDomain pCodeDomain = pDomain as ICodedValueDomain; if (pCodeDomain == null) { continue; } List <CodeValuePair> pairs = new List <CodeValuePair>(); for (int j = 0; j < pCodeDomain.CodeCount; j++) { CodeValuePair pair = new CodeValuePair { Name = pCodeDomain.Name[j], Value = pCodeDomain.Value[j] }; pairs.Add(pair); } pRecord = new TreeRecord(true, pField.Type, pField.AliasName, _lineFeature1.Value[i], pairs, i, -1, _lineFeature2.Value[i], ""); } else { IRangeDomain pRangeDomain = pDomain as IRangeDomain; } } _treeRecords.Add(pRecord); } }
/// <summary> /// Returns a list of all the coded domains: 0 - Value, 1 - Name, 2 - Combined "Value (name)" /// </summary> /// <param name="feature_layer"></param> /// <param name="attribute_field"></param> /// <param name="domainitemtype"></param> /// <returns></returns> public IList <string> GetCodedDomainItems(IFeatureLayer feature_layer, string attribute_field, DomainItemType domainitemtype) { IList <string> domain_list = new List <string>(); IFields fields = feature_layer.FeatureClass.Fields; if (fields.FieldCount == 0) { throw new Exception("Feature Class has no fields"); } int field_index = fields.FindField(attribute_field); if (field_index > -1) { IDomain domain = fields.get_Field(field_index).Domain; if (domain == null) { throw new Exception("Attribute field '" + attribute_field + "' has no domain"); } if (domain.Type == esriDomainType.esriDTCodedValue) { ICodedValueDomain codedvaluedomain = (ICodedValueDomain)domain; int codecount = codedvaluedomain.CodeCount; if (domainitemtype == DomainItemType.Name) { for (int i = 0; i < codecount; i++) { domain_list.Add(codedvaluedomain.get_Name(i).ToString()); } } if (domainitemtype == DomainItemType.Value) { for (int i = 0; i < codecount; i++) { domain_list.Add(codedvaluedomain.get_Value(i).ToString()); } } if (domainitemtype == DomainItemType.Combined) { string name = String.Empty; string value = String.Empty; for (int i = 0; i < codecount; i++) { name = codedvaluedomain.get_Name(i).ToString(); value = codedvaluedomain.get_Value(i).ToString(); domain_list.Add(name + " (" + value + ")"); } } } } return(domain_list); }
/// <summary> /// Creates an <see cref="IEnumerable{T}" /> from an <see cref="ICodedValueDomain" /> /// </summary> /// <param name="source">An <see cref="ICodedValueDomain" /> to create an <see cref="IEnumerable{T}" /> from.</param> /// <returns>An <see cref="IEnumerable{T}" /> that contains the domain from the input source.</returns> public static IEnumerable <KeyValuePair <string, string> > AsEnumerable(this ICodedValueDomain source) { if (source != null) { for (int i = 0; i < source.CodeCount; i++) { yield return(new KeyValuePair <string, string>(source.Name[i], TypeCast.Cast(source.Value[i], string.Empty))); } } }
private static void UpdateCodedValueDomain(IWorkspace theWorkspace, string DomainName, string SourceClassName, string CodeFieldName, string ValueFieldName) { // Get reference to the table to read codes and values from ITable theTable = commonFunctions.OpenTable(theWorkspace, SourceClassName); // Get reference to the domain itself IWorkspaceDomains wsDomains = (IWorkspaceDomains)theWorkspace; ICodedValueDomain theDomain = (ICodedValueDomain)wsDomains.get_DomainByName(DomainName); // Requires exclusive schema lock ISchemaLock schemaLock = (ISchemaLock)theDomain; try { // Get an exclusive lock schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock); // Clear everything out of the domain first int codedValues = theDomain.CodeCount; for (int i = 0; i <= codedValues - 1; i++) { theDomain.DeleteCode(theDomain.Value[0]); } // Sort the table ITableSort tableSorter = new TableSortClass(); tableSorter.Fields = ValueFieldName; tableSorter.set_Ascending(ValueFieldName, true); tableSorter.Table = theTable; tableSorter.Sort(null); // Loop through the sorted rows, add to the domain int codeFld = theTable.FindField(CodeFieldName); int valueFld = theTable.FindField(ValueFieldName); ICursor theCursor = tableSorter.Rows; IRow theRow = theCursor.NextRow(); while (theRow != null) { theDomain.AddCode(theRow.get_Value(codeFld), theRow.get_Value(valueFld).ToString()); theRow = theCursor.NextRow(); } } catch (Exception e) { MessageBox.Show(DomainName + " was not updated. This is likely because an exclusive schema lock could not be obtained.", "NCGMP Tools"); } finally { // Release the exclusive lock, if it was acquired. // This block of code (finally) is called whether or not there is a problem schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock); } }
private Dictionary <string, object> GetDomainNameValuePair(IDomain pDomain) { Dictionary <string, object> myDic = new Dictionary <string, object>(); ICodedValueDomain cv = pDomain as ICodedValueDomain; for (int i = 0; i < cv.CodeCount; i++) { myDic.Add(cv.GetCodeName(i), cv.GetCodeValue(i)); } return(myDic); }
public override void Setup() { base.Setup(); // The code to create a new coded value domain. _CodedValueDomain = new CodedValueDomainClass(); // Value and name pairs. _CodedValueDomain.AddCode("RES", "Residential"); _CodedValueDomain.AddCode("COM", "Commercial"); _CodedValueDomain.AddCode("IND", "Industrial"); _CodedValueDomain.AddCode("BLD", "Building"); }
protected override void OnClick() { IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactory(); IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(@"D:\Applications\ArcObjects\TestButton\GeoDP\GeoDB.gdb", ArcMap.Application.hWnd); IWorkspaceDomains pWorkspaceDomains = pWorkspace as IWorkspaceDomains; ICodedValueDomain pDomain = pWorkspaceDomains.DomainByName["Resturants"] as ICodedValueDomain; for (int i = 0; i < pDomain.CodeCount; i++) { MessageBox.Show("Code: " + pDomain.Value[i] + Environment.NewLine + "Description: " + pDomain.Name[i]); } }
/// <summary> /// This function will take in a coded value domain and a code and will return the coded value domain string /// </summary> /// <param name="CVDomain">the ICodedValueDomain value to search</param> /// <param name="sCode">the code that you are looking for</param> /// <returns>the string associated with the CVD</returns> public static string GetDomainDesc(ICodedValueDomain CVDomain, string sCode) { string sDesc = ""; for (int i = 0; i < CVDomain.CodeCount; i++) { if (CVDomain.Value[i].ToString() == sCode) { sDesc = CVDomain.Name[i]; i = CVDomain.CodeCount; } } return(sDesc); }
private void SetDomainTree() { if (comboBoxDomains.SelectedIndex < 0 || fieldNamesHasDomain.Count == 0) { return; } string fieldName = fieldNamesHasDomain[comboBoxDomains.SelectedIndex]; int index = fieldinfos.IndexOf(fieldName); IFieldInfo field = fieldinfos.Get(index); IDomain domainSelect = field.Domain; if (domainSelect == null) { return; } nodekeyMap.Clear(); this.treeViewDomain.Nodes.Clear(); if (domainSelect.DomainType == gviDomainType.gviDomainCodedValue) { ICodedValueDomain codedomain = domainSelect as ICodedValueDomain; int nCodes = codedomain.CodeCount; for (int c = 0; c < nCodes; c++) { string codename = codedomain.GetCodeName(c); object codevalue = codedomain.GetCodeValue(c); this.treeViewDomain.Nodes.Add(codevalue.ToString(), codename, 2, 2); nodekeyMap.Add(codename, c); TreeNode pNode = this.treeViewDomain.Nodes.Find(codevalue.ToString(), true)[0]; pNode.Checked = true; } //其它值 { this.treeViewDomain.Nodes.Add("other", "other", 2, 2); nodekeyMap.Add("other", nCodes); TreeNode pNode = this.treeViewDomain.Nodes.Find("other", true)[0]; pNode.Checked = true; } } else { IRangeDomain rangedomain = domainSelect as IRangeDomain; object minValue = rangedomain.MinValue; object maxValue = rangedomain.MaxValue; } }
//复制工作空间坐标空间域 private void CreateWorkspaceDomains(IWorkspace pWs1, IWorkspace pWs2) { try { WaitForm.SetCaption("正在复制工作空间域,请稍后..."); IWorkspaceDomains pWsD1 = pWs1 as IWorkspaceDomains; IWorkspaceDomains pWsD2 = pWs2 as IWorkspaceDomains; IEnumDomain pEnumDomain = pWsD1.Domains; IDomain pDomain1 = null; IDomain pDomain2 = null; if (pEnumDomain == null) { return; } while ((pDomain1 = pEnumDomain.Next()) != null) { if (pDomain1.Type == esriDomainType.esriDTCodedValue)//编码域 { ICodedValueDomain tempDomain1 = pDomain1 as ICodedValueDomain; ICodedValueDomain tempDomain2 = new CodedValueDomainClass(); for (int i = 0; i < tempDomain1.CodeCount; i++) { tempDomain2.AddCode(tempDomain1.get_Value(i), tempDomain1.get_Name(i)); } pDomain2 = tempDomain2 as IDomain; pDomain2.Description = pDomain1.Description; pDomain2.FieldType = pDomain1.FieldType; pDomain2.DomainID = pDomain1.DomainID; pDomain2.MergePolicy = pDomain1.MergePolicy; pDomain2.Name = pDomain1.Name; pDomain2.Owner = pDomain1.Owner; pDomain2.SplitPolicy = pDomain1.SplitPolicy; pWsD2.AddDomain(pDomain2); } else//范围域 { IRangeDomain tempDomain1 = pDomain1 as IRangeDomain; IRangeDomain tempDomain2 = new RangeDomainClass(); tempDomain2.MaxValue = tempDomain1.MaxValue; tempDomain2.MinValue = tempDomain1.MinValue; pDomain2 = tempDomain2 as IDomain; pWsD2.AddDomain(pDomain2); } } } catch (System.Exception ex) { return; } }
private string GetCodedValueDomainValue(ICodedValueDomain pDomain, string domainDescription) { string result = "<Null>"; for (int i = 0; i < pDomain.CodeCount; i++) { if (pDomain.get_Name(i) == domainDescription) { result = pDomain.get_Value(i).ToString(); break; } } return(result); }
/// <summary> /// Gets the corresponding domain value for the value. /// </summary> /// <param name="field">The field.</param> /// <param name="keyword">The criteria.</param> /// <param name="comparisonOperator">The comparison operator.</param> /// <returns> /// The code value for the domain; otherwise the value parameter. /// </returns> private IEnumerable <string> GetDomainValues(IField field, string keyword, ComparisonOperator comparisonOperator) { List <string> items = new List <string>(); if (_Subtypes.HasSubtype) { var values = _Subtypes.Subtypes.AsEnumerable(); foreach (var subtype in values) { if (_Subtypes.SubtypeFieldName.Equals(field.Name, StringComparison.CurrentCultureIgnoreCase)) { if (this.AsOperatorMatch(keyword, subtype.Value, comparisonOperator)) { var subtypeCode = subtype.Key.ToString(CultureInfo.InvariantCulture); if (!items.Contains(subtypeCode)) { items.Add(subtypeCode); } } } else { ICodedValueDomain codedValueDomain = _Subtypes.Domain[subtype.Key, field.Name] as ICodedValueDomain; if (codedValueDomain != null) { foreach (var domain in codedValueDomain.AsEnumerable()) { if (this.AsOperatorMatch(keyword, domain.Key, comparisonOperator)) { if (!items.Contains(domain.Value)) { items.Add(domain.Value); } } } } } } } if (items.Count == 0) { items.Add(keyword); } return(items); }
public static object GetCode([NotNull] ICodedValueDomain domain, [NotNull] string name) { Assert.ArgumentNotNull(domain, nameof(domain)); int codeCount = domain.CodeCount; for (var index = 0; index < codeCount; index++) { if (domain.Name[index].Equals(name)) { return(domain.Value[index]); } } return(null); }
public static object GetCodedValueName([NotNull] ICodedValueDomain domain, [CanBeNull] object value) { Assert.ArgumentNotNull(domain, nameof(domain)); int codeCount = domain.CodeCount; for (var index = 0; index < codeCount; index++) { if (Equals(domain.Value[index], value)) { return(domain.Name[index]); } } return(value); }
private KeyValueList <object, string> ReadColumnDomainValues(IField field) { ICodedValueDomain codedValueDomain = field?.Domain as ICodedValueDomain; if (codedValueDomain == null) { return(null); } var result = new KeyValueList <object, string>(); for (var index = 0; index < codedValueDomain.CodeCount; index++) { result.AddOrReplace(codedValueDomain.Value[index], codedValueDomain.Name[index]); } return(result); }
protected override void OnClick() { // // TODO: Sample code showing how to access button host // IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactory(); IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(@"C:\IGeometry\IGeometryGDB\IGeometry.gdb", ArcMap.Application.hWnd); IWorkspaceDomains pWorkspaceDomains = pWorkspace as IWorkspaceDomains; ICodedValueDomain pDomain = pWorkspaceDomains.DomainByName["RestaurantTypes"] as ICodedValueDomain; for (int i = 0; i < pDomain.CodeCount; i++) { MessageBox.Show("Code: " + pDomain.Value[i] + Environment.NewLine + "Description: " + pDomain.Name[i]); } ArcMap.Application.CurrentTool = null; }
public static IDomain AddDomain(IWorkspace workspace, IDomain domain) { if (domain == null) { return(null); } IWorkspaceDomains pWorkspaceDomains = workspace as IWorkspaceDomains; if (pWorkspaceDomains == null) { return(null); } IDomain pDomain = pWorkspaceDomains.DomainByName[domain.Name]; if (pDomain != null) { return(pDomain); } if (domain.Type == esriDomainType.esriDTCodedValue) { ICodedValueDomain pCodedValueDomain = new CodedValueDomainClass(); ICodedValueDomain pOriginCodedValueDomain = domain as ICodedValueDomain; for (int i = 0; i < pOriginCodedValueDomain.CodeCount; i++) { pCodedValueDomain.AddCode(pOriginCodedValueDomain.Value[i], pOriginCodedValueDomain.Name[i]); } pDomain = pCodedValueDomain as IDomain; } else { IRangeDomain pRangeDomain = new RangeDomainClass(); IRangeDomain pOriginRangeDomain = domain as IRangeDomain; pRangeDomain.MinValue = pOriginRangeDomain.MinValue; pRangeDomain.MaxValue = pOriginRangeDomain.MaxValue; pDomain = pRangeDomain as IDomain; } pDomain.Name = domain.Name; pDomain.FieldType = domain.FieldType; pDomain.Description = domain.Description; pDomain.SplitPolicy = esriSplitPolicyType.esriSPTDuplicate; pDomain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue; pWorkspaceDomains.AddDomain(pDomain); return(pDomain); }
public static bool DoesDomainMemberExist(ICodedValueDomain cvDomain, object code) { return !string.IsNullOrEmpty(ValueFromCode(cvDomain as IDomain, code)); }
/// <summary> /// Used for CodedValueDomain /// This function is used to construct a query string which when executed on the source Feature Class/Table will return the records that violate domain constraints. /// </summary> /// <param name="ipCodedDomain">Coded value domain applied to the field whose attributes are getting validated</param> /// <param name="strFieldName">Name of the field</param> /// <returns></returns> private string GetQueryStringForCodedDomain(ICodedValueDomain ipCodedDomain, string strFieldName) { if (null == ipCodedDomain || string.IsNullOrEmpty(strFieldName)) return ""; string strQueryString = ""; IDomain ipDomain = ipCodedDomain as IDomain; if (ipDomain.FieldType == esriFieldType.esriFieldTypeDate) { strQueryString = GetDateQueryStringForCodedDomain(ipCodedDomain, strFieldName); } else if (ipDomain.FieldType == esriFieldType.esriFieldTypeDouble || ipDomain.FieldType == esriFieldType.esriFieldTypeInteger || ipDomain.FieldType == esriFieldType.esriFieldTypeSingle || ipDomain.FieldType == esriFieldType.esriFieldTypeSmallInteger ) { if(ipCodedDomain.CodeCount > 0) { strQueryString = ""; strQueryString = strFieldName + " NOT IN ("; for (int i = 0; i < ipCodedDomain.CodeCount; i++) { if(i==0) strQueryString += Convert.ToString(ipCodedDomain.get_Value(i)); else strQueryString += "," + Convert.ToString(ipCodedDomain.get_Value(i)); } strQueryString += ")"; } } else if (ipDomain.FieldType == esriFieldType.esriFieldTypeString) { if (ipCodedDomain.CodeCount > 0) { strQueryString = ""; strQueryString = strFieldName + " NOT IN ("; for (int i = 0; i < ipCodedDomain.CodeCount; i++) { if (i == 0) strQueryString += "'" + Convert.ToString(ipCodedDomain.get_Value(i)) + "'"; else strQueryString += ",'" + Convert.ToString(ipCodedDomain.get_Value(i)) + "'"; } strQueryString += ")"; } } return strQueryString; }
/// <summary> /// Used when the CodedValueDomain field is of Date type /// This function is used to construct a query string which when executed on the source Feature Class/Table will return the records that violate domain constraints. /// </summary> /// <param name="ipCodedDomain">Coded value domain applied to the Date type field whose attributes are getting validated</param> /// <param name="strFieldName">Name of the Date type field</param> /// <returns></returns> private string GetDateQueryStringForCodedDomain(ICodedValueDomain ipCodedDomain, string strFieldName) { if (null == ipCodedDomain || string.IsNullOrEmpty(strFieldName)) return ""; if (null == m_ipWorkspace) return ""; string strQueryString = ""; DatabaseType eDBType = GetDatabaseType(m_ipWorkspace); if (eDBType == DatabaseType.FGDB || eDBType == DatabaseType.SHAPEFILE) { if (ipCodedDomain.CodeCount > 0) { strQueryString = strFieldName + " NOT IN ("; for (int i = 0; i < ipCodedDomain.CodeCount; i++) { if (i == 0) strQueryString += "date '" + Convert.ToString(ipCodedDomain.get_Value(i)) + "'"; else strQueryString += ", date '" + Convert.ToString(ipCodedDomain.get_Value(i)) + "'"; } strQueryString += ")"; } } else if (eDBType == DatabaseType.MDB) { if (ipCodedDomain.CodeCount > 0) { strQueryString = strFieldName + " NOT IN ("; for (int i = 0; i < ipCodedDomain.CodeCount; i++) { if (i == 0) strQueryString += "#" + Convert.ToString(ipCodedDomain.get_Value(i)) + "#"; else strQueryString += ", #" + Convert.ToString(ipCodedDomain.get_Value(i)) + "#"; } strQueryString += ")"; } } else if (eDBType == DatabaseType.ORACLE) { if (ipCodedDomain.CodeCount > 0) { strQueryString = strFieldName + " NOT IN ("; for (int i = 0; i < ipCodedDomain.CodeCount; i++) { DateTime dateTimeValue = Convert.ToDateTime(ipCodedDomain.get_Value(i)); string strYear = dateTimeValue.Year.ToString(); string strMonth = dateTimeValue.Month.ToString(); if (dateTimeValue.Month < 10) strMonth = "0" + strMonth; string strDay = dateTimeValue.Day.ToString(); if (dateTimeValue.Day < 10) strDay = "0" + strDay; string strHour = dateTimeValue.Hour.ToString(); if (dateTimeValue.Hour < 10) strHour = "0" + strHour; string strMin = dateTimeValue.Minute.ToString(); if (dateTimeValue.Minute < 10) strMin = "0" + strMin; string strSec = dateTimeValue.Second.ToString(); if (dateTimeValue.Second < 10) strSec = "0" + strSec; string strFormattedDate = string.Format("to_date('{0}-{1}-{2} {3}:{4}:{5}', 'dd-mm-yyyy hh24:mi:ss')",strDay,strMonth,strYear,strHour,strMin,strSec); if (i == 0) strQueryString += strFormattedDate; else strQueryString += "," + strFormattedDate; } strQueryString += ")"; } } else if (eDBType == DatabaseType.POSTGRESQL || eDBType == DatabaseType.SQLSERVER) { if (ipCodedDomain.CodeCount > 0) { strQueryString = strFieldName + " NOT IN ("; for (int i = 0; i < ipCodedDomain.CodeCount; i++) { if (i == 0) strQueryString += "'" + Convert.ToString(ipCodedDomain.get_Value(i)) + "'"; else strQueryString += ", '" + Convert.ToString(ipCodedDomain.get_Value(i)) + "'"; } strQueryString += ")"; } } else { strQueryString = ""; } return strQueryString; }
/// <summary> /// Converts the specified ESRI field type to a .NET type. /// </summary> /// <param name="esriType">The ESRI field type to be converted.</param> /// <returns>The appropriate .NET type.</returns> private Type EsriFieldTypeToSystemType(IField field) { esriFieldType esriType = field.Type; // Does this field have a domain? cvDomain = field.Domain as ICodedValueDomain; if ((null != cvDomain) && useCVDomain) { return typeof(string); } try { switch (esriType) { case esriFieldType.esriFieldTypeBlob: //beyond scope of sample to deal with blob fields return typeof(string); case esriFieldType.esriFieldTypeDate: return typeof(DateTime); case esriFieldType.esriFieldTypeDouble: return typeof(double); case esriFieldType.esriFieldTypeGeometry: return typeof(string); case esriFieldType.esriFieldTypeGlobalID: return typeof(string); case esriFieldType.esriFieldTypeGUID: return typeof(Guid); case esriFieldType.esriFieldTypeInteger: return typeof(Int32); case esriFieldType.esriFieldTypeOID: return typeof(Int32); case esriFieldType.esriFieldTypeRaster: //beyond scope of sample to correctly display rasters return typeof(string); case esriFieldType.esriFieldTypeSingle: return typeof(Single); case esriFieldType.esriFieldTypeSmallInteger: return typeof(Int16); case esriFieldType.esriFieldTypeString: return typeof(string); default: return typeof(string); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); return typeof(string); } }