public void MainMethodCode() { Uri arcgisOnlineURL = new Uri("http://services1.arcgis.com/47GG2ga246DGaLwa/arcgis/rest/services/FeatureServiceName/FeatureServer"); ServiceConnectionProperties arcGISOnline = new ServiceConnectionProperties(arcgisOnlineURL); using (Geodatabase featureService = new Geodatabase(arcGISOnline)) { using (FeatureClass featureClass = featureService.OpenDataset <FeatureClass>("0")) { // Use the feature class opened from layer ID 0. } using (Table table = featureService.OpenDataset <Table>("4")) { // Use the table opened from layer ID 4. } using (AttributedRelationshipClass attributedRelationshipClass = featureService.OpenDataset <AttributedRelationshipClass>("5")) { // Use the attributed relationship class opened from layer ID 5. } try { string idOfLayerWhichIsNotTable = "3"; featureService.OpenDataset <Table>(idOfLayerWhichIsNotTable); } catch (InvalidOperationException) { // Handle Exception. } } }
/// <summary> /// Since the LocalGovernment Geodatabase does not have AttributedRelationshipClasses, the following method illustrates the behavior /// if such a dataset existed. /// </summary> 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 (AttributedRelationshipClass attributedRelationshipClass = geodatabase.OpenDataset <AttributedRelationshipClass>("LocalGovernment.GDB.ParcelToBuilding")) using (FeatureClass parcelFeatureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.Parcel")) using (FeatureClass buildingFeatureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.Building")) { QueryFilter parcelQueryFilter = new QueryFilter { WhereClause = "APN = 1234 OR APN = 5678" }; QueryFilter buildingQueryFilter = new QueryFilter { WhereClause = "BUILDID = 4321 OR BUILDID = 8765" }; Selection parcelsSelection = parcelFeatureClass.Select(parcelQueryFilter, SelectionType.ObjectID, SelectionOption.Normal); Selection buildingSelection = buildingFeatureClass.Select(buildingQueryFilter, SelectionType.ObjectID, SelectionOption.Normal); IReadOnlyList <AttributedRelationship> relationshipsForOrigin = null; IReadOnlyList <AttributedRelationship> relationshipsForDestination = null; try { relationshipsForOrigin = attributedRelationshipClass.GetRelationshipsForOriginRows(parcelsSelection.GetObjectIDs()); relationshipsForDestination = attributedRelationshipClass.GetRelationshipsForDestinationRows(buildingSelection.GetObjectIDs()); } finally { Dispose(relationshipsForOrigin); Dispose(relationshipsForDestination); } } }
/// <summary> /// Since the LocalGovernment Geodatabase does not have AttributedRelationshipClasses, the following method illustrates the behavior /// if such a dataset existed. /// </summary> public async Task 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 (AttributedRelationshipClass attributedRelationshipClass = geodatabase.OpenDataset <AttributedRelationshipClass>("LocalGovernment.GDB.ParcelToBuilding")) using (FeatureClass parcelFeatureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.Parcel")) using (FeatureClass buildingFeatureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.Building")) { RowCursor parcelsCursor = parcelFeatureClass.Search(new QueryFilter { WhereClause = "APN = 5678" }, false); parcelsCursor.MoveNext(); Row parcelFeature = parcelsCursor.Current; RowCursor buildingsCursor = buildingFeatureClass.Search(new QueryFilter { WhereClause = "BUILDID = 4321" }, false); buildingsCursor.MoveNext(); Row buildingFeature = buildingsCursor.Current; try { EditOperation editOperation = new EditOperation(); editOperation.Callback(context => { // Assuming such a relationship exists. attributedRelationshipClass.DeleteRelationship(parcelFeature, buildingFeature); }, attributedRelationshipClass); bool executeResult = editOperation.Execute(); bool saveResult = await Project.Current.SaveEditsAsync(); IReadOnlyList <AttributedRelationship> relationshipsForOriginRows = attributedRelationshipClass.GetRelationshipsForOriginRows( new List <long> { parcelFeature.GetObjectID() }); // This will be null. AttributedRelationship newlyAddedRelationship = relationshipsForOriginRows.FirstOrDefault(relationship => relationship.GetDestinationRow().GetObjectID() == buildingFeature.GetObjectID()); } finally { parcelsCursor.Dispose(); if (parcelFeature != null) { parcelFeature.Dispose(); } buildingsCursor.Dispose(); if (buildingFeature != null) { buildingFeature.Dispose(); } } } }