GDAL 编译为 .NET (C#) 使用

GDAL compilation to .NET (C#) use

我想编译 GDAL 库以在 C# 程序中使用。我使用 Microsoft Visual Studio 2013。之前,我编译了 GDAL C++,结果我有 dll 和库(没问题)。接下来我尝试使用 instruction 进行编译,因为我想在 C# 程序中使用 GDAL。但是,我并没有低估我在这一步中应该做什么。

Creating the SWIG interface code For creating the interface execute the following command.

nmake /f makefile.vc interface

Previous Step make's error when regenerates the *PINVOKE.cs files ,so skip to next step ,it will work

我试着跳过这一步,但总是有同样的异常(如下所示)。结果我没有可在 C# 中使用的 dll...

    ogr\OsrPINVOKE.cs(192,10): error CS0111: Type 'OSGeo.OGR.OsrPINVOKE' already
        defines a member called 'OsrPINVOKE' with the same parameter types
ogr\OsrPINVOKE.cs(188,10): (Location of symbol related to previous error)
NMAKE : fatal error U1077: '"C:\Program Files (x86)\MSBuild.0\bin\csc.EXE"' :
 return code '0x1'
Stop.

我应该将 GDAL 编译成 C# 什么?也许你有什么想法。

在 GdalPINVOKE.cs、OgrPINVOKE.cs、OsrPINVOKE.cs 中重复定义 class 构造函数。

把重复的行注释掉就行了。

您可以在 http://www.gisinternals.com/

找到已编译的二进制文件

只需添加对 \bin\gdal\csharp*_csharp.dll 的引用,将 *_wrap.dll 添加到您的输出位置和其他 gdal dll。

只需使用 nuget 包,如果你将 GDAL Native 安装到你的项目中,你将获得你需要的所有 dll 和一些配置 .cs,这样你就可以调用库而无需将它们导入你的 .cs