Linux 学习笔记(十四)GDAL.pdf
文本预览下载声明
Linux 学习笔记(十四) 1
2013.5.11 2
一、 Linux中 GDAL安装、配置、编译与运用 3
#安装: 4
常用的配置方法有两种:package manager和 source。为了后期配置更合理,使用 source。 5
注意:在进行安装前,必须先安装 C和 C++编译器(gcc、g++)。 6
$sudo apt-get install gcc g++ 7
8
Package manager: 9
$sudo apt-get install gdal-bin 10
$sudo apt-get install python-gdal 11
12
Building from source: 13
Download source tarball gdal-1.9.1.tar.gz 14
$tar xvfz gdal-1.9.1.tar.gz 15
$cd ./gdal-1.9.1.tar.gz/ 16
$./configure [--prefix==INSTALL_DIRECTORY] 17
(安装前.bashrc中定义 INSTALL_DIRECTORY变量,export) 18
(prefix为指定安装路径,默认为/usr/local/) 19
$make 20
$make install 21
22
安装完成后,/usr/local/lib和/usr/local/include中将会有 GDAL的*.h和*.so文件。 23
#配置: 24
在.bashrc中,给 PATH变量添加 GDAL的引用路径: 25
export PATH=$PATH:/usr/local/bin #默认安装时,已将 gdal-bin加入/usr/local/bin 26
若更改了安装路径: 27
export PATH=INSTALL_DIRECTORY/gdal-1.9.1/bin:$PATH #添加 bin引用路径 28
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH #如果不设置,将出现下面错误: 29
(error while loading shared libraries: libgdal.so.1: cannot open shared object file: No such file or 30
directory) 31
32
33
#编译: 34
配置后: 35
$g++ gdal_linux.cpp –lgdal –o output #c++编译,引用 gdal库,输出 output 36
$./output #执行 37
38
未配置: 39
$g++ gdal_linux.cpp –I /usr/local/include/ -L /usr/local/lib/ -lgdal –o output 40
$LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH 41
$./output 42
43
#运用:使用安装时编译好的 gdal-bin 44
#raster info: 45
$gdalinfo *.tif #显示 raster文件属性 46
47
#vector info: 48
$ogrinfo –al vectorfile #显示 vector文件属性 49
50
51
52
#Resize an Image: 53
$gdal_translate -outsize newxsize newysize imageFile outputFile 54
$gdal_translate –outsize 15% 15% im.tif resized.tif #缩小为原来的 15% 55
$gdal_translate –outsize 1024 768 im.tif resized.tif #大小改为 1024X768 56
57
58
#Change Image Format: 59
$gdal_translate -of FORMAT imageFile outputFile 60
$gdal_translate –of PNG resized.tif converted.png #tif转为 png 61
62
63
#Add Overviews: 64
$gdaladdo -r M
显示全部