GDAL installation and configuration nanny-level tutorial (WIN10 VS2015 C#)

Tucao about our school, I feel that the teachers always think that we can be self-taught. I didn't mention GDAL (could it be that the teacher mentioned it, but I didn't listen carefully in class???), I didn't find this library until I encountered a bottleneck in my homework and looked for information. After collecting a lot of information, I finally installed and configured it for a long time. All right. . .
refer to:
https://blog.csdn.net/u011574296/article/details/76565703
https://blog.csdn.net/u012505618/article/details/52724060
https://blog.csdn.net/zhangying_496/article/details/51258862
------------------------------------------------------------------------------------------------------------------------------

My computer: WIN10, VS2015, 64 bit

Step 1: Download GDAL
Official website: http://trac.osgeo.org/gdal/wiki/DownloadSource
I downloaded 2.2.3

After decompression, put it in a GDAL folder I created in the D drive, the path is D:\GDAL


Step 2: Download swigwin (note that it is swigwin, don't download it wrong)

This is used for C# compilation of gdal. If you do not use C#, this step can be ignored


Download the official website: https://sourceforge.net/projects/swig/files/swigwin/

I downloaded swigwin3.0.12 and put it in the path D:\GDAL

Step 3: Make Various Modifications
Open the gdal-2.2.3 folder, find nmake.opt, open it with a text editor, I use notepad++
(1) Find GDAL_HOME and modify the path

Oh I see:

Change it to this: (a new gdal2.23 folder is created in the GDAL folder, and the compiled files are here)

(2) Find the red box below

Change it to:


Step 3: Compile
(1) Enter the vs2015 developer command prompt


(2) Enter cmd, enter cd D:\GDAL\gdal-2.2.3, and enter the path of the previously downloaded gdal


Then enter nmake /f makefile.vc


After this step is successful, enter nmake /f makefile.vc install


After this step is successful, enter: nmake /f makefile.vc devinstall


After the above three commands are successfully executed, the following folders will appear in the D:\GDAL\gdal2.23 folder:


Up to now, the compilation has actually been completed, but I want to use C#, so I need to compile the following

Step 4: Compile C#

(1) Open D:\GDAL\gdal-2.2.3, find nmake.opt (the file that was compiled before), and find SWIG=swig.exe


Change it to the following (the storage path of the previously downloaded swigwin file)


(2) Open D:\GDAL\gdal-2.2.3\swig\csharp\AssemblyInfo.cs file
Find line 94 and comment out this line


(3)打开D:\GDAL\gdal-2.2.3\swig\csharp\gdal\GdalPINVOKE.cs
               D:\GDAL\gdal-2.2.3\swig\csharp\ogr\OgrPINVOKE.cs
               D:\GDAL\gdal-2.2.3\swig\csharp\osr\OsrPINVOKE.cs

  Modify lines 188~193: Comment out the repeated code to solve the problem of interface redefinition.
(The following is one of them, all three are modified like this)

(4)D:\GDAL\gdal-2.2.3\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) 

(5)上面的修改完成后,回到cmd里,进入D:\GDAL\gdal-2.2.3\swig\csharp之下

依次执行命令:nmake /f makefile.vc
                       nmake /f makefile.vc install


等编译成功后,D:\GDAL\gdal2.23 文件夹里会出现csharp文件夹,csharp文件夹里有8个.dll文件。

至此,gdal的C#就编译成功了。
------------------------------------------------------------------------------------------------------------------------------
下面是在VS2015里进行配置。
1、新建一个窗体文件
2、在引用里添加D:\GDAL\gdal2.23\csharp里的四个 _csharp.dll 类型的引用


3、将D:\GDAL\gdal2.23\csharp里除了_csharp.dll类型的其余的.dll文件,加上D:\GDAL\gdal2.23\bin里的 gdal202.dll 复制到刚刚建立的窗体文件的bin/Debug文件夹里去。(一层层文件夹找就行)

4、代码示例
 
 

就运行成功了,撒花完结

CSDN的用户体验真的是极差极差极差!!!代码经常串行,动不动就崩!!!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326308231&siteId=291194637