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);
    }
}
相关推荐
江山如画,佳人北望9 小时前
C#程序入门
开发语言·windows·c#
与火星的孩子对话9 小时前
Unity进阶课程【六】Android、ios、Pad 终端设备打包局域网IP调试、USB调试、性能检测、控制台打印日志等、C#
android·unity·ios·c#·ip
future141210 小时前
C#每日学习日记
java·学习·c#
军训猫猫头13 小时前
1.如何对多个控件进行高效的绑定 C#例子 WPF例子
开发语言·算法·c#·.net
葬歌倾城1 天前
JSON的缩进格式方式和紧凑格式方式
c#·json
Eiceblue1 天前
使用 C# 发送电子邮件(支持普通文本、HTML 和附件)
开发语言·c#·html·visual studio
小小小小王王王1 天前
hello判断
开发语言·c#
金增辉1 天前
基于C#的OPCServer应用开发,引用WtOPCSvr.dll
c#
Modify_QmQ1 天前
leaflet【十一】地图瓦片路径可视化
gis·vue3·leaflet·leafletmapblock
future14121 天前
C#学习日记
开发语言·学习·c#