[关闭]
@ecnu-cyx 2016-12-05T11:44:13.000000Z 字数 2725 阅读 1920

Install GDAL on Windows

Software-Installation


昨晚跟水妹在一起聊天,聊到数据处理,刚好自己最近也在处理监督分类得到的矢量数据,这类数据vertex较多,那么加载显示的时候会非常的耗内存并且很慢,所以想到抽稀点来进行vertex的减少,然后进行平滑,使用ArcMap操作后很快能够进行抽稀(Generalize)和平滑(Smooth),但是保存要素更改会出现卡顿,所以在想有没有比较好的方法进行类似的处理。然后就聊到了GDAL,对于地理空间数据处理有比较好的可扩展性,相比于ArcPy。
GDAL是由C++完成的编写,并且是开源的,所以其它平台或语言需要调用,则需要对其进行编译,然后才能进行调用,如果下载原始代码,则需要先对其进行编译。此文仅是介绍从网站下载现有的编译好的GDAL安装程序gdal-201-1700-core.msi和GDAL-2.1.0.win32-py2.7 和安装步骤。


Tutor SourceInstall GDAL on Windows

Contents:

  • Install Python
  • Install the GDAL binaries published by Tamas Szekeres
  • Append your environment Path variable
  • Add the GDAL_DATA environment variable
  • Perform a quick test to make sure everything worked.

1. 安装Python

先要安装好Python,并确定要安装的版本和位数(Version 2.7 for Win32),这个可以在Python官网进行下载安装,当然安装ArcGIS过程中也会提示安装的。

2. 安装GDAL二进制包

进入GDAL Homepage,导航到【User Oriented Documentation】,点击【Downloads】进入GDAL二进制包下载页,这里包含很多平台的安装包链接,此处我们导航到【Windows】,然后点击GISInternals,该网站包含很多由VC2005/VC2008/VC2010/VC2012/VC2013编译的Win32和Win64的GDAL二进制包,点击Stable Release,里面包含MapServer和GDAL更新的二进制包,然后选择自己需要的版本和位数的二进制包,此文选择的版本GDAL 2.1.0 and MapServer 7.0.1,然后编译器选择的是MSVC2012的,安装程序版本选择的是Win32的,因为查看安装的Python是Win32的,注:不是系统的位数。
进入到最终下载页面,会列出一系列的Available downloads,首先找到与Python版本一致的GDAL Python安装包,看到后面的描述是“Installer for the GDAL python bindings(requires to install ther GDAL core)”,所以需要找到GDAL core,对应的描述是“Generic installer for the GDAL core components”。

1) 首先安装GDAL core,一路默认点击下去。(此处选择的是Win32的,所以默认安装到的是C盘的Program Files(x86) 下面,文件夹为GDAL;若为Win64的,则默认安装到的是C盘的Program Files下。)
2) 再安装GDAL Python安装包,也是默认点击下去,这个会生成到Python目录的Lib->site-packages下,也有可能会生成到msi的同级目录,这就需要手动将得到的文件夹拷贝到Python对应的目录下。

3. 设置环境变量Path

进入系统的环境变量设置窗口,找到Path变量,对其进行编辑,在末尾追加一个GDAL core的安装路径“C:\Program Files (x86)\GDAL”。
warning: Be sure to confirm your GDAL installation directory. I installed GDAL on Windows7, but if you run a newer version of Windows, your installation path may be different from mine.

4. 添加GDAL_DATA环境

同样在环境变量窗口,在系统变量窗口中点击【新建】,新建一个系统环境变量,系统变量名为GDAL_DATA,在系统变量值文本框中添加“C:\Program Files (x86)\GDAL\gdal-data”。
作用: helps the various GDAL utilities find the gdal-data folder. Without access to the files in the gdal-data folder, GDAL may have trouble recognizing some projections and coordinate systems, among other things.

Update: 添加环境变量GDAL_DRIVER_PATH与添加GDAL_DATA是一样的。
作用: For those who already have GDAL installed along with the Python bindings–If you’re trying to write custom scripts and you’re getting errors like “ERROR 4: ..does not exist ..is not recognized as a supported dataset name”, you may simply need to add this additional environment variable. This is especially true if you followed my tutorial for setting up GDAL on your system in the first place! In case of the latter, my apologies.

5. 测试验证

到了最后一步就是测试是否安装成功,使用的是ogr2ogr命令,进入cmd黑窗,输入ogr2ogr回车,如果出现下图内容,则说明安装成功。
测试安装GDAL成功界面

进入Python命令交互窗口,输入import gdal,如果不报错则安装成功。
例如出现:“ImportError: DLL load failed: %1 不是有效的 Win32 应用程序”,则说明安装的GDAL python版本不是Win32的,而是Win64的,则需要重新下载安装Win32的GDAL python bindings。

致谢: 在此非常感谢原创作者Cheers, Elijah!
附: 学习教程

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注