private static async Task EnterpriseGeodabaseWorkFlow() { // 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")) { EditOperation editOperation = new EditOperation(); editOperation.Callback(context => { RowBuffer rowBuffer = null; Feature feature = null; try { FeatureClassDefinition facilitySiteDefinition = enterpriseFeatureClass.GetDefinition(); int facilityIdIndex = facilitySiteDefinition.FindField("FACILITYID"); rowBuffer = enterpriseFeatureClass.CreateRowBuffer(); // Either the field index or the field name can be used in the indexer. rowBuffer[facilityIdIndex] = "FAC-400"; rowBuffer["NAME"] = "Griffith Park"; rowBuffer["OWNTYPE"] = "Municipal"; rowBuffer["FCODE"] = "Park"; // Add it to Public Attractions Subtype. rowBuffer[facilitySiteDefinition.GetSubtypeField()] = 820; List <Coordinate2D> newCoordinates = new List <Coordinate2D> { new Coordinate2D(1021570, 1880583), new Coordinate2D(1028730, 1880994), new Coordinate2D(1029718, 1875644), new Coordinate2D(1021405, 1875397) }; rowBuffer[facilitySiteDefinition.GetShapeField()] = new PolygonBuilder(newCoordinates).ToGeometry(); feature = enterpriseFeatureClass.CreateRow(rowBuffer); //To Indicate that the Map has to draw this feature and/or the attribute table to be updated context.Invalidate(feature); long objectID = feature.GetObjectID(); Polygon polygon = feature.GetShape() as Polygon; // Do some other processing with the newly-created feature. } catch (GeodatabaseException exObj) { Console.WriteLine(exObj); } finally { if (rowBuffer != null) { rowBuffer.Dispose(); } if (feature != null) { feature.Dispose(); } } }, enterpriseFeatureClass); bool editResult = editOperation.Execute(); // If the table is non-versioned this is a no-op. If it is versioned, we need the Save to be done for the edits to be persisted. bool saveResult = await Project.Current.SaveEditsAsync(); } }
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() { using (Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\Data\LocalGovernment.gdb")))) using (Table table = fileGeodatabase.OpenDataset <Table>("luCodeInspection")) { QueryFilter queryFilter = new QueryFilter { WhereClause = "ACTION = '1st Notice'" }; using (RowCursor cursor = table.Search(queryFilter)) // Using Recycling. { bool hasRow = cursor.MoveNext(); using (Row currentRow = cursor.Current) { TableDefinition tableDefinition = table.GetDefinition(); int trivialFindField = currentRow.FindField(currentRow.GetFields()[0].Name); // This will (obviously) give 0. int inspectIDIndex = currentRow.FindField("INSPECTID"); int violateKeyIndex = currentRow.FindField("violatekey"); int workKeyIndex = currentRow.FindField("WorkKey"); int subtypeFieldIndex = currentRow.FindField(tableDefinition.GetSubtypeField()); // Will be -1 since there are no subtypes. int objectIdFieldIndex = currentRow.FindField(tableDefinition.GetObjectIDField()); int minusOne = currentRow.FindField("Gibberish"); // This will be -1. } } } // 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 landUseCaseFeatureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.LandUseCase")) { QueryFilter filter = new QueryFilter { WhereClause = "CASETYPE = 'Rezoning'" }; using (RowCursor landUseCursor = landUseCaseFeatureClass.Search(filter, false)) { FeatureClassDefinition featureClassDefinition = landUseCaseFeatureClass.GetDefinition(); while (landUseCursor.MoveNext()) { Feature rezoningUseCase = (Feature)landUseCursor.Current; int caseIdIndex = rezoningUseCase.FindField("CASEID"); int caseNameIndex = rezoningUseCase.FindField("casename"); int applicantIndex = rezoningUseCase.FindField("Applicant"); int shapeFieldIndex = rezoningUseCase.FindField(featureClassDefinition.GetShapeField()); int subtypeIndex = rezoningUseCase.FindField(featureClassDefinition.GetSubtypeField()); // Will be -1 since there are no subtypes. int objectIdIndex = rezoningUseCase.FindField(featureClassDefinition.GetObjectIDField()); break; } } } }
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() { using (Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\Data\LocalGovernment.gdb")))) using (FeatureClass featureClass = fileGeodatabase.OpenDataset <FeatureClass>("PollingPlace")) { QueryFilter queryFilter = new QueryFilter { WhereClause = "CITY = 'Plainfield'" }; Selection selection = featureClass.Select(queryFilter, SelectionType.ObjectID, SelectionOption.Normal); // The result is a mapping between those object ids which failed validation and the reason why the validation failed (a string message). IReadOnlyDictionary <long, string> validationResult = featureClass.Validate(selection); RowCursor rowCursor = featureClass.Search(queryFilter, false); List <Feature> features = new List <Feature>(); try { while (rowCursor.MoveNext()) { features.Add(rowCursor.Current as Feature); } // This is equivalent to the validation performed using the selection. IReadOnlyDictionary <long, string> equivalentValidationResult = featureClass.Validate(features); // Again this is equivalent to both the above results. IReadOnlyDictionary <long, string> anotherEquivalentResult = featureClass.Validate(queryFilter); SpatialQueryFilter spatialQueryFilter = new SpatialQueryFilter { FilterGeometry = new EnvelopeBuilder( new MapPointBuilder(1052803, 1812751).ToGeometry(), new MapPointBuilder(1034600, 1821320).ToGeometry()).ToGeometry(), SpatialRelationship = SpatialRelationship.Within }; IReadOnlyDictionary <long, string> spatialFilterBasedValidationResult = featureClass.Validate(spatialQueryFilter); } finally { rowCursor.Dispose(); Dispose(features); } } // 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")) { QueryFilter parkFilter = new QueryFilter { WhereClause = "FCODE = 'Park'" }; Selection parkSelection = enterpriseFeatureClass.Select(parkFilter, SelectionType.ObjectID, SelectionOption.Normal); // Remember that validation cost is directly proprtional to the number of Features validated. So, select the set of features to be // validated judiciously. This will be empty because all the Park Features are valid. IReadOnlyDictionary <long, string> emptyDictionary = enterpriseFeatureClass.Validate(parkSelection); // We are adding an invalid feature to illustrate a case where the validation result is not empty. long invalidFeatureObjectID = -1; EditOperation editOperation = new EditOperation(); editOperation.Callback(context => { RowBuffer rowBuffer = null; Feature feature = null; try { FeatureClassDefinition facilitySiteDefinition = enterpriseFeatureClass.GetDefinition(); rowBuffer = enterpriseFeatureClass.CreateRowBuffer(); rowBuffer["FACILITYID"] = "FAC-400"; rowBuffer["NAME"] = "Griffith Park"; rowBuffer["OWNTYPE"] = "Municipal"; rowBuffer["FCODE"] = "Park"; // Note that this is an invalid subtype value. rowBuffer[facilitySiteDefinition.GetSubtypeField()] = 890; rowBuffer[facilitySiteDefinition.GetShapeField()] = new PolygonBuilder(new List <Coordinate2D> { new Coordinate2D(1021570, 1880583), new Coordinate2D(1028730, 1880994), new Coordinate2D(1029718, 1875644), new Coordinate2D(1021405, 1875397) }).ToGeometry(); feature = enterpriseFeatureClass.CreateRow(rowBuffer); invalidFeatureObjectID = feature.GetObjectID(); } catch (GeodatabaseException exObj) { Console.WriteLine(exObj); } finally { if (rowBuffer != null) { rowBuffer.Dispose(); } if (feature != null) { feature.Dispose(); } } }, enterpriseFeatureClass); editOperation.Execute(); // This will have one keypair value for the invalid row that was added. IReadOnlyDictionary <long, string> result = enterpriseFeatureClass.Validate(parkFilter); // This will say "invalid subtype code". string errorMessage = result[invalidFeatureObjectID]; } }