Ubuntu16.04 builds the WebGIS framework of geodjango+postgresql+postgis (1) Install third-party spatial library

  postgis is a spatial extension object of postgresql, which requires the support of some third-party libraries. Including GEOSPROJ.4  and  GDAL . We first install these space libraries.

Execute in the ubuntu system terminal: (pre-install some dependent libraries)

$ sudo apt-get install binutils libproj-dev gdal-bin

Then install GEOSPROJ.4  and  GDAL three space libraries from source code .

    1) GEOS: GEOS is a practical library for topological relationship operations of set shapes (it may not be accurate to say so), simply put, it is to judge the relationship between two geometric shapes and operate on two geometric shapes to form a new geometry library of shapes

$ wget http://download.osgeo.org/geos/geos-3.5.1.tar.bz2
$ tar xjf geos-3.5.1.tar.bz2 After 
the download is complete:
configure:
$ cd geos-3.5.1
$ ./configure
$ make
$ sudo make install
$ cd .. 
(Note: The version given by the official website is 3.4.2, but since the postgresql I use is 9.6, GEOS+ is required for compilation, so I changed it to version 3.5.1, and I have been tossing around here for a long time, be sure to pay attention Whether the version matches your own installed postgresql)
2) proj.4: The most famous map projection library of open source GIS. The functions of Proj.4 mainly include the conversion of latitude and longitude coordinates and geographic coordinates, the conversion of coordinate systems, including datum transformation, etc.
Download the source code:
$ wget http://download.osgeo.org/proj/proj-4.9.1.tar.gz
$ wget http://download.osgeo.org/proj/proj-datumgrid-1.5.tar.gz
解压缩源代码压缩文件,并在nad子目录中提取基准移位文件。这些必须在配置之前完成
$ tar xzf proj-4.9.1.tar.gz
$ cd proj-4.9.1/nad
$ tar xzf ../../proj-datumgrid-1.5.tar.gz
$ cd ..

配置
$ ./configure
$ make
$ sudo make install
$ cd ..

3)GDAL:GDAL(Geospatial Data Abstraction Library)是一个在X/MIT许可协议下的开源栅格空间数据转换库。它利用抽象数据模型来表达所支持的各种文件格式。它还有一系列命令行工具来进行数据转换和处理。(百度百科定义)
下载源码:
$ wget http://download.osgeo.org/gdal/2.2.2/gdal-2.2.2.tar.gz
$ tar xzf gdal-2.2.2.tar.gz
$ cd gdal-2.2.2
(官网给的版本是1.11.2,我使用时出现错误(忘记啥错误了),我换成更新的版本,这次ok)
配置:
$ ./configure
$ make # 挺久的,可以看会动漫了
$ sudo make install
$ cd ..

安装完检查是否安装成功:
安装之后的文件在/user/local下面,其中bin下面放可执行的程序,includes存放源代码,lib下存放动态库(xx.sa)和静态库(xx.a)。

geos:在gdal目录下,执行./configure,如果出现GEOS support = yes,成功。proj属于动态加载,不会显示,只需将proj的动态库和gdal的动态库放在一起即可。
检验GDAL:在终端输入gdalinfo名利即可。

错误处理:(配置geodjango环境时,绝大多数错误是外部共享库不能被加载,因为操作系统不知道去哪里加载从源构建的库目录)
配置环境变量:将库路径user/local/bin加入到LD_LIBRARY_PATH
vim ~/bashrc
加入下面的一行:
export LD_LIBRARY_PATH=/usr/local/lib

设置系统库路径:
$ sudo echo /usr/local/lib >> /etc/ld.so.conf
$ sudo ldconfig

修改错误后,再次检查是否安装成功
ps:(一定要注意版本问题,我真的在版本上折腾了很久,如果还有无法解决的错误,建议查看官方文档))
希望对大家有帮助,我也是初学,不足之处,多多指正!



 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325023861&siteId=291194637