ArcGIS Pro二次开发获得图层的数据源
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using ArcGIS.Core.CIM; using ArcGIS.Core.Data; using ArcGIS.Core.Geometry; using ArcGIS.Desktop.Catalog; using ArcGIS.Desktop.Core; using ArcGIS.Desktop.Editing; using ArcGIS.Desktop.Extensions; using ArcGIS.Desktop.Framework; using ArcGIS.Desktop.Framework.Contracts; using ArcGIS.Desktop.Framework.Dialogs; using ArcGIS.Desktop.Framework.Threading.Tasks; using ArcGIS.Desktop.Mapping; namespace ProAppModule1 { internal class Button2 : Button { public static async Task<string> GetDataSource(BasicFeatureLayer theLayer) { try { return await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => { var inTable = theLayer.Name; var table = theLayer.GetTable(); var dataStore = table.GetDatastore(); var workspaceNameDef = dataStore.GetConnectionString(); var workspaceName = workspaceNameDef.Split('=')[1]; var fullSpec = System.IO.Path.Combine(workspaceName, inTable); return fullSpec; }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return string.Empty; } } protected override async void OnClick() { var mv = MapView.Active; var lyrs = mv.Map.Layers; foreach (var lyr in lyrs) { if (lyr is FeatureLayer) { var datasource = await GetDataSource(lyr as BasicFeatureLayer); MessageBox.Show(datasource); } } } } }