删除旧版本
sudo apt remove libgdal*
sudo apt remove gdal*
sudo apt autoremove
下载proj和gdal
https://github.com/OSGeo/PROJ/releases
这里使用的是9.3.0版本:
https://github.com/OSGeo/gdal/releases
这里使用的是3.7.3版本:
编译
安装依赖包
sudo apt install libsqlite3-0 libtiff5 libtiff5-dev curl libcurl4 libcurl4-gnutls-dev
解压文件:
sudo tar xvf proj-9.3.0.tar.gz
sudo tar xvf gdal-3.7.3.tar.gz
编辑PROJ
cd proj-9.3.0
sudo mkdir build
cd build
sudo cmake ..
sudo cmake --build . --target install -- -j 20
编译GDAL
cd gdal-3.7.3
sudo mkdir build
cd build
sudo cmake ..
sudo cmake --build . --target install -- -j 20
后续
sudo ln -s /usr/local/lib/libgdal.so.33.3.7.3 /usr/lib/libgdal.so
sudo ln -s /usr/local/lib/libgdal.so.33 /usr/lib/libgdal.so.33
sudo ln -s /usr/local/lib/libproj.so.25 /usr/lib/libproj.so.25
python安装
pip install numpy
pip install gdal==3.7.3
测试
$ python3
Python 3.8.10 (default, Sep 28 2021, 16:10:42)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from osgeo import gdal
>>> from osgeo import ogr
>>> from osgeo import osr
>>> from osgeo import gdal_array
>>> from osgeo import gdalconst