private RelationshipClass MakeJoin(RelationshipClass relationshipClass, Table leftTable, Table rightTable) { var virtualRelationshipClassDescription = new VirtualRelationshipClassDescription(_leftField, _rightField, SelectedCardinality.RelationshipCardinality); relationshipClass = leftTable.RelateTo(rightTable, virtualRelationshipClassDescription); var joinDescription = new JoinDescription(relationshipClass) { JoinDirection = JoinDirection.Forward }; joinDescription.JoinType = IsLeftOuterJoin ? JoinType.LeftOuterJoin : JoinType.InnerJoin; if (LeftFields.Count > 1) { joinDescription.TargetFields = LeftFields.Select(item => item.Field).ToList(); } var join = new Join(joinDescription); var joinedTable = @join.GetJoinedTable(); if (joinedTable is FeatureClass) { LayerFactory.Instance.CreateFeatureLayer(joinedTable as FeatureClass, MapView.Active.Map, 0, LayerName); } return(relationshipClass); }
// // CONSTRUCTOR // public TabbedDocumentRelationship(RelationshipClass relationshipClass) { InitializeComponent(); this.relationshipModel1.RelationshipClass = relationshipClass; this.relationshipModel1.OpenModel(); this.Text = relationshipClass.Name; this.TabImage = this.relationshipModel1.Icon; }
/// <summary> /// Initializes a new instance of the <see cref="TestData" /> class. /// </summary> protected TestData( ) { SourceApp = new AppClass( ); TargetApp = new AppClass( ); Map = new MapClass( ); Relationship = new RelationshipClass( ); TypeA = new TypeClass( ); TypeB = new TypeClass( ); TypeAInstance = new TypeClass( ); TypeBInstance = new TypeClass( ); }
public CreateAnnoMasksEngine(CreateAnnoMasks config, IProcessingContext context, IProcessingFeedback feedback) : base(config.Name, context, feedback) { _inputDataset = OpenRequiredDataset(config.InputDataset, nameof(config.InputDataset)); _outputMaskDataset = OpenRequiredDataset(config.OutputMaskDataset, nameof(config.OutputMaskDataset)); _relationshipClass = OpenAssociation(config.OutputAssociation); _maskAttributes = ProcessingUtils.CreateFieldSetter( config.MaskAttributes, _outputMaskDataset.FeatureClass, nameof(config.MaskAttributes)); _maskMargin = ImplicitValue.Create(config.MaskMargin, nameof(config.MaskMargin)); _maskMargin.Environment = new StandardEnvironment().RegisterConversionFunctions(); _simplificationToleranceMu = config.SimplificationTolerance; // TODO convert mm to mu _maskOutlineType = config.MaskOutlineType; _fillHoles = config.FillHoles; }
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 (RelationshipClass relationshipClass = geodatabase.OpenDataset <RelationshipClass>("LocalGovernment.GDB.luCodeViolationHasInspections")) using (FeatureClass violationsFeatureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.luCodeViolation")) { List <Row> jeffersonAveViolations = new List <Row>(); QueryFilter queryFilter = new QueryFilter { WhereClause = "LOCDESC LIKE '///%Jefferson///%'" }; // If you need to *cache* the rows retrieved from the cursor for processing later, it is important that you don't use recycling in // the Search() method (i.e., useRecyclingCursor must be set to *false*). Also, the returned rows/features cached in the list // should be disposed when no longer in use so that unmanaged resources are not held on to longer than necessary. using (RowCursor rowCursor = violationsFeatureClass.Search(queryFilter, false)) { while (rowCursor.MoveNext()) { jeffersonAveViolations.Add(rowCursor.Current); } } foreach (Row jeffersoneAveViolation in jeffersonAveViolations) { IReadOnlyList <Row> relatedDestinationRows = relationshipClass.GetRowsRelatedToOriginRows(new List <long> { jeffersoneAveViolation.GetObjectID() }); try { EditOperation editOperation = new EditOperation(); editOperation.Callback(context => { foreach (Row relatedDestinationRow in relatedDestinationRows) { try { relationshipClass.DeleteRelationship(jeffersoneAveViolation, relatedDestinationRow); } catch (GeodatabaseRelationshipClassException exception) { Console.WriteLine(exception); } } }, relationshipClass); bool editResult = editOperation.Execute(); } finally { Dispose(relatedDestinationRows); } } try { // 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(); } finally { Dispose(jeffersonAveViolations); } } }
public void MainMethodCode() { // To run this code import the LocalGovernment.gdb to a sql server instance with the following settings. 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)) { // Safe cast to Table to get a table reference. using (Table table = geodatabase.OpenDataset <Table>("LocalGovernment.GDB.EmployeeInfo")) { } // Open a featureClass (within a feature dataset or outside a feature dataset). using (FeatureClass featureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.AddressPoint")) { } // You can open a FeatureClass as a Table which will give you a Table Reference. using (Table featureClassAsTable = geodatabase.OpenDataset <Table>("LocalGovernment.GDB.AddressPoint")) { // But it is really a FeatureClass object. FeatureClass featureClassOpenedAsTable = featureClassAsTable as FeatureClass; } // Open a FeatureDataset. using (FeatureDataset featureDataset = geodatabase.OpenDataset <FeatureDataset>("LocalGovernment.GDB.Address")) { } // Open a RelationsipClass. Just as you can open a FeatureClass as a Table, you can also open an AttributedRelationshipClass as a RelationshipClass. using (RelationshipClass relationshipClass = geodatabase.OpenDataset <RelationshipClass>("LocalGovernment.GDB.AddressPointHasSiteAddresses")) { } try { geodatabase.OpenDataset <Table>(null); } catch (ArgumentException exception) { //Providing a null for dataset name gives argument exception } try { geodatabase.OpenDataset <Table>("LocalGovernment.GDB.Something"); } catch (InvalidOperationException exception) { // Providing a non-existent dataset name gives Invalid Operation Exception } } }
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 (RelationshipClass relationshipClass = geodatabase.OpenDataset <RelationshipClass>("LocalGovernment.GDB.OverviewToProject")) using (FeatureClass projectsFeatureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.CIPProjects")) using (FeatureClass overviewFeatureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.CIPProjectsOverview")) { FeatureClassDefinition overviewDefinition = overviewFeatureClass.GetDefinition(); // Because the following fields are used in 2 places, it is more inefficient to get their respective indexes so that they can be resued. int projectManagerIndex = overviewDefinition.FindField("PROJECTMAN"); int fundSourceIndex = overviewDefinition.FindField("FUNDSOUR"); RelationshipClassDefinition relationshipClassDefinition = relationshipClass.GetDefinition(); // This will be PROJNAME. This can be used to get the field index or used directly as the field name. string originKeyField = relationshipClassDefinition.GetOriginKeyField(); EditOperation editOperation = new EditOperation(); editOperation.Callback(context => { // The rows are being added to illustrate adding relationships. If one has existing rows, those can be used to add a relationship. RowBuffer projectsRowBuffer = projectsFeatureClass.CreateRowBuffer(); projectsRowBuffer["TOTCOST"] = 500000; RowBuffer overviewRowBufferWithoutPKValue = overviewFeatureClass.CreateRowBuffer(); overviewRowBufferWithoutPKValue[projectManagerIndex] = "John Doe"; overviewRowBufferWithoutPKValue[fundSourceIndex] = "Public"; RowBuffer overviewRowBuffer = overviewFeatureClass.CreateRowBuffer(); overviewRowBuffer["PROJNAME"] = "LibraryConstruction"; overviewRowBuffer[projectManagerIndex] = "John Doe"; overviewRowBuffer[fundSourceIndex] = "Public"; using (Row projectsRow = projectsFeatureClass.CreateRow(projectsRowBuffer)) using (Row overviewRowWithoutPKValue = overviewFeatureClass.CreateRow(overviewRowBufferWithoutPKValue)) using (Row overviewRow = overviewFeatureClass.CreateRow(overviewRowBuffer)) { try { Relationship failingRelationship = relationshipClass.CreateRelationship(overviewRowWithoutPKValue, projectsRow); } catch (GeodatabaseRelationshipClassException exception) { // This will have a message "Unable to obtain origin primary key value.". So, the origin row needs to have the origin *primary* // key value referenced by the origin *foreign* key value in the RelationshipClass. Console.WriteLine(exception); } Relationship relationship = relationshipClass.CreateRelationship(overviewRow, projectsRow); //To Indicate that the Map has to draw this feature/row and/or the attribute table has to be updated context.Invalidate(projectsRow); context.Invalidate(overviewRow); context.Invalidate(relationshipClass); } }, projectsFeatureClass, overviewFeatureClass); 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() { using (Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\Data\LocalGovernment.gdb")))) using (FeatureDataset featureDataset = fileGeodatabase.OpenDataset<FeatureDataset>("Address")) using (FeatureClass featureClass = featureDataset.OpenDataset<FeatureClass>("AddressPoint")) using (RelationshipClass relationshipClass = featureDataset.OpenDataset<RelationshipClass>("AddressPointHasSiteAddresses")) { IReadOnlyList<Definition> definitions = fileGeodatabase.GetRelatedDefinitions(featureDataset.GetDefinition(), DefinitionRelationshipType.DatasetInFeatureDataset); foreach (Definition definition in definitions) { Dataset dataset = null; try { if (definition.DatasetType == DatasetType.Table) { dataset = featureDataset.OpenDataset<Table>(definition.GetName()); } else if (definition.DatasetType == DatasetType.FeatureClass) { dataset = featureDataset.OpenDataset<FeatureClass>(definition.GetName()); } else if (definition.DatasetType == DatasetType.RelationshipClass) { dataset = featureDataset.OpenDataset<RelationshipClass>(definition.GetName()); } else if (definition.DatasetType == DatasetType.AttributedRelationshipClass) { dataset = featureDataset.OpenDataset<AttributedRelationshipClass>(definition.GetName()); } // Do something with dataset } catch (InvalidOperationException exception) { //This exception is thrown if one of the datasets in the FeatureDatasets are not supported and thus marked as Unknown Console.WriteLine(exception); } finally { // Should explicitly dispose of a Dataset. if (dataset != null) dataset.Dispose(); } } } // 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 (FeatureDataset enterpriseFeatureDataset = geodatabase.OpenDataset<FeatureDataset>("LocalGovernment.GDB.ReferenceData")) using (FeatureClass communityCenter = enterpriseFeatureDataset.OpenDataset<FeatureClass>("LocalGovernment.GDB.CommunityCenter")) using (FeatureClass library = enterpriseFeatureDataset.OpenDataset<FeatureClass>("LocalGovernment.GDB.Library")) { try { // Trying to open non-existent RelationshipClasses and AttributedRelationshipClasses. Dataset badRelationshipClass = enterpriseFeatureDataset.OpenDataset<RelationshipClass>("SomeGibberish"); Dataset badAttributedRelationshipClass = enterpriseFeatureDataset.OpenDataset<AttributedRelationshipClass>("SomeGibberish"); } catch (GeodatabaseCatalogDatasetException exception) { // Thrown for RelationshipClass and AttributedRelationshipClass. } try { // Trying to open non-existent FeatureClasses. Dataset badFeatureClass = enterpriseFeatureDataset.OpenDataset<FeatureClass>("SomeGibberish"); } catch (GeodatabaseDatasetException exception) { // Thrown for FeatureClasses. } try { // Tables and FeatureDatasets cannot exist in a FeatureDataset. Dataset badFeatureDataset = enterpriseFeatureDataset.OpenDataset<FeatureDataset>("SomeGibberish"); Dataset badTable = enterpriseFeatureDataset.OpenDataset<Table>("SomeGibberish"); } catch (InvalidOperationException exception) { // Thrown for Table and FeatureDataset. } } }
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 (RelationshipClass relationshipClass = geodatabase.OpenDataset <RelationshipClass>("LocalGovernment.GDB.luCodeViolationHasInspections")) using (FeatureClass violationsFeatureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.luCodeViolation")) using (Table inspectionTable = geodatabase.OpenDataset <Table>("LocalGovernment.GDB.luCodeInspection")) { List <Row> jeffersonAveViolations = new List <Row>(); QueryFilter queryFilter = new QueryFilter { WhereClause = "LOCDESC LIKE '///%Jefferson///%'" }; // If you need to *cache* the rows retrieved from the cursor for processing later, it is important that you don't use recycling in // the Search() method (i.e., useRecyclingCursor must be set to *false*). Also, the returned rows/features cached in the list // should be disposed when no longer in use so that unmanaged resources are not held on to longer than necessary. using (RowCursor rowCursor = violationsFeatureClass.Search(queryFilter, false)) { while (rowCursor.MoveNext()) { jeffersonAveViolations.Add(rowCursor.Current); } } IReadOnlyList <Row> relatedOriginRows = null; IReadOnlyList <Row> relatedDestinationRows = null; try { QueryFilter filter = new QueryFilter { WhereClause = "ACTION = '1st Notice'" }; Selection selection = inspectionTable.Select(filter, SelectionType.ObjectID, SelectionOption.Normal); relatedOriginRows = relationshipClass.GetRowsRelatedToDestinationRows(selection.GetObjectIDs()); // Find out if any of 1st Notice inspections were from Jefferson Avenue. FeatureClassDefinition featureClassDefinition = violationsFeatureClass.GetDefinition(); int locationDescriptionIndex = featureClassDefinition.FindField("LOCDESC"); bool containsJeffersonAve = relatedOriginRows.Any(row => Convert.ToString(row[locationDescriptionIndex]).Contains("Jefferson")); List <long> jeffersonAveViolationObjectIds = jeffersonAveViolations.Select(row => row.GetObjectID()).ToList(); relatedDestinationRows = relationshipClass.GetRowsRelatedToOriginRows(jeffersonAveViolationObjectIds); //Find out if any Jefferson Ave Violations have 1st Notice Inspections TableDefinition tableDefinition = inspectionTable.GetDefinition(); int actionFieldIndex = tableDefinition.FindField("ACTION"); bool hasFirstNoticeInspections = relatedDestinationRows.Any(row => Convert.ToString(row[actionFieldIndex]).Contains("1st Notice")); } finally { Dispose(jeffersonAveViolations); Dispose(relatedOriginRows); Dispose(relatedDestinationRows); } } }