c语言编译gdal,GDAL编译安装指南

1.需求

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

2.环境

CentOS 7 , GDAL 2.4.0 , hadoop 2.9.2

3.编译准备

3.1源代码下载

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

#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 -lhdfs,若编译成功,表示以上步骤正确,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

首先需要安装swig和ant

yum install -y swig

http://ant.apache.org/

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

7.测试gdal读取hdfs文件

将hadoop配置文件core_site.xml拷贝到本机HADOOP_HOME目录下

在控制台输入

gdalinfo /vsihdfs/hdfs://ip:port/tif/3857t.tif

若成功显示该tiff文件的信息,则说明GDAL+HDFS编译安装成功。

7.1.测试gdal通过webHDFS接口读取hdfs文件

在控制台输入

gdalinfo /vsiwebhdfs/http://ip:port/webhdfs/v1/tif/3857t.tif

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值