private void GetDomainAndPopulateList(IReadOnlyList <Field> fields, string fieldName, ObservableCollection <DomainCodedValuePair> memberCodedValueDomains, bool orderbyName = false) { ArcGIS.Core.Data.Field foundField = fields.FirstOrDefault(field => field.Name == fieldName); //Clear out any old values memberCodedValueDomains.Clear(); if (foundField != null) { Domain domain = foundField.GetDomain(); var codedValueDomain = domain as CodedValueDomain; if (codedValueDomain != null) { SortedList <object, string> codedValuePairs = codedValueDomain.GetCodedValuePairs(); foreach (KeyValuePair <object, string> pair in codedValuePairs) { DomainCodedValuePair domainObjectPair = new DomainCodedValuePair(pair.Key, pair.Value); memberCodedValueDomains.Add(domainObjectPair); } if (orderbyName) { //Order the collection alphabetically by the names, rather than the default by the code memberCodedValueDomains.Sort(); } } } }
private async Task <string> GetDomainValueAsync(string fieldName, string key) { try { IEnumerable <GDBProjectItem> gdbProjectItems = Project.Current.GetItems <GDBProjectItem>(); return(await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => { foreach (GDBProjectItem gdbProjectItem in gdbProjectItems) { using (Datastore datastore = gdbProjectItem.GetDatastore()) { //Unsupported datastores (non File GDB and non Enterprise GDB) will be of type UnknownDatastore if (datastore is UnknownDatastore) { continue; } Geodatabase geodatabase = datastore as Geodatabase; string geodatabasePath = geodatabase.GetPath(); if (geodatabasePath.Contains(ProSymbolEditorModule.WorkspaceString)) { //Correct GDB, open the current selected feature class _currentFeatureClass = geodatabase.OpenDataset <FeatureClass>(_currentFeatureClassName); using (_currentFeatureClass) { ArcGIS.Core.Data.FeatureClassDefinition facilitySiteDefinition = _currentFeatureClass.GetDefinition(); IReadOnlyList <ArcGIS.Core.Data.Field> fields = facilitySiteDefinition.GetFields(); ArcGIS.Core.Data.Field foundField = fields.FirstOrDefault(field => field.Name == fieldName); if (foundField != null) { CodedValueDomain domain = foundField.GetDomain() as CodedValueDomain; return domain.GetCodedValue(key).ToString(); } } break; } } } return ""; })); } catch (Exception exception) { System.Diagnostics.Debug.WriteLine(exception.ToString()); } return(null); }
private void GetDomainAndPopulateList(IReadOnlyList <Field> fields, string fieldName, ObservableCollection <DomainCodedValuePair> memberCodedValueDomains)//SortedList<object, string> memberCodedValueDomains) { ArcGIS.Core.Data.Field foundField = fields.FirstOrDefault(field => field.Name == fieldName); //Clear out any old values memberCodedValueDomains.Clear(); if (foundField != null) { Domain domain = foundField.GetDomain(); var codedValueDomain = domain as CodedValueDomain; SortedList <object, string> codedValuePairs = codedValueDomain.GetCodedValuePairs(); foreach (KeyValuePair <object, string> pair in codedValuePairs) { DomainCodedValuePair domainObjectPair = new DomainCodedValuePair(pair.Key, pair.Value); memberCodedValueDomains.Add(domainObjectPair);//pair.Value); } } }
private string GetName(ArcGIS.Core.Data.Field field) { return(string.IsNullOrEmpty(field.AliasName) ? field.Name : field.AliasName); }
public List <ComboData> getDomainValuesforTable(TableDefinition def, string fieldName) { List <ComboData> domainValues = new List <ComboData>(); // always add a blank at the start ComboData item = new ComboData(); item.Id = _noneField; item.Value = _noneField; item.Tooltip = _noneField; domainValues.Add(item); try { IReadOnlyList <ArcGIS.Core.Data.Field> fields = def.GetFields(); ArcGIS.Core.Data.Field thefield = fields.First(field => field.Name.ToLower() == fieldName.ToLower()); IReadOnlyList <ArcGIS.Core.Data.Subtype> subtypes = def.GetSubtypes(); if (subtypes.Count == 0) { Domain domain = thefield.GetDomain(); if (domain is CodedValueDomain) { var codedValueDomain = domain as CodedValueDomain; SortedList <object, string> codedValuePairs = codedValueDomain.GetCodedValuePairs(); for (int i = 0; i < codedValuePairs.Count; i++) { item = new ComboData(); item.Id = codedValuePairs.ElementAt(i).Key.ToString(); item.Value = codedValuePairs.ElementAt(i).Value.ToString(); item.Tooltip = getDomainTooltip(item.Id, item.Value); domainValues.Add(item); } } } else if (subtypes.Count > 0) { List <string> domainNames = new List <string>(); for (int s = 0; s < subtypes.Count; s++) { ArcGIS.Core.Data.Subtype stype = subtypes[s]; Domain domain = thefield.GetDomain(stype); if (domain != null) { string dname = domain.GetName(); if (domain is CodedValueDomain && !domainNames.Contains(dname)) { domainNames.Add(dname); var codedValueDomain = domain as CodedValueDomain; SortedList <object, string> codedValuePairs = codedValueDomain.GetCodedValuePairs(); for (int i = 0; i < codedValuePairs.Count; i++) { item = new ComboData(); item.Id = codedValuePairs.ElementAt(i).Key.ToString(); item.Value = codedValuePairs.ElementAt(i).Value.ToString(); item.Tooltip = getDomainTooltip(item.Id, item.Value) + " - " + dname; bool found = false; for (int cv = 0; cv < domainValues.Count; cv++) { ComboData dv = domainValues[cv]; if (item.Id.Equals(dv.Id) && item.Value.Equals(dv.Value) && item.Tooltip.Equals(dv.Tooltip)) { found = true; } } if (!found) { domainValues.Add(item); } } } } } } } catch { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Unable to retrieve domain values for " + fieldName); return(domainValues); } return(domainValues); }
private void GetDomainAndPopulateList(IReadOnlyList <Field> fields, string fieldName, ObservableCollection <DomainCodedValuePair> memberCodedValueDomains, bool orderbyName = false) { ArcGIS.Core.Data.Field foundField = fields.FirstOrDefault(field => field.Name == fieldName); //Clear out any old values memberCodedValueDomains.Clear(); if (foundField != null) { Domain domain = foundField.GetDomain(); var codedValueDomain = domain as CodedValueDomain; if (codedValueDomain != null) { SortedList <object, string> codedValuePairs = codedValueDomain.GetCodedValuePairs(); foreach (KeyValuePair <object, string> pair in codedValuePairs) { DomainCodedValuePair domainObjectPair = new DomainCodedValuePair(pair.Key, pair.Value); memberCodedValueDomains.Add(domainObjectPair); } if (orderbyName) { //Order the collection alphabetically by the names, rather than the default by the code memberCodedValueDomains.Sort(); } // Minor hack to make USA appear first in the list if (fieldName == "countrycode") { // TRICKY: Domains have 3 different formats, old format: "USA" and new format: "US" "840" // Check the format of the domains to see which format we should use DomainCodedValuePair testDomainPair = memberCodedValueDomains[0]; object code = testDomainPair.Code; DomainCodedValuePair usaDomainObjectPair = null; if (code is int) { // New Format usaDomainObjectPair = new DomainCodedValuePair(840, "United States"); // new format, 2525D/APP6D } else if (code is string) { string testString = code as string; if (testString.Length == 2) { usaDomainObjectPair = new DomainCodedValuePair("US", "United States"); // new format, 2525B/C/APP6B } else { usaDomainObjectPair = new DomainCodedValuePair("USA", "United States"); // old format } } if (usaDomainObjectPair != null) { memberCodedValueDomains.Insert(0, usaDomainObjectPair); } } // Add a "<null>" value to the domain list - so this field can be cleared with this flag // but skip ones that will cause problems with the addin if (!((fieldName == "identity") || (fieldName == "affiliation") || (fieldName == "extendedfunctioncode") || (fieldName == "symbolentity"))) { memberCodedValueDomains.Add(new DomainCodedValuePair(ProSymbolUtilities.NullFieldValueFlag, ProSymbolUtilities.NullFieldValueFlag)); } } } }