GDAL编译安装指南

1.需求

根据GDAL2.4.0的更新说明,从该版本开始GDAL支持对HDFS存储的影像数据的读取,但是目前发布的prebuilt版本均没有提供此功能,因此需要从源代码重新编译。

2.环境

CentOS 7 , GDAL 2.4.0 , hadoop 2.9.2

3.编译准备
3.1源代码下载

GDAL:https://github.com/OSGeo/gdal/releases
hadoop:https://hadoop.apache.org/releases.html

4.编译hadoop

下载hadoop源代码并解压缩后,在BUILDING.txt文件可看到hadoop的安装指南,其中编译需求摘录如下:

Requirements:

* Unix System
* JDK 1.7 or 1.8
* Maven 3.0 or later
* Findbugs 1.3.9 (if running findbugs)
* ProtocolBuffer 2.5.0
* CMake 2.6 or newer (if compiling native code), must be 3.0 or newer on Mac
* Zlib devel (if compiling native code)
* openssl devel (if compiling native hadoop-pipes and to get the best HDFS encryption performance)
* Linux FUSE (Filesystem in Userspace) version 2.6 or above (if compiling fuse_dfs)
* Internet connection for first build (to fetch all Maven and Hadoop dependencies)
* python (for releasedocs)
* Node.js / bower / Ember-cli (for YARN UI v2 building)

根据该说明下载相关软件并安装后,进入hadoop-2.9.2-src源代码目录,执行
mvn clean package -Pdist,native -DskipTests -Dtar -Dsnappy.lib=/usr/lib64 -Dbundle.snappy -Drequire.openssl进行编译和打包,打包好的文件位于hadoop-2.9.2-src/hadoop-dist目录下

5.配置libhdfs.so

libhdfs.so是hadoop提供的操作HDFS的C语言客户端,经过上一步的编译后,生成的libhdfs.so位于/hadoop-dist/target/hadoop-2.9.2/lib/native/,生成的hdfs.h头文件位于/hadoop-dist/target/hadoop-2.9.2/include/,然后将libhdfs.so拷贝到/usr/local/lib,将hdfs.h文件拷贝到/usr/local/include,编写测试代码testhdfs.c

#include <stdio.h>
#include "hdfs.h"

int main(int argc, char **argv)
{
    hdfsFS fs = hdfsConnect("10.46.120.32", 8010);
    if (!fs) {
        fprintf(stderr, "connect fail\n");
        return -1;
    }
    hdfsFile writeFile = hdfsOpenFile(fs, "/first.txt", O_WRONLY, 4096, 0, 0);
    if (!writeFile) {
        fprintf(stderr,"openfile fali\n");
        return -1;
    }
    hdfsWrite(fs, writeFile, "hello hdfs", 10);
    hdfsCloseFile(fs, writeFile);
    hdfsDisconnect(fs);
    return 0;
}

使用GCC编译gcc testhdfs.c,若编译成功,表示以上步骤正确,libhdfs.so配置正确。

6.编译gdal

进入gdal源代码路径下,输入

./configure --with-java=/home/jdk1.8.0_191 --with-hdfs=/usr/local/
make
make install

默认安装路径在/usr/local,在控制台输入gdalinfo --version看到版本信息即代表编译安装成功。

6.1.编译gdal的Java binding

进入/gdal/swig/java目录,在控制台输入make,即可在该目录下生成gdal.jar,libgdalalljni.so,libgdalalljni.la三个文件,最后将so文件和la文件拷贝到/usr/local/lib

7.测试gdal读取hdfs文件

在控制台输入
gdalinfo /vsiwebhdfs/http://192.168.1.1:14000/webhdfs/v1/tif/3857t.tif
若成功显示该tiff文件的信息,则说明GDAL编译安装成功。

猜你喜欢

转载自blog.csdn.net/weixin_33810302/article/details/87275204
今日推荐