ArcGIS Pro SDK (八)地理数据库 2 界说
环境:Visual Studio 2022 + .NET6 + ArcGIS Pro SDK 3.0
1 从地理数据库获取界说
- public async Task ObtainingDefinitionFromGeodatabase()
- {
- await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(
- () =>
- {
- using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
- {
- // 对于企业级数据库,必须使用数据库名和用户名限定数据集名称。
- TableDefinition enterpriseTableDefinition = geodatabase.GetDefinition<TableDefinition>("LocalGovernment.GDB.CitizenContactInfo");
- // 无论数据集是否在 FeatureDataset 中,都没有关系。
- FeatureClassDefinition featureClassDefinition = geodatabase.GetDefinition<FeatureClassDefinition>("LocalGovernment.GDB.FireStation");
- // 获取 RelationshipClass 的定义。
- RelationshipClassDefinition relationshipClassDefinition = geodatabase.GetDefinition<RelationshipClassDefinition>("LocalGovernment.GDB.AddressPointHasSiteAddresses");
- // 获取 FeatureDataset 的定义。
- FeatureDatasetDefinition featureDatasetDefinition = geodatabase.GetDefinition<FeatureDatasetDefinition>("LocalGovernment.GDB.Address");
- }
- });
- }
复制代码 2 从地理数据库获取界说列表
- public async Task ObtainingDefinitionsFromGeodatabase()
- {
- await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(
- () =>
- {
- using (Geodatabase geodatabase = new Geodatabase(
- new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
- {
- var enterpriseDefinitions =
- geodatabase.GetDefinitions<FeatureClassDefinition>();
- IEnumerable<Definition> featureClassesHavingGlobalID =
- enterpriseDefinitions.Where(definition => definition.HasGlobalID());
- var featureDatasetDefinitions =
- geodatabase.GetDefinitions<FeatureDatasetDefinition>();
- bool electionRelatedFeatureDatasets =
- featureDatasetDefinitions.Any(
- definition => definition.GetName().Contains("Election"));
- var attributedRelationshipClassDefinitions =
- geodatabase.GetDefinitions<AttributedRelationshipClassDefinition>();
- var relationshipClassDefinitions =
- geodatabase.GetDefinitions<RelationshipClassDefinition>();
- }
- });
- }
复制代码 3 从地理数据库获取相干界说
- public async Task ObtainingRelatedDefinitionsFromGeodatabase()
- {
- await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(
- () =>
- {
- using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
- {
- // 对于 RelationshipClass,必须使用数据库名限定名称。
- RelationshipClassDefinition enterpriseDefinition =
- geodatabase.GetDefinition<RelationshipClassDefinition>("LocalGovernment.GDB.AddressPointHasSiteAddresses");
- IReadOnlyList<Definition> enterpriseDefinitions =
- geodatabase.GetRelatedDefinitions(enterpriseDefinition, DefinitionRelationshipType.DatasetsRelatedThrough);
- FeatureClassDefinition enterpriseAddressPointDefinition =
- enterpriseDefinitions.First(
- defn => defn.GetName().Equals("LocalGovernment.GDB.AddressPoint")) as FeatureClassDefinition;
- FeatureDatasetDefinition featureDatasetDefinition =
- geodatabase.GetDefinition<FeatureDatasetDefinition>("LocalGovernment.GDB.Address");
- IReadOnlyList<Definition> datasetsInAddressDataset =
- geodatabase.GetRelatedDefinitions(featureDatasetDefinition, DefinitionRelationshipType.DatasetInFeatureDataset);
- FeatureClassDefinition addressPointInAddressDataset =
- datasetsInAddressDataset.First(
- defn => defn.GetName().Equals("LocalGovernment.GDB.AddressPoint")) as FeatureClassDefinition;
- RelationshipClassDefinition addressPointHasSiteAddressInAddressDataset = datasetsInAddressDataset.First(
- defn => defn.GetName().Equals("LocalGovernment.GDB.AddressPointHasSiteAddresses")) as RelationshipClassDefinition;
- }
- });
- }
复制代码 4 从层获取表界说
- // GetDefinitionFromLayer - 这段代码即使在图层连接了另一个表的情况下也能正常工作
- private TableDefinition GetDefinitionFromLayer(FeatureLayer featureLayer)
- {
- // 从图层获取要素类
- FeatureClass featureClass = featureLayer.GetFeatureClass();
- // 确定要素类是否连接了另一个表
- if (featureClass.IsJoinedTable())
- {
- // 从要素类获取连接
- Join join = featureClass.GetJoin();
- // 从连接中获取源表
- Table originTable = join.GetOriginTable();
- // 从连接的源表返回要素类定义
- return originTable.GetDefinition();
- }
- else
- {
- return featureClass.GetDefinition();
- }
- }
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |