c# 使用GDAL处理大图
注意問題:
1.GDAL 使用官網(wǎng)生成好的dll,必須把Bin目錄下的dll一并加到執(zhí)行目錄下去,否則會(huì)出錯(cuò)。
?2. 用環(huán)境變量設(shè)置引用路徑可以避免一大堆dll放一起。代碼如下:
/// <summary>/// Function to determine which platform we're on/// </summary>private static string GetPlatform(){return IntPtr.Size == 4 ? "x86" : "x64";}/// <summary>/// Construction of Gdal/Ogr/// </summary>public static void Gdal_Configuration(){var executingAssemblyFile = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath;var executingDirectory = Path.GetDirectoryName(executingAssemblyFile);if (string.IsNullOrEmpty(executingDirectory))throw new InvalidOperationException("cannot get executing directory");var gdalPath = Path.Combine(executingDirectory, "gdal");var nativePath = Path.Combine(gdalPath, GetPlatform());// Prepend native path to environment path, to ensure the// right libs are being used.var path = Environment.GetEnvironmentVariable("PATH");path = nativePath + ";" ;Environment.SetEnvironmentVariable("PATH", path);Gdal.AllRegister();}?
3.最好使用自己手動(dòng)編譯的dll,會(huì)少很多沒使用到的dll,只用9個(gè)dll。
4.用GDAL的用戶控件,第二次拖動(dòng)控件進(jìn)窗體后會(huì)造成“未能加載工具箱項(xiàng),將從列表中移除”的問題,建議代碼手動(dòng)添加吧,是非托管dll的問題。
編譯步驟如下:
首先,下載GDAL源碼,官網(wǎng)下即可。
打開D:\gdal\nmake.opt
修改54行: GDAL_HOME = "D:\GDAL"。(編譯生成文件的保存路徑)
?????? 83行: SWIG = D:\swigwin-2.0.4\swig.exe(必須是swigwin.exe的完整路徑)。
????? 153行: "#WIN64=YES",去掉#。注意保存。
????? 675行:"SYM_PREFIX=_",去掉最后面的下劃線。
?
打開D:\gdal\makefile.vc,修改23~26行,將“_”改為$(SYM_PREFIX)。如圖:
?
打開D:\1.10.1\swig\csharp\AssemblyInfo.cs文件,將94行代碼注釋掉,解決安全透明代碼無法調(diào)用的問題。
?
打開 D:\1.10.1\swig\csharp\gdal\GdalPINVOKE.cs
?????????D:\1.10.1\swig\csharp\ogr\OgrPINVOKE.cs
???????? D:\1.10.1\swig\csharp\osr\OsrPINVOKE.cs?
???????????? 修改188~193行:將重復(fù)的代碼注釋掉,解決接口重定義的問題。
?
打開D:\1.10.1\swig\csharp\gdal\Band.cs|Dataset.cs|Driver.cs,修改第17行,解決接口成員名錯(cuò)誤問題。
?public Band(IntPtr cPtr, bool cMemoryOwn, object parent) : base(GdalPINVOKE.Band_SWIGUpcast(cPtr), cMemoryOwn, parent)
?public Dataset(IntPtr cPtr, bool cMemoryOwn, object parent) : base(GdalPINVOKE.Dataset_SWIGUpcast(cPtr), cMemoryOwn, parent)
?public Driver(IntPtr cPtr, bool cMemoryOwn, object parent) : base(GdalPINVOKE.Driver_SWIGUpcast(cPtr), cMemoryOwn, parent) {
?
3、編譯
開始—所有程序—Microsoft Visual Studio 2010—Visual Studio Tools—Visual Studio x64兼容工具命令提示(2010)
打開命令行工具,cd d:\gdal-1.10.1
然后執(zhí)行 nmake /f makefile.vc
??????????????? nmake /f makefile.vc install
??????????????? nmake /f makefile.vc devinstall
注:編譯可能要費(fèi)一些時(shí)間,不要著急。
以上是完成了C++的編譯,要再進(jìn)入csharp編譯。
執(zhí)行???????? cd swig\csharp
????????????????nmake /f makefile.vc
??????????? (運(yùn)行這一步有問題的話,加以下兩句:namke /f makefile.vc clear 、nmake /f makefile.vc interface)
??????????????? nmake /f makefile.vc install
正常情況下可以編譯成功。
命令參數(shù)說明:
使用命令:nmake -f makefile.vc MSVC_VER=1600 DEBUG=1 ANALYZE=1 WITH_PDB=1 可以設(shè)置使用的c++版本
MSVC_VER:VC++的版本,下面是對(duì)應(yīng)關(guān)系
1900 = 14.0(2015)
1800 = 12.0(2013)
1700 = 11.0(2012)
1600 = 10.0(2010)
1500 = 9.0 (2008)
1400 = 8.0 (2005) - specific compilation flags, different from older VC++
1310 = 7.1 (2003)
1300 = 7.0 (2002)
1200 = 6.0
DEBUG:bebug版本標(biāo)識(shí),不使用此參數(shù),默認(rèn)為Release
ANALYZE=1:對(duì)GDAL代碼進(jìn)行分析,這個(gè)一般不用
WITH_PDB=1:標(biāo)識(shí)生成調(diào)試信息
總結(jié)
以上是生活随笔為你收集整理的c# 使用GDAL处理大图的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NTP (Network Time Pr
- 下一篇: zip-gzip-bzip2_压缩文件