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);
    }
}
相关推荐
吴可可1235 小时前
C#实现CAD框选闭合图元外偏移1毫米
c#
꒰ঌ 安卓开发໒꒱5 小时前
.NET CAP入门到入土
后端·c#·.net
逝水无殇9 小时前
C# 枚举(Enum)详解
开发语言·后端·c#
Java面试题总结10 小时前
C# 源生成器使用方法
windows·ui·c#
影寂ldy11 小时前
C# WinForms 窗体继承
开发语言·c#
苍狼唤1 天前
WinForm练习知识补充(多线程)
c#
4154111 天前
GeoTools 实战(二):空间数据格式转换全解析——Shp ↔ GeoJSON ↔ WKT(GeoTools 29.3 + JTS 1.19.0 实战版)
java·gis·geotools·geojson·shp·wkt
逝水无殇1 天前
C# 字符串(String)详解
开发语言·后端·c#
小巧的砖头1 天前
C#会重蹈覆辙吗?系列之2:反射及元数据的性能问题
开发语言·前端·c#
医疗信息化王工1 天前
从零到一:基于 GGUF 格式部署 Unlimited-OCR 搭建企业级证件识别服务
图像处理·c#·ocr