Beispiel #1
0
        public void MainMethodCode()
        {
            // Opens a file geodatabase  This will open the geodatabase if the folder exists and contains a valid geodatabase.

            using (Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\Data\LocalGovernment.gdb"))))
            {
                TableDefinition tableDefinition = fileGeodatabase.GetDefinition <TableDefinition>("CitizenContactInfo");

                // Use the fileGeodatabase and tableDefinition.
            }

            // 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)))
            {
                // Remember that for Enterprise databases you have to qualify your dataset names with the DatabaseName and UserName.
                TableDefinition enterpriseTableDefinition = geodatabase.GetDefinition <TableDefinition>("LocalGovernment.GDB.CitizenContactInfo");

                // It does not matter if the dataset is within a FeatureDataset or not.
                FeatureClassDefinition featureClassDefinition = geodatabase.GetDefinition <FeatureClassDefinition>("LocalGovernment.GDB.FireStation");

                // GetDefinition For a RelationshipClass.
                RelationshipClassDefinition relationshipClassDefinition = geodatabase.GetDefinition <RelationshipClassDefinition>("LocalGovernment.GDB.AddressPointHasSiteAddresses");

                // GetDefinition For a FeatureDataset.
                FeatureDatasetDefinition featureDatasetDefinition = geodatabase.GetDefinition <FeatureDatasetDefinition>("LocalGovernment.GDB.Address")
                ;
                try
                {
                    // Note that although you can open a FeatureClass as a Table using OpenDataset, you cannot call GetDefinition on a FeatureClass with DatasetType.Table.
                    geodatabase.GetDefinition <TableDefinition>("LocalGovernment.GDB.FireStation");

                    // Attempting to open a FeatureDataset as a RelationshipClass will fail.
                    // This is an example i.e. any mismatch between DatasetType specified and Actual DatasetType will cause GetDefinition to fail.
                    geodatabase.GetDefinition <RelationshipClassDefinition>("LocalGovernment.GDB.Address");

                    // If you do not qualify your Dataset Name GetDefinition fails. Note that this worked for File Geodatabase.
                    geodatabase.GetDefinition <TableDefinition>("CitizenContactInfo");

                    // Trying to GetDefinition of a non existent dataset.
                    geodatabase.GetDefinition <TableDefinition>("SomeRandomString");
                }
                catch (GeodatabaseCatalogDatasetException catalogDatasetException)
                {
                    // All of the above scenarios will result in GeodatabaseCatalogDatasetException with a message "Item Not Found".
                    // Remember that when you get this exception, most likely the following are the reasons.
                    // 1. The Item might not exist.
                    // 2. There might be a mismatch between DatasetType specified and Actual DatasetType.
                    // 3. The qualification for the DatasetName is wrong.
                    // 4. The User does not have visibility to the dataset
                }
            }
        }
        private async Task SetupDefinitionDetailsAsync()
        {
            DefinitionDetails.Clear();
            try
            {
                var lstDefs = await QueuedTask.Run <List <string> >(() =>
                {
                    Definition datasetDefinition = Dataset.DatasetDefinition;
                    List <string> lstDefDetails  = new List <string>();
                    if (datasetDefinition is TableDefinition)
                    {
                        TableDefinition tableDefinition = datasetDefinition as TableDefinition;
                        lstDefDetails.Add($"Object ID Field: {tableDefinition.GetObjectIDField()}");
                        StringBuilder stringBuilder = new StringBuilder();

                        if (!(_datastore is FileSystemDatastore))
                        {
                            lstDefDetails.Add($"Alias Name: {tableDefinition.GetAliasName()}");
                            lstDefDetails.Add($"CreatedAt Field: {tableDefinition.GetCreatedAtField()}");
                            lstDefDetails.Add($"Creator Field: {tableDefinition.GetCreatorField()}");
                            lstDefDetails.Add($"Subtype Field: {tableDefinition.GetSubtypeField()}");
                            lstDefDetails.Add($"Default Subtype Code: {tableDefinition.GetDefaultSubtypeCode()}");
                            lstDefDetails.Add($"EditedAt Field: {tableDefinition.GetEditedAtField()}");
                            lstDefDetails.Add($"Editor Field: {tableDefinition.GetEditorField()}");
                            lstDefDetails.Add($"Global ID Field: {tableDefinition.GetGlobalIDField()}");
                            lstDefDetails.Add($"Model Name: {tableDefinition.GetModelName()}");
                            foreach (var subtype in tableDefinition.GetSubtypes())
                            {
                                stringBuilder.Append(subtype.GetCode()).Append(": ").Append(subtype.GetName()).Append(Environment.NewLine);
                            }
                            lstDefDetails.Add($"Subtypes: {stringBuilder}");
                        }
                        stringBuilder = new StringBuilder();
                        foreach (Index index in tableDefinition.GetIndexes())
                        {
                            stringBuilder.Append(index.GetName()).Append(",");
                            string order = index.IsAscending() ? "Ascending" : "Descending";
                            stringBuilder.Append(order).Append(", ");
                            string unique = index.IsUnique() ? "Unique" : "Not Unique";
                            stringBuilder.Append(unique);
                        }
                        lstDefDetails.Add($"Indexes: {stringBuilder}");
                    }

                    if (datasetDefinition is FeatureClassDefinition)
                    {
                        FeatureClassDefinition featureClassDefinition = datasetDefinition as FeatureClassDefinition;
                        if (!(_datastore is FileSystemDatastore))
                        {
                            lstDefDetails.Add($"Area Field: {featureClassDefinition.GetAreaField()}");
                            lstDefDetails.Add($"Length Field: {featureClassDefinition.GetLengthField()}");
                        }
                        lstDefDetails.Add($"Shape Field: {featureClassDefinition.GetShapeField()}");
                        lstDefDetails.Add($"Shape Type: {featureClassDefinition.GetShapeType()}");
                        lstDefDetails.Add($"Spatial Reference Name: {featureClassDefinition.GetSpatialReference().Name}");
                        Envelope extent = featureClassDefinition.GetExtent();
                        lstDefDetails.Add($"Extent Details: XMin-{extent.XMin} XMax-{extent.XMax} YMin-{extent.YMin} YMax-{extent.YMax}");
                    }

                    if (datasetDefinition is FeatureDatasetDefinition)
                    {
                        FeatureDatasetDefinition featureDatasetDefinition = datasetDefinition as FeatureDatasetDefinition;
                        lstDefDetails.Add($"Spatial Reference Name: {featureDatasetDefinition.GetSpatialReference().Name}");
                        try
                        {
                            Envelope extent = featureDatasetDefinition.GetExtent();
                            lstDefDetails.Add($"Extent Details: XMin-{extent.XMin} XMax-{extent.XMax} YMin-{extent.YMin} YMax-{extent.YMax}");
                        }
                        catch (Exception)
                        {
                            lstDefDetails.Add("Could not get extent");
                        }
                    }

                    if (datasetDefinition is RelationshipClassDefinition)
                    {
                        RelationshipClassDefinition relationshipClassDefinition = datasetDefinition as RelationshipClassDefinition;
                        lstDefDetails.Add($"Alias Name: {relationshipClassDefinition.GetAliasName()}");
                        lstDefDetails.Add($"Cardinality: {relationshipClassDefinition.GetCardinality()}");
                        lstDefDetails.Add($"Origin Class: {relationshipClassDefinition.GetOriginClass()}");
                        lstDefDetails.Add($"Destination Class: {relationshipClassDefinition.GetDestinationClass()}");
                        lstDefDetails.Add($"Origin Primary Key: {relationshipClassDefinition.GetOriginKeyField()}");
                        lstDefDetails.Add($"Origin Foreign Key: {relationshipClassDefinition.GetOriginForeignKeyField()}");
                        lstDefDetails.Add($"Is Attachement?: {relationshipClassDefinition.IsAttachmentRelationship()}");
                        lstDefDetails.Add($"Is Composite Relationship?: {relationshipClassDefinition.IsComposite()}");
                    }

                    if (datasetDefinition is AttributedRelationshipClassDefinition)
                    {
                        AttributedRelationshipClassDefinition relationshipClassDefinition = datasetDefinition as AttributedRelationshipClassDefinition;
                        lstDefDetails.Add($"Destination Key: {relationshipClassDefinition.GetDestinationKeyField()}");
                        lstDefDetails.Add($"Destination Foreign Key: {relationshipClassDefinition.GetDestinationForeignKeyField()}");
                        lstDefDetails.Add($"Object ID Field: {relationshipClassDefinition.GetObjectIDField()}");
                    }
                    return(lstDefDetails);
                });

                DefinitionDetails.AddRange(lstDefs);
            }
            catch (Exception exObj)
            {
                MessageBox.Show(exObj.Message, "Error");
            }
        }
        public void MainMethodCode()
        {
            // Opens a file geodatabase  This will open the geodatabase if the folder exists and contains a valid geodatabase.

            using (Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\Data\LocalGovernment.gdb"))))
            {
                RelationshipClassDefinition definition  = fileGeodatabase.GetDefinition <RelationshipClassDefinition>("AddressPointHasSiteAddresses");
                IReadOnlyList <Definition>  definitions = fileGeodatabase.GetRelatedDefinitions(definition, DefinitionRelationshipType.DatasetsRelatedThrough);

                // This will not be null.
                FeatureClassDefinition addressPointDefinition = definitions.First(defn => defn.GetName().Equals("AddressPoint")) as FeatureClassDefinition;

                // This will not be null.
                FeatureClassDefinition siteAddressPointDefinition = definitions.First(defn => defn.GetName().Equals("SiteAddressPoint")) as FeatureClassDefinition;
            }

            // 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))
            {
                // Remember the qualification of DatabaseName. for the RelationshipClass.
                RelationshipClassDefinition enterpriseDefinition  = geodatabase.GetDefinition <RelationshipClassDefinition>("LocalGovernment.GDB.AddressPointHasSiteAddresses");
                IReadOnlyList <Definition>  enterpriseDefinitions = geodatabase.GetRelatedDefinitions(enterpriseDefinition, DefinitionRelationshipType.DatasetsRelatedThrough);

                // This will not be null.
                FeatureClassDefinition enterpriseAddressPointDefinition = enterpriseDefinitions.First(
                    defn => defn.GetName().Equals("LocalGovernment.GDB.AddressPoint")) as FeatureClassDefinition;

                // This will not be null.
                FeatureClassDefinition enterpriseSiteAddressPointDefinition = enterpriseDefinitions.First(
                    defn => defn.GetName().Equals("LocalGovernment.GDB.SiteAddressPoint")) as FeatureClassDefinition;

                FeatureDatasetDefinition   featureDatasetDefinition = geodatabase.GetDefinition <FeatureDatasetDefinition>("LocalGovernment.GDB.Address");
                IReadOnlyList <Definition> datasetsInAddressDataset = geodatabase.GetRelatedDefinitions(featureDatasetDefinition, DefinitionRelationshipType.DatasetInFeatureDataset);

                // This will not be null.
                FeatureClassDefinition addressPointInAddressDataset = datasetsInAddressDataset.First(
                    defn => defn.GetName().Equals("LocalGovernment.GDB.AddressPoint")) as FeatureClassDefinition;

                // This will not be null.
                FeatureClassDefinition siteAddressPointInAddressDataset = datasetsInAddressDataset.First(
                    defn => defn.GetName().Equals("LocalGovernment.GDB.SiteAddressPoint")) as FeatureClassDefinition;

                // This will not be null.
                FeatureClassDefinition addressEntryPointInAddressDataset = datasetsInAddressDataset.First(
                    defn => defn.GetName().Equals("LocalGovernment.GDB.AddressEntrancePoint")) as FeatureClassDefinition;

                // This will not be null.
                RelationshipClassDefinition addressPointHasSiteAddressInAddressDataset = datasetsInAddressDataset.First(
                    defn => defn.GetName().Equals("LocalGovernment.GDB.AddressPointHasSiteAddresses")) as RelationshipClassDefinition;

                // This will not be null.
                RelationshipClassDefinition siteAddressHasPostalAddressInAddressDataset = datasetsInAddressDataset.First(
                    defn => defn.GetName().Equals("LocalGovernment.GDB.SiteAddresshasPostalAddresses")) as RelationshipClassDefinition;

                FeatureClassDefinition featureClassDefinition = geodatabase.GetDefinition <FeatureClassDefinition>("LocalGovernment.GDB.AddressPoint");
                // This will be empty.
                IReadOnlyList <Definition> emptyDefinitionList = geodatabase.GetRelatedDefinitions(featureClassDefinition, DefinitionRelationshipType.DatasetInFeatureDataset);

                TableDefinition tableClassDefinition = geodatabase.GetDefinition <TableDefinition>("LocalGovernment.GDB.EmployeeInfo");
                // This will be empty.
                IReadOnlyList <Definition> anotherEmptyDefinitionList = geodatabase.GetRelatedDefinitions(tableClassDefinition, DefinitionRelationshipType.DatasetsRelatedThrough);
            }
        }