核心主机
环境:Visual Studio 2022 + .NET6 + ArcGIS Pro SDK 3.0
1 初始化核心主机
csharp
using ArcGIS.Core.Data;
//必须引用ArcGIS.CoreHost.dll
using ArcGIS.Core.Hosting;
class Program {
//[STAThread] 必须出现在应用程序入口点上
[STAThread]
static void Main(string[] args)
{
//必须在构造任何 ArcGIS.Core 对象之前调用 Host.Initialize
try {
Host.Initialize();
}
catch (Exception e) {
//错误(缺少安装、没有许可证、64位不匹配等)
Console.WriteLine(string.Format("Initialization failed: {0}",e.Message));
return;
}
//执行到这,ArcGIS.Core已经初始化成功
Geodatabase gdb = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\Data\SDK\GDB\MySampleData.gdb")));
IReadOnlyList<TableDefinition> definitions = gdb.GetDefinitions<FeatureClassDefinition>();
foreach (var fdsDef in definitions) {
Console.WriteLine(TableString(fdsDef as TableDefinition));
}
Console.Read();
}
private static string TableString(TableDefinition table)
{
string alias = table.GetAliasName();
string name = table.GetName();
return string.Format("{0} ({1})", alias.Length > 0 ? alias : name, name);
}
}