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);
    }
}
相关推荐
小码编匠6 小时前
WPF 中的高级交互通过右键拖动实现图像灵活缩放
后端·c#·.net
唐青枫13 小时前
C#.NET 定时任务与队列利器:Hangfire 完整教程
c#·.net
hez201019 小时前
Runtime Async - 步入高性能异步时代
c#·.net·.net core·clr
mudtools1 天前
.NET驾驭Word之力:玩转文本与格式
c#·.net
唐青枫2 天前
C#.NET 数据库开发提速秘籍:SqlSugar 实战详解
c#·.net
mudtools2 天前
.NET驾驭Word之力:理解Word对象模型核心 (Application, Document, Range)
c#·.net
大飞pkz2 天前
【设计模式】C#反射实现抽象工厂模式
设计模式·c#·抽象工厂模式·c#反射·c#反射实现抽象工厂模式
你是一个铁憨憨2 天前
ArcGIS定向影像(1)——非传统影像轻量级解决方案
arcgis·gis·影像·定向影像
QQ3596773452 天前
ArcGIS Pro实现基于 Excel 表格批量创建标准地理数据库(GDB)——高效数据库建库解决方案
数据库·arcgis·excel
唐青枫3 天前
从入门到进阶:C#.NET Stopwatch 计时与性能测量全攻略
c#·.net