/// <summary> /// Returns a CodedValueSources object constructed form the CodedValueDomain value. /// </summary> /// <param name="field">The field to make a CodedValueSource from.</param> /// <returns>The CodedValueSources object used for a code to value lookup.</returns> internal static CodedValueSources BuildCodedValueSource(Field field) { CodedValueDomain codedValueDomain = field.Domain as CodedValueDomain; CodedValueSources codedValueSources = null; if (codedValueDomain != null) { foreach (KeyValuePair <object, string> codedValue in codedValueDomain.CodedValues) { if (codedValueSources == null) { codedValueSources = new CodedValueSources(); if (field.Nullable) { CodedValueSource nullableSource = new CodedValueSource() { Code = null, DisplayName = " " }; codedValueSources.Add(nullableSource); } } codedValueSources.Add(new CodedValueSource() { Code = codedValue.Key, DisplayName = codedValue.Value }); } } return(codedValueSources); }
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); }
/// <summary> /// Builds a DynamicCodedValueSource object used to lookup display value. /// </summary> /// <param name="field">The field to build DynamicCodedValueSource for</param> /// <param name="layerInfo">The FeatureLayerInfo used to lookup all the coded value domains </param> /// <returns>DynamicCodedValueSource which is a collection of coded value domain values for a field.</returns> internal static DynamicCodedValueSource BuildDynamicCodedValueSource(Field field, FeatureLayerInfo layerInfo) { DynamicCodedValueSource dynamicCodedValueSource = null; foreach (object key in layerInfo.FeatureTypes.Keys) { FeatureType featureType = layerInfo.FeatureTypes[key]; if (featureType.Domains.ContainsKey(field.Name)) { if (dynamicCodedValueSource == null) { dynamicCodedValueSource = new DynamicCodedValueSource(); } CodedValueDomain codedValueDomain = featureType.Domains[field.Name] as CodedValueDomain; if (codedValueDomain != null) { CodedValueSources codedValueSources = null; foreach (KeyValuePair <object, string> kvp in codedValueDomain.CodedValues) { if (codedValueSources == null) { codedValueSources = new CodedValueSources(); if (field.Nullable) { CodedValueSource nullableSource = new CodedValueSource() { Code = null, DisplayName = " " }; codedValueSources.Add(nullableSource); } } codedValueSources.Add(new CodedValueSource() { Code = kvp.Key, DisplayName = kvp.Value }); } if (codedValueSources != null) { if (dynamicCodedValueSource == null) { dynamicCodedValueSource = new DynamicCodedValueSource(); } dynamicCodedValueSource.Add(featureType.Id, codedValueSources); } } } } return(dynamicCodedValueSource); }
private void FeatureLayer_Initialized(object sender, EventArgs e) { FeatureLayer fl = sender as FeatureLayer; #region populate the FeatureTypeListBox with the possible templates FeatureTypeListBox.Items.Clear(); IDictionary <object, FeatureType> featureTypes = fl.LayerInfo.FeatureTypes; if (fl.Renderer != null) { Symbol defaultSymbol = fl.Renderer.GetSymbol(null); if (featureTypes != null && featureTypes.Count > 0) { foreach (KeyValuePair <object, FeatureType> featureTypePairs in featureTypes) { if (featureTypePairs.Value != null && featureTypePairs.Value.Templates != null && featureTypePairs.Value.Templates.Count > 0) { foreach (KeyValuePair <string, FeatureTemplate> featureTemplate in featureTypePairs.Value.Templates) { string name = featureTypePairs.Value.Name; if (featureTypePairs.Value.Templates.Count > 1) { name = string.Format("{0}-{1}", featureTypePairs.Value.Name, featureTemplate.Value.Name); } Symbol symbol = featureTemplate.Value.GetSymbol(fl.Renderer) ?? defaultSymbol; FeatureTypeListBox.Items.Add(new CVDTemplateItem(name, symbol, Convert.ToInt32(featureTypePairs.Value.Id))); } } } } } #endregion #region get coded value codes and descriptions var facilityField = fl.LayerInfo.Fields.Where(f => f.Name == "facility").First(); facilityFieldDomain = facilityField.Domain as CodedValueDomain; FacilityChoicesListBox.ItemsSource = facilityFieldDomain.CodedValues; var qualityField = fl.LayerInfo.Fields.Where(f => f.Name == "quality").First(); qualityFieldDomain = qualityField.Domain as CodedValueDomain; QualityChoicesListBox.ItemsSource = qualityFieldDomain.CodedValues; #endregion //enable the app bar and context menu items for (int i = 0; i < ApplicationBar.Buttons.Count; ++i) { (ApplicationBar.Buttons[i] as IApplicationBarIconButton).IsEnabled = true; } }
private void DamageTable_Loaded(object sender, EventArgs e) { // This code needs to work with the UI, so it needs to run on the UI thread. RunOnUiThread(() => { // Get the relevant field from the table. ServiceFeatureTable table = (ServiceFeatureTable)sender; Field typeDamageField = table.Fields.First(field => field.Name == AttributeFieldName); // Get the domain for the field. _domain = (CodedValueDomain)typeDamageField.Domain; // Listen for user taps on the map - this will select the feature. _myMapView.GeoViewTapped += MapView_Tapped; }); }
private void DamageTable_Loaded(object sender, EventArgs e) { // This code needs to work with the UI, so it needs to run on the UI thread. Dispatcher.Invoke(() => { // Get the relevant field from the table. ServiceFeatureTable table = (ServiceFeatureTable)sender; Field typeDamageField = table.Fields.First(field => field.Name == AttributeFieldName); // Get the domain for the field. CodedValueDomain attributeDomain = (CodedValueDomain)typeDamageField.Domain; // Update the combobox with the attribute values. DamageTypeDropDown.ItemsSource = attributeDomain.CodedValues.Select(codedValue => codedValue.Name); }); }
private void DamageTable_Loaded(object sender, EventArgs e) { // Unsubscribe from event. ((ServiceFeatureTable)sender).Loaded -= DamageTable_Loaded; // This code needs to work with the UI, so it needs to run on the UI thread. BeginInvokeOnMainThread(() => { // Get the relevant field from the table. ServiceFeatureTable table = (ServiceFeatureTable)sender; Field typeDamageField = table.Fields.First(field => field.Name == AttributeFieldName); // Get the domain for the field. _domain = (CodedValueDomain)typeDamageField.Domain; }); }
/// <summary> /// Initializes a new instance of the <see cref="FeatureDataField<T>"/> class. /// </summary> /// <param name="featureDataForm">The feature data form.</param> /// <param name="layerInfo">The feature layer info.</param> /// <param name="field">The field.</param> /// <param name="propertyType">Type of the property.</param> /// <param name="propertyValue">The property value.</param> internal FeatureDataField(FeatureDataForm featureDataForm, FeatureLayerInfo layerInfo, Field field, Type propertyType, T propertyValue) { this._featureDataForm = featureDataForm; this._field = field; this._layerInfo = layerInfo; this._codedValueDomain = null; Domain domain = field.Domain; if (domain != null && !Toolkit.Utilities.FieldDomainUtils.IsDynamicDomain(_field, _layerInfo)) { this._codedValueDomain = domain as CodedValueDomain; if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?)) { this._dateRangeDomain = domain as RangeDomain <DateTime>; } else if (propertyType == typeof(double) || propertyType == typeof(double?)) { this._doubleRangeDomain = domain as RangeDomain <double>; } else if (propertyType == typeof(float) || propertyType == typeof(float?)) { this._floatRangeDomain = domain as RangeDomain <float>; } else if (propertyType == typeof(int) || propertyType == typeof(int?)) { this._intRangeDomain = domain as RangeDomain <int>; } else if (propertyType == typeof(short) || propertyType == typeof(short?)) { this._shortRangeDomain = domain as RangeDomain <short>; } else if (propertyType == typeof(long) || propertyType == typeof(long?)) { this._longRangeDomain = domain as RangeDomain <long>; } else if (propertyType == typeof(byte) || propertyType == typeof(byte?)) { this._byteRangeDomain = domain as RangeDomain <byte>; } } this._propertyType = propertyType; this._propertyValue = propertyValue; }
/// <summary> /// Initializes a new instance of the <see cref="FeatureDataField<T>"/> class. /// </summary> /// <param name="featureDataForm">The feature data form.</param> /// <param name="field">The field.</param> /// <param name="propertyType">Type of the property.</param> /// <param name="propertyValue">The property value.</param> internal FeatureDataField(FeatureDataForm featureDataForm, Field field, Type propertyType, T propertyValue) { this._featureDataForm = featureDataForm; this._codedValueDomain = null; Domain domain = field.Domain; if (domain != null) { this._codedValueDomain = domain as CodedValueDomain; if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?)) { this._dateRangeDomain = domain as RangeDomain <DateTime>; } else if (propertyType == typeof(double) || propertyType == typeof(double?)) { this._doubleRangeDomain = domain as RangeDomain <double>; } else if (propertyType == typeof(float) || propertyType == typeof(float?)) { this._floatRangeDomain = domain as RangeDomain <float>; } else if (propertyType == typeof(int) || propertyType == typeof(int?)) { this._intRangeDomain = domain as RangeDomain <int>; } else if (propertyType == typeof(short) || propertyType == typeof(short?)) { this._shortRangeDomain = domain as RangeDomain <short>; } else if (propertyType == typeof(long) || propertyType == typeof(long?)) { this._longRangeDomain = domain as RangeDomain <long>; } else if (propertyType == typeof(byte) || propertyType == typeof(byte?)) { this._byteRangeDomain = domain as RangeDomain <byte>; } } this._field = field; this._propertyType = propertyType; this._propertyValue = propertyValue; }
public static KeyValuePair <object, string> GetCodedValue(this CodedValueDomain domain, object value, bool nullable = false) { if (domain == null || domain.CodedValues == null) { return(default(KeyValuePair <object, string>)); } if (value == null && nullable) { return(new KeyValuePair <object, string>(null, "")); } #if !NETFX_CORE return(domain.CodedValues.FirstOrDefault(x => x.Key != null && x.Key.Equals(value))); #else var kvp = domain.CodedValues.FirstOrDefault(x => x.Key != null && x.Key.Equals(value)); return(new KeyValuePair <object, string>(kvp.Key, kvp.Value)); #endif }
// CodedValueDomain public static Dictionary <string, object> ToDictionary(this CodedValueDomain domain) { Dictionary <string, object> dictionary = new Dictionary <string, object>(); if (!string.IsNullOrEmpty(domain.Name)) { dictionary.Add("name", domain.Name); } if (domain.CodedValues != null) { List <Dictionary <string, object> > codedValues = new List <Dictionary <string, object> >(); foreach (KeyValuePair <object, string> value in domain.CodedValues) { codedValues.Add(value.ToDictionary()); } dictionary.Add("codedValues", codedValues); } return(dictionary); }
private static IDomain GetOrCreateDomain(IWorkspace ws) { IWorkspaceDomains wsd = ws as IWorkspaceDomains; IDomain domain = wsd.get_DomainByName(DOMAIN_NAME); if (domain == null) { ICodedValueDomain2 cvd = new CodedValueDomain() as ICodedValueDomain2; cvd.AddCode(1, "New Feature"); cvd.AddCode(2, "Modified Feature"); cvd.AddCode(3, "Modified Feature (After)"); cvd.AddCode(6, "Modified Feature (Before)"); cvd.AddCode(4, "Deleted Feature"); domain = cvd as IDomain; domain.FieldType = esriFieldType.esriFieldTypeInteger; domain.Name = DOMAIN_NAME; domain.SplitPolicy = esriSplitPolicyType.esriSPTDuplicate; domain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue; int i = wsd.AddDomain(domain); } return(domain); }
public static FieldDomain GetDomain(Domain fs_domain) { FieldDomain result; try { ObservableDictionary <string, FieldDomain> domains = AfaDocData.ActiveDocData.DocDataset.Domains; string key = DocUtil.FixSymbolName(fs_domain.DomainName); FieldDomain fieldDomain = null; if (domains.TryGetValue(key, out fieldDomain) && FieldDomain.AreEquivalent(fieldDomain, fs_domain)) { result = fieldDomain; } else { string domainType = ""; if (fs_domain is CodedValueDomain) { domainType = "CodedValueDomain"; } else if (fs_domain is RangeDomain) { domainType = "RangeDomain"; } CadField.CadFieldType cadFieldType = FieldDomain.GetCadFieldType(fs_domain.FieldType); fieldDomain = new FieldDomain(fs_domain.DomainName, cadFieldType, domainType); if (fs_domain is CodedValueDomain) { CodedValueDomain codedValueDomain = (CodedValueDomain)fs_domain; if (codedValueDomain.CodedValues.Length <= 0) { goto IL_129; } CodedValue[] array = codedValueDomain.CodedValues.ToArray <CodedValue>(); try { CodedValue[] array2 = array; for (int i = 0; i < array2.Length; i++) { CodedValue codedValue = array2[i]; fieldDomain.CodedValues.Add(DocUtil.FixSymbolName(codedValue.Name), new MSCCodedValue(codedValue.Name, cadFieldType, codedValue.Code)); } goto IL_129; } catch (SystemException ex) { string arg_FC_0 = ex.Message; goto IL_129; } } if (fs_domain is RangeDomain) { RangeDomain rangeDomain = (RangeDomain)fs_domain; fieldDomain.MinValue = rangeDomain.MinValue; fieldDomain.MaxValue = rangeDomain.MaxValue; } IL_129: AfaDocData.ActiveDocData.DocDataset.Domains.Add(fieldDomain.Name, fieldDomain); result = fieldDomain; } } catch { result = null; } return(result); }
private void FeatureLayer_Initialized(object sender, EventArgs e) { FeatureLayer fl = sender as FeatureLayer; #region populate the FeatureTypeListBox with the possible templates FeatureTypeListBox.Items.Clear(); IDictionary<object, FeatureType> featureTypes = fl.LayerInfo.FeatureTypes; if (fl.Renderer != null) { Symbol defaultSymbol = fl.Renderer.GetSymbol(null); if (featureTypes != null && featureTypes.Count > 0) { foreach (KeyValuePair<object, FeatureType> featureTypePairs in featureTypes) { if (featureTypePairs.Value != null && featureTypePairs.Value.Templates != null && featureTypePairs.Value.Templates.Count > 0) { foreach (KeyValuePair<string, FeatureTemplate> featureTemplate in featureTypePairs.Value.Templates) { string name = featureTypePairs.Value.Name; if (featureTypePairs.Value.Templates.Count > 1) name = string.Format("{0}-{1}", featureTypePairs.Value.Name, featureTemplate.Value.Name); Symbol symbol = featureTemplate.Value.GetSymbol(fl.Renderer) ?? defaultSymbol; FeatureTypeListBox.Items.Add(new CVDTemplateItem(name, symbol, Convert.ToInt32(featureTypePairs.Value.Id))); } } } } } #endregion #region get coded value codes and descriptions var facilityField = fl.LayerInfo.Fields.Where(f => f.Name == "facility").First(); facilityFieldDomain = facilityField.Domain as CodedValueDomain; FacilityChoicesListBox.ItemsSource = facilityFieldDomain.CodedValues; var qualityField = fl.LayerInfo.Fields.Where(f => f.Name == "quality").First(); qualityFieldDomain = qualityField.Domain as CodedValueDomain; QualityChoicesListBox.ItemsSource = qualityFieldDomain.CodedValues; #endregion //enable the app bar and context menu items for (int i = 0; i < ApplicationBar.Buttons.Count; ++i) (ApplicationBar.Buttons[i] as IApplicationBarIconButton).IsEnabled = true; }
/// <summary> /// Initializes a new instance of the <see cref="FeatureDataFieldValueConverter"/> class. /// </summary> /// <param name="codedValueDomain">The coded value domain.</param> public FeatureDataFieldValueConverter(CodedValueDomain codedValueDomain) { this._codedValueDomain = codedValueDomain; }
public void MainMethodCode() { // Opening a Non-Versioned SQL Server instance. DatabaseConnectionProperties connectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer) { AuthenticationMode = AuthenticationMode.DBMS, // Where testMachine is the machine where the instance is running and testInstance is the name of the SqlServer instance. Instance = @"testMachine\testInstance", // Provided that a database called LocalGovernment has been created on the testInstance and geodatabase has been enabled on the database. Database = "LocalGovernment", // Provided that a login called gdb has been created and corresponding schema has been created with the required permissions. User = "******", Password = "******", Version = "dbo.DEFAULT" }; using (Geodatabase geodatabase = new Geodatabase(connectionProperties)) using (FeatureClass featureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.FacilitySite")) { FeatureClassDefinition featureClassDefinition = featureClass.GetDefinition(); int facilityCodeIndex = featureClassDefinition.FindField("FCODE"); Field field = featureClassDefinition.GetFields()[facilityCodeIndex]; Domain domain = field.GetDomain(featureClassDefinition.GetSubtypes().FirstOrDefault( subtype => subtype.GetName().ToLowerInvariant().Contains("agriculture"))); CodedValueDomain codedValueDomain = (CodedValueDomain)domain; // Will be "Agriculture Food and Livestock FCode"'. string name = codedValueDomain.GetName(); // Will be FieldType.String'. FieldType fieldType = codedValueDomain.GetFieldType(); // Will be "The type of agriculture, food and livestock facility"'. string description = codedValueDomain.GetDescription(); // Will be 13 since there are 13 code value pairs in this domain'. int numberOfcodedValues = codedValueDomain.GetCount(); // This will be a the code value pairs sorted (in this case) by the codes' increasing integer value. SortedList <object, string> codedValuePairs = codedValueDomain.GetCodedValuePairs(); FeatureClassDefinition siteAddressPointDefinition = geodatabase.GetDefinition <FeatureClassDefinition>("LocalGovernment.GDB.SiteAddressPoint"); int unitTypeIndex = siteAddressPointDefinition.FindField("UNITTYPE"); Field unitTypeField = siteAddressPointDefinition.GetFields()[unitTypeIndex]; Domain addressUnitTypeDomain = unitTypeField.GetDomain(); CodedValueDomain valueDomain = (CodedValueDomain)addressUnitTypeDomain; // Will be Apartment. string aptCodeDescription = valueDomain.GetName("APT"); // Will be Basement. string bsmtCodeDescription = valueDomain.GetName("BSMT"); // Will be DEPT. Make sure you know the domain's FieldType is String before cast. string departmentCode = valueDomain.GetCodedValue("Department") as string; // Will be FL. string floorCode = valueDomain.GetCodedValue("Floor") as string; } }