ArcGIS Pro SDK (六)CoreHost

核心主机

环境: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);
    }
}
相关推荐
AAA大运重卡何师傅(专跑国道)8 小时前
【无标题】
开发语言·c#
xiaoshuaishuai817 小时前
C# AvaloniaUI ProgressBar用法
开发语言·c#
wearegogog12320 小时前
基于C#的电机监控上位机(串口通信+实时波形)
开发语言·c#
△曉風殘月〆20 小时前
C#如何Hook托管函数
c#·hook
雪豹阿伟21 小时前
18.C# —— 三层结构 + 接口架构实战(UI+Model+DAL+IDAL)
c#·上位机
雪豹阿伟21 小时前
17.C# —— 事件
c#·上位机
weixin_4280053021 小时前
C#调用 AI学习从0开始-第2阶段(Function Calling+工具调用智能体)-第9天实战
人工智能·学习·ai·c#·functioncalling
FuckPatience1 天前
C# 继承中的使用new的陷阱,和abstract /virtual 的不同
开发语言·c#
z落落1 天前
C# 索引器 this[]
开发语言·c#
csdn_aspnet1 天前
C# List 移除某个属性值中最大的值
开发语言·c#·list