c# 使用GDAL處理大圖

來源:互聯網
上載者:User

標籤:drive   invoke   oca   diff   native   turn   debug   stat   setenv   

注意問題:

1.GDAL 使用官網產生好的dll,必須把Bin目錄下的dll一併加到執行目錄下去,否則會出錯。

 2. 用環境變數設定引用路徑可以避免一大堆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.最好使用自己手動編譯的dll,會少很多沒使用到的dll,只用9個dll。

4.用GDAL的使用者控制項,第二次拖動控制項進表單後會造成“未能載入工具箱項,將從列表中移除”的問題,建議代碼手動添加吧,是非託管dll的問題。

編譯步驟如下:

首先,下載GDAL源碼,官網下即可。

開啟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行代碼注釋掉,解決安全透明代碼無法調用的問題。

 

開啟 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行:將重複的代碼注釋掉,解決介面重定義的問題。

 

開啟D:\1.10.1\swig\csharp\gdal\Band.cs|Dataset.cs|Driver.cs,修改第17行,解決介面成員名錯誤問題。

 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

然後執行 nmake /f makefile.vc

                nmake /f makefile.vc install

                nmake /f makefile.vc devinstall

註:編譯可能要費一些時間,不要著急。

以上是完成了C++的編譯,要再進入csharp編譯。

執行         cd swig\csharp

                nmake /f makefile.vc

            (運行這一步有問題的話,加以下兩句:namke /f makefile.vc clear 、nmake /f makefile.vc interface)

                nmake /f makefile.vc install

正常情況下可以編譯成功。


命令參數說明:

使用命令:nmake -f makefile.vc MSVC_VER=1600 DEBUG=1 ANALYZE=1 WITH_PDB=1 可以設定使用的c++版本
MSVC_VER:VC++的版本,下面是對應關係
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版本標識,不使用此參數,預設為Release
ANALYZE=1:對GDAL代碼進行分析,這個一般不用
WITH_PDB=1:標識產生調試資訊

c# 使用GDAL處理大圖

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.