在C#中使用GDAL时发生异常 [英] Exception while using GDAL in C#

查看:636
本文介绍了在C#中使用GDAL时发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在应用程序中使用 gdal_csharp dll并读取geotiff文件。但它说:

I started to use gdal_csharp dll in my application and read a geotiff file. but it says:

The type initializer for 'OSGeo.GDAL.GdalPINVOKE' threw an exception.

这是我的代码

string fileName = @"/path to geotiff file";

OSGeo.GDAL.Dataset DS = 
    OSGeo.GDAL.Gdal.Open(fileName, OSGeo.GDAL.Access.GA_ReadOnly);

有人可以帮忙吗?

编辑:

我有这些dll

这是完整的错误消息:

它说无法加载 gdal_wrap 。但是,当我要将该dll添加到我的应用程序时,将显示以下消息:

It says that cannot load gdal_wrap. But when I'm going to add that dll to my application the below message is shown:

推荐答案

作为对此的更新,现在由GDAL维护在此处的nuget程序包中对其进行定期更新。您需要为项目安装 GDAL.Native和 GDAL软件包,才能使用GDAL库。通过nuget安装后,它们将自动创建一个 GdalConfiguration.cs,您可以调用该文件来初始化GDAL路径,然后再开始。唯一需要注意的是,将软件包设置为自动将其相应的GDAL库复制到输出构建目录。如果您需要部署应用程序,则需要付出一些额外的努力。

As an update to this there is now GDAL maintained by the SharpMap team as a nuget package here which is updated regularly. You'll need to install both the "GDAL.Native" and "GDAL" package for your project to use the GDAL library. Once installed via nuget, they'll automatically create a "GdalConfiguration.cs" that you call into to initialize the GDAL paths before starting. The only thing to note is the packages are setup to automatically copy their appropriate GDAL libraries to your output build directory. If you need to deploy the application you'll have to do a bit of extra effort.

这篇关于在C#中使用GDAL时发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆