/// <summary> /// Check to make sure the enviornment is set up correctly before processing the users request /// /// </summary> /// <returns></returns> private async Task <bool> CheckRequirements() { if (_selectedMap == null) { MessageBox.Show("Select A Map In Domain Appointer Settings"); return(false); } if (_selectedLayer == null) { MessageBox.Show("Select A Layer in Domain Appointer Settings"); return(false); } if (_selectedField == null) { MessageBox.Show("Select a Field in Domain Appointer Settings"); } bool canEditData = false; await QueuedTask.Run(() => { canEditData = _selectedLayer.CanEditData(); }); if (!canEditData) { MessageBox.Show("Feature Layer '" + _selectedLayer.Name + "' Is not Editable"); return(false); } IEnumerable <Field> fields = null; await QueuedTask.Run(() => { Table table = _selectedLayer.GetTable(); if (table is FeatureClass) { FeatureClass featureclass = table as FeatureClass; using (FeatureClassDefinition def = featureclass.GetDefinition()) { fields = def.GetFields(); } } }); var match = fields.FirstOrDefault(field => field.Name.ToLower().Contains(_selectedField.ToLower())); if (match == null) { MessageBox.Show("The field '" + _selectedField + "' is Missing From '" + _selectedLayer.Name + "' Feature Layer"); return(false); } return(true); }
private async Task <Boolean> CheckRequirements() { if (_selectedMap == null) { MessageBox.Show("Select A Map In File Tile Opener Settings"); return(false); } if (_selectedFeatureLayer == null) { MessageBox.Show("Select A Layer in File Tile Opener Settings"); return(false); } if (_selectedField == null) { MessageBox.Show("Select a Field in File Tile Opener Settings"); } IEnumerable <Field> fields = null; await QueuedTask.Run(() => { Table table = _selectedFeatureLayer.GetTable(); if (table is FeatureClass) { FeatureClass featureclass = table as FeatureClass; using (FeatureClassDefinition def = featureclass.GetDefinition()) { fields = def.GetFields(); } } }); var match = fields.FirstOrDefault(field => field.Name.ToLower().Contains(_selectedField.ToLower())); if (match == null) { MessageBox.Show("This field '" + _selectedField + "' is Missing From '" + _selectedFeatureLayer.Name + "' Feature Layer", "Oops"); return(false); } // No need to check for whitespace. I disallow this in the 'view'. if (String.IsNullOrEmpty(_fileExtension)) { MessageBox.Show("Type or Choose a File Extension in File Tile Opener Settings"); return(false); } if (String.IsNullOrWhiteSpace(_fileWorkspace)) { MessageBox.Show("Type or Choose a File Workspace in File Tile Opener Settings"); return(false); } return(true); }
/// <summary> /// Validates Conditions for user before attempting to edit the data /// </summary> /// <returns></returns> private async Task <bool> PrepStatus() { if (_selectedMap == null) { MessageBox.Show("Select A Map In Inspector Settings"); return(false); } if (_selectedLayer == null) { MessageBox.Show("Select A Layer in Inspector Settings"); return(false); } IEnumerable <Field> fields = null; FeatureClass featureclass = null; await QueuedTask.Run(() => { // Get the fields Table table = (_selectedLayer as FeatureLayer).GetTable(); if (table is FeatureClass) { featureclass = table as FeatureClass; using (FeatureClassDefinition def = featureclass.GetDefinition()) { fields = def.GetFields(); } } }); var match = fields.FirstOrDefault(field => field.Name.ToLower().Contains(InpsectorFieldName.ToLower())); if (match == null) { MessageBox.Show("Add field named '" + InpsectorFieldName + "' to '" + _selectedLayer.Name + "' layer of type Integer"); return(false); } match = fields.FirstOrDefault(field => (field.FieldType == FieldType.SmallInteger || field.FieldType == FieldType.Integer)); if (match == null) { MessageBox.Show("Add field named '" + InpsectorFieldName + "' to '" + _selectedLayer.Name + "' layer of type Integer"); return(false); } return(true); }
double GetLength(FeatureClass fc, EnterpriseDatabaseType enterpriseDbType) { try { using (FeatureClassDefinition fcd = fc.GetDefinition()) { // the name of the length field changes depending on what enterprise geodatabase is used var areaFieldName = "Shape_Length"; switch (enterpriseDbType) { case EnterpriseDatabaseType.SQLServer: areaFieldName = "STLength"; break; } Field lengthField = fcd.GetFields().FirstOrDefault(x => x.Name.Contains(areaFieldName)); if (lengthField == null) { return(0); } System.Diagnostics.Debug.WriteLine(lengthField.Name); StatisticsDescription SumDesc = new StatisticsDescription(lengthField, new List <StatisticsFunction>() { StatisticsFunction.Sum }); TableStatisticsDescription tsd = new TableStatisticsDescription(new List <StatisticsDescription>() { SumDesc }); double sum = 0; try { sum = fc.CalculateStatistics(tsd).FirstOrDefault().StatisticsResults.FirstOrDefault().Sum; // exception is thrown on this line } catch { sum = Utilities.GetSumWorkAround(fc, lengthField.Name); } return(sum); } } catch (Exception ex) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(ex.ToString(), "Error"); return(0); } }
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 (FeatureClassDefinition featureClassDefinition = geodatabase.GetDefinition <FeatureClassDefinition>("LocalGovernment.GDB.ServiceRequestComment")) { int rankIndex = featureClassDefinition.FindField("RANK"); Field field = featureClassDefinition.GetFields()[rankIndex]; Domain domain = field.GetDomain(); RangeDomain rangeDomain = (RangeDomain)domain; // Will be "ServiceRequestRanking". string name = rangeDomain.GetName(); // Will be FieldType.Integer. FieldType fieldType = rangeDomain.GetFieldType(); // Will be "A factor assigned to unassigned service requests indicating importance". string description = rangeDomain.GetDescription(); // Will be 1. int minValue = Convert.ToInt32(rangeDomain.GetMinValue()); // Will be 5. int maxValue = Convert.ToInt32(rangeDomain.GetMaxValue()); } }
public void MainMethodCode() { Uri serviceUrl = new Uri("https://arcgis.server.example.com:6443/arcgis/rest/services/FeatureServiceName/FeatureServer"); ServiceConnectionProperties arcGisServer = new ServiceConnectionProperties(serviceUrl) { User = "******", Password = "******" }; using (Geodatabase serverFeatureService = new Geodatabase(arcGisServer)) { FeatureClassDefinition featureClassDefinition = serverFeatureService.GetDefinition <FeatureClassDefinition>("0"); string shapeField = featureClassDefinition.GetShapeField(); IReadOnlyList <Field> fields = featureClassDefinition.GetFields(); TableDefinition tableDefinition = serverFeatureService.GetDefinition <TableDefinition>("4"); string objectIDField = tableDefinition.GetObjectIDField(); } }
double GetArea(FeatureClass fc) { try { using (FeatureClassDefinition fcd = fc.GetDefinition()) { // the name of the area field changes depending on what enterprise geodatabase is used var areaFieldName = "Shape_Area"; Field areaField = fcd.GetFields().FirstOrDefault(x => x.Name.Contains(areaFieldName)); if (areaField == null) { return(0); } System.Diagnostics.Debug.WriteLine(areaField.Name); // Output is "Shape.STArea()" as expected StatisticsDescription SumDesc = new StatisticsDescription(areaField, new List <StatisticsFunction>() { StatisticsFunction.Sum }); TableStatisticsDescription tsd = new TableStatisticsDescription(new List <StatisticsDescription>() { SumDesc }); double sum = 0; try { sum = fc.CalculateStatistics(tsd).FirstOrDefault().StatisticsResults.FirstOrDefault().Sum; // exception is thrown on this line } catch { sum = Utilities.GetSumWorkAround(fc, areaField.Name); } return(sum); } } catch (Exception ex) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(ex.ToString(), "Error"); return(0); } }
/// <summary> /// Gets all the field in the selected layer that meets requirement and adds them to the drop down list /// </summary> private async void PopulateLayerFields() { _fields.Clear(); IEnumerable <Field> fields = null; FeatureClass featureclass = null; await QueuedTask.Run(() => { Table table = _selectedLayer.GetTable(); if (table is FeatureClass) { featureclass = table as FeatureClass; using (FeatureClassDefinition def = featureclass.GetDefinition()) { fields = def.GetFields(); } foreach (Field field in fields) { Domain domain = field.GetDomain(); if (domain != null) { FieldType fieldType = domain.GetFieldType(); if (fieldType == FieldType.SmallInteger || fieldType == FieldType.Integer) { _fields.Add(field.Name); } ; } } } }); if (_fields.Count <= 0) { MessageBox.Show("No Valid Fields in '" + _selectedLayer.Name + "' Feature Layer"); } }
/// <summary> /// Adds the selected feature layer's field to the '_fields' collection /// </summary> private async void PopulateFeatureLayerFields() { _fields.Clear(); IEnumerable <Field> fields = null; FeatureClass featureclass = null; await QueuedTask.Run(() => { Table table = _selectedFeatureLayer.GetTable(); if (table is FeatureClass) { featureclass = table as FeatureClass; using (FeatureClassDefinition def = featureclass.GetDefinition()) { fields = def.GetFields(); } foreach (Field field in fields) { FieldType fieldType = field.FieldType; // Change field type acceptance here if (fieldType == FieldType.SmallInteger || fieldType == FieldType.Integer || fieldType == FieldType.String || fieldType == FieldType.Double || fieldType == FieldType.Single || fieldType == FieldType.GUID) { _fields.Add(field.Name); } ; } } }); if (_fields.Count <= 0) { MessageBox.Show("No Valid Fields in '" + _selectedFeatureLayer.Name + "' Feature Layer"); } }
private async void cboLayerList_SelectionChanged(object sender, SelectionChangedEventArgs e) { string lname = cboLayerList.SelectedItem.ToString(); var mv = MapView.Active; FeatureLayer fl = mv.Map.FindLayers(lname).FirstOrDefault() as FeatureLayer; var fields = await QueuedTask.Run(() => { FeatureClass fc = fl.GetFeatureClass(); FeatureClassDefinition fcdef = fc.GetDefinition(); return(fcdef.GetFields()); }); lstFields.Items.Clear(); for (int i = 0; i < fields.Count; i++) { Field fld = fields[i]; if (fld.FieldType == FieldType.String) { lstFields.Items.Add(fld.Name); } } lstFields.SelectAll(); }
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 enterpriseFeatureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.FacilitySite")) { FeatureClassDefinition facilitySiteDefinition = enterpriseFeatureClass.GetDefinition(); int facilityCodeIndex = facilitySiteDefinition.FindField("FCODE"); int ownerTypeIndex = facilitySiteDefinition.FindField("OWNTYPE"); int subtypeFieldIndex = facilitySiteDefinition.FindField(facilitySiteDefinition.GetSubtypeField()); // Agriculture, Food and Livestock subtype. Subtype agricultureSubtype = facilitySiteDefinition.GetSubtypes().First(subtype => subtype.GetCode() == 701); // Industry Subtype. Subtype industrySubtype = facilitySiteDefinition.GetSubtypes().First(subtype => subtype.GetName().Equals("Industry")); Field faclilityCodeField = facilitySiteDefinition.GetFields()[facilityCodeIndex]; // This will be null since there is not domain assigned at the field level. Domain facilityCodeFieldLevelDomain = faclilityCodeField.GetDomain(); Domain facilityCodeAgricultureSubtypeDomain = faclilityCodeField.GetDomain(agricultureSubtype); // This will be "Agriculture Food and Livestock FCode". string facilityCodeAgricultureSubtypeDomainName = facilityCodeAgricultureSubtypeDomain.GetName(); Domain facilityCodeIndustrySubtypeDomain = faclilityCodeField.GetDomain(industrySubtype); // This will be "Industry FCode" string facilityCodeIndustrySubtypeDomainName = facilityCodeIndustrySubtypeDomain.GetName(); Field ownerTypeField = facilitySiteDefinition.GetFields()[ownerTypeIndex]; Domain ownerTypeFieldLevelDomain = ownerTypeField.GetDomain(); // This will be "OwnerType". string ownerTypeFieldLevelDomainName = ownerTypeFieldLevelDomain.GetName(); Domain ownerTypeAgricultureSubtypeDomain = ownerTypeField.GetDomain(agricultureSubtype); // This will be "OwnerType" because the same domain has been set at the subtype level. string ownerTypeAgricultureSubtypeDomainName = ownerTypeAgricultureSubtypeDomain.GetName(); Domain ownerTypeIndustrySubtypeDomain = ownerTypeField.GetDomain(industrySubtype); // This will be "OwnerType" because the same domain has been set at the subtype level. string ownerTypeIndustrySubtypeDomainName = ownerTypeIndustrySubtypeDomain.GetName(); Field subtypeField = facilitySiteDefinition.GetFields()[subtypeFieldIndex]; // This will be null. Domain subtypeField_FieldLevelDomain = subtypeField.GetDomain(); // This will be null. Domain subtypeField_AgricultureSubtypeDomain = subtypeField.GetDomain(agricultureSubtype); // This will be null. Domain subtypeField_IndustrySubtypeDomain = subtypeField.GetDomain(industrySubtype); } }
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 enterpriseFeatureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.FacilitySite")) { FeatureClassDefinition facilitySiteDefinition = enterpriseFeatureClass.GetDefinition(); int facilityCodeIndex = facilitySiteDefinition.FindField("FCODE"); int subtypeFieldIndex = facilitySiteDefinition.FindField(facilitySiteDefinition.GetSubtypeField()); // Agriculture, Food and Livestock subtype. Subtype agricultureSubtype = facilitySiteDefinition.GetSubtypes().First(subtype => subtype.GetCode() == 701); // Industry Subtype. Subtype industrySubtype = facilitySiteDefinition.GetSubtypes().First(subtype => subtype.GetName().Equals("Industry")); Field faclilityCodeField = facilitySiteDefinition.GetFields()[facilityCodeIndex]; // This will be true since FCODE is a Text field. if (faclilityCodeField.FieldType.Equals(FieldType.String)) { // This will be null since at the field level there is no default value. string fieldLevelDefaultValue = faclilityCodeField.GetDefaultValue() as String; // This will be "Agriculture or Livestock Structure". string defaultValueForAgricultureSubtype = faclilityCodeField.GetDefaultValue(agricultureSubtype) as String; // This will be "Industrial Facility". string defaultValueForIndustrySubtype = faclilityCodeField.GetDefaultValue(industrySubtype) as String; } Field subtypeField = facilitySiteDefinition.GetFields()[subtypeFieldIndex]; // This will be true since SUBTYPEFIELD is a Long Integer field. if (subtypeField.FieldType.Equals(FieldType.Integer)) { // This will be 701 since at the field level the default value is set. int fieldLevelDefaultValue = Convert.ToInt32(subtypeField.GetDefaultValue()); // This will give you 701 since it is Agriculture, Food and Livestock subtype subtype. int defaultValueForAgricultureSubtype = Convert.ToInt32(subtypeField.GetDefaultValue(agricultureSubtype)); // This will give you 710 since it is Industry subtype. int defaultValueForIndustrySubtype = Convert.ToInt32(subtypeField.GetDefaultValue(industrySubtype)); } } }
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; } }
/// <summary> /// Check to make sure the enviorment is set up correctly before processing the users request /// </summary> /// <returns></returns> private async Task <bool> CheckRequirements() { if (_selectedMap == null) { MessageBox.Show("Select a Map in File Tile Cloner Settings", "Oops"); return(false); } if (_selectedFeatureLayer == null) { MessageBox.Show("Select a Feature Layer In File Tile Cloner Settings", "Oops"); return(false); } if (string.IsNullOrEmpty(_selectedField)) { MessageBox.Show("Select A Field In File Tile Cloner Settings", "Oops"); return(false); } IEnumerable <Field> fields = null; await QueuedTask.Run(() => { Table table = _selectedFeatureLayer.GetTable(); if (table is FeatureClass) { FeatureClass featureclass = table as FeatureClass; using (FeatureClassDefinition def = featureclass.GetDefinition()) { fields = def.GetFields(); } } }); var match = fields.FirstOrDefault(field => field.Name.ToLower().Contains(_selectedField.ToLower())); if (match == null) { MessageBox.Show("This field '" + _selectedField + "' is Missing From '" + _selectedFeatureLayer.Name + "' Feature Layer", "Oops"); return(false); } // No need to check for whitespace. I disallow this in the 'view'. if (string.IsNullOrEmpty(_fileExtension)) { MessageBox.Show("Type or Choose a File Extension"); return(false); } if (string.IsNullOrWhiteSpace(_fileWorkspace)) { MessageBox.Show("Type or Choose a File Workspace"); return(false); } if (_fileCloningMethod == EnumFileCloningMethod.None) { MessageBox.Show("Select a File Cloner Method", "Oops"); return(false); } if (_fileCloningMethod == EnumFileCloningMethod.Selected) { var result = await QueuedTask.Run(() => { var selection = _selectedFeatureLayer.GetSelection(); if (selection.GetCount() <= 0) { MessageBox.Show("Select at least one feature"); return(false); } return(true); }); if (!result) { return(result); } } return(true); }