zlib Home Site

wget https://codeload.github.com/madler/zlib/zip/refs/tags/v1.2.9
#下载后文件名称不对,对的话可以不改
mv v1.2.9 v1.2.9.zip
unzip v1.2.9.zip
cd zlib-1.2.9
./configure --prefix=/usr/local/zlib-1.2.9
make && make install

#先备份,然后把这里都删了,因为不删后面还是用1.2.11的包,然而apt卸载不掉
cp /lib/aarch64-linux-gnu/libz.so.1.2.11 /opt
rm -rf /lib/aarch64-linux-gnu/libz*
ln -s -f /usr/local/zlib-1.2.9/lib/libz.so.1.2.9 /lib/aarch64-linux-gnu/libz.so.1

libtiff

Index of /libtiff/ (osgeo.org)

undefined reference to `TIFFReadDirectory@LIBTIFF_4.0‘ 

 要自己编译,不然gdal会报TIFFReadDirectory@LIBTIFF_4.0

apt remove libtiff5
#可以先尝试编译下,使用build是迫不得已,提示选择平台
wget http://download.osgeo.org/libtiff/tiff-4.0.9.zip
./configure --prefix=/usr/local/tiff-4.0.9 \
--build=aarch64-unknown-linux-gnu
make && make install

 

环境变量 

/etc/profile
#tiff
export TIFF_HOME=/usr/local/tiff-4.0.9
export TIFF_CFLAGS=$TIFF_HOME/include
export TIFF_LIBS=$TIFF_HOME/lib/pkgconfig
export PKG_CONFIG_PATH=$TIFF_LIBS:$PKG_CONFIG_PATH

/etc/ld.so.conf
/usr/local/tiff-4.0.9/lib

apt install libcurl4 libcurl4-openssl-dev curl 

wget https://curl.se/download/archeology/curl-7.29.0.tar.gz
./configure --prefix=/usr/local/curl-7.29.0 
#--with-zlib=/usr/local/zlib-1.2.9
make && make install

proj-9.2.1

wget https://codeload.github.com/OSGeo/PROJ/zip/refs/tags/9.2.1
cmake .. -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local/proj-9.2.1 \
-DSQLITE3_INCLUDE_DIR=/usr/local/sqlite3400000/include \
-DSQLITE3_LIBRARY=/usr/local/sqlite3400000/lib/libsqlite3.so \
-DTIFF_INCLUDE_DIR=/usr/local/tiff-4.0.9/include \
-DTIFF_LIBRARY=/usr/local/tiff-4.0.9/lib/libtiff.so \
-DBUILD_TESTING=OFF

编译前环境

#cmake
export CMAKE_HOME=/usr/local/cmake-3.21.1
export PATH=$CMAKE_HOME/bin:$PATH
#sqlite
export SQLITE_HOME=/usr/local/sqlite3400000
export PATH=$SQLITE_HOME/bin:$PATH
export PKG_CONFIG_PATH=$SQLITE_HOME/lib/pkgconfig:$PKG_CONFIG_PATH
#tiff
export TIFF_HOME=/usr/local/tiff-4.0.9
export TIFF_CFLAGS=$TIFF_HOME/include
export TIFF_LIBS=$TIFF_HOME/lib/pkgconfig
export PKG_CONFIG_PATH=$TIFF_LIBS:$PKG_CONFIG_PATH
#curl
#export CURL_HOME=/usr/local/curl-7.29.0
#export CURL_CFLAGS=$TIFF_HOME/include
#export CURL_LIBS=$TIFF_HOME/lib/pkgconfig
#export PKG_CONFIG_PATH=$CURL_LIBS:$PKG_CONFIG_PATH
#proj
export PROJ_HOME=/usr/local/proj-9.2.1
export PKG_CONFIG_PATH=$PROJ_HOME/lib/pkgconfig:$PKG_CONFIG_PATH
/usr/local/tiff-4.0.9/lib
/usr/local/sqlite3400000/lib
/usr/local/freexl-2.0.0/lib
/usr/local/proj-9.2.1/lib

gdal-3.6.2

#如果有highgo库,把libz依赖移走,会和gdal的libz冲突
mv /opt/highgo/hgdb-see-4.5.8/lib/libz.so.1 /opt/

cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/gdal-3.6.2  \
-DBUILD_TESTING=OFF \
-DTIFF_INCLUDE_DIR=/usr/local/tiff-4.0.9/include \
-DTIFF_LIBRARY=/usr/local/tiff-4.0.9/lib/libtiff.so \
-DSQLite3_INCLUDE_DIR=/usr/local/sqlite3400000/include \
-DSQLite3_LIBRARY=/usr/local/sqlite3400000/lib/libsqlite3.so \

#支持xls文件格式
-DFREEXL_INCLUDE_DIR=/usr/local/freexl-2.0.0/include \
-DFREEXL_LIBRARY=/usr/local/freexl-2.0.0/lib/libfreexl.so 

#支持pg,可选项
-DOGR_ENABLE_DRIVER_PG=ON \
-DPostgreSQL_INCLUDE_DIR=/opt/highgo/hgdb-see-4.5.8/include \
-DPostgreSQL_LIBRARY=/opt/highgo/hgdb-see-4.5.8/lib/libpq.so 

#如果上面不装zlib,这里不需要
-DZLIB_INCLUDE_DIR=/usr/local/zlib-1.2.9/include 
-DZLIB_LIBRARY=/usr/local/zlib-1.2.9/lib/libz.so.1.2.9

PROJ is detected in priority through CMake config files, in which case PROJ_INCLUDE_DIR and PROJ_LIBRARY_RELEASE will be ignored.

官方回复:通过 CMake 配置文件优先检测 PROJ,在这种情况下 PROJ_INCLUDE_DIR 和 PROJ_LIBRARY_RELEASE 将被忽略。 

配置环境

vi /etc/profile
#gdal
export GDAL_HOME=/usr/local/gdal-3.6.2
export PATH=$GDAL_HOME/bin:$PATH
export PKG_CONFIG_PATH=$GDAL_HOME/lib64/pkgconfig:$PKG_CONFIG_PATH
source /etc/profile
vi /etc/ld.so.conf
...
/usr/local/gdal-3.6.2/lib
/opt/highgo/hgdb-see-4.5.8/lib  #配上libpq

ldconfig -v

 验证 GDAL

#支持格式
ogr2ogr --formats

#导入shp
ogr2ogr -f "PostgreSQL" PG:"host='127.0.0.1' dbname='highgo' user='sysdba' password='Test@123' port=5866" /opt/110m_physical/ne_110m_ocean.shp

#导入xls
ogr2ogr -f "PostgreSQL" PG:"host='127.0.0.1' dbname='highgo' user='sysdba' password='Test@123' port=5866" /opt/dltbxz_tqmj.xlsx
11-20 00:44