PostGIS
2. 安装
根据开发环境,用户可从 PostGIS安装 页面选择适合自己的方式进行安装PostGIS安装。
2.1. 源码安装
除PostGIS社区提供的安装方式以外,IvorySQL社区也提供了源码安装方式,源码安装环境为 CentOS Stream 9(x86_64)。
请确保环境中已安装了IvorySQL3.0及以上版本 |
-
安装依赖
dnf install -y gcc gcc-c++ libtiff libtiff-devel.x86_64 libcurl-devel.x86_64 libtool libxml2-devel redhat-rpm-config clang llvm geos311 automake protobuf-c-devel
-
安装SQLITE
$ wget https://www.sqlite.org/2022/sqlite-autoconf-3400000.tar.gz
$ tar -xvf sqlite-autoconf-3400000.tar.gz
$ cd sqlite-autoconf-3400000
$ sed -n '1i\#define SQLITE_ENABLE_COLUMN_METADATA 1' sqlite3.c
$ ./configure --prefix=/usr/local/sqlite
$ make && make install
$ rm usr/bin/sqlite3 && ln -s /usr/local/sqlite/bin/sqlite3 /usr/bin/sqlite3
$ sqlite3 -version
$ export PKG_CONFIG_PATH=/usr/local/sqlite/lib/pkgconfig:$PKG_CONFIG_PATH
-
安装PROJ
$ wget https://download.osgeo.org/proj/proj-8.2.1.tar.gz
$ tar -xvf proj-8.2.1.tar.gz
$ cd proj-8.2.1
$ ./configure --prefix=/usr/local/proj-8.2.1
$ make && make install
-
安装 GDAL
$ wget https://github.com/OSGeo/gdal/releases/download/v3.4.3/gdal-3.4.3.tar.gz
$ tar -xvf gdal-3.4.3.tar.gz
$ cd gdal-3.4.3
$ sh autogen.sh
$ ./configure --prefix=/usr/local/gdal-3.4.3 --with-proj=/usr/local/proj-8.2.1
$ make && make install
-
安装 GEOS
$ wget https://download.osgeo.org/geos/geos-3.9.2.tar.bz2
$ tar -xvf geos-3.9.2.tar.bz2
$ cd geos-3.9.2
$ ./configure --prefix=/usr/local/geos-3.9.2
$ make && make install
-
安装 Protobuf
$ wget https://plug-neomirror.rcac.purdue.edu/adelie/source/archive/protobuf-3.20.1/protobuf-3.20.1.tar.gz
$ tar -xvf protobuf-3.20.1.tar.gz
$ cd protobuf-3.20.1
$ sh autogen.sh
$ ./configure --prefix=/usr/local/protobuf-3.20.1
$ make && make install
$ export PROTOBUF_HOME=/usr/local/protobuf-3.20.1
$ export PATH=$PROTOBUF_HOME/bin:$PATH
$ export PKG_CONFIG_PATH=$PROTOBUF_HOME/lib/pkgconfig:$PKG_CONFIG_PATH
-
安装 Protobuf-c
$ wget --no-check-certificate https://sources.buildroot.net/protobuf-c/protobuf-c-1.4.1.tar.gz
$ tar -xvf protobuf-c-1.4.1.tar.gz
$ cd protobuf-c-1.4.1
$ ./configure --prefix=/usr/local/protobuf-c-1.4.1
$ make && make install
$ export PROTOBUFC_HOME=/usr/local/protobuf-c-1.4.1
$ export PATH=$PROTOBUF_HOME/bin:$PROTOBUFC_HOME/bin:$PATH
$ export PKG_CONFIG_PATH=$PROTOBUFC_HOME/lib:$PKG_CONFIG_PATH
-
安装 PostGIS
$ wget https://download.osgeo.org/postgis/source/postgis-3.4.0.tar.gz
$ tar -xvf postgis-3.4.0.tar.gz
$ cd postgis-3.4.0
$ sh autogen.sh
$ ./configure --with-geosconfig=/usr/local/geos-3.9.2/bin/geos-config --with-projdir=/usr/local/proj-8.2.1 --with-gdalconfig=/usr/local/gdal-3.4.3/bin/gdal-config --with-protobufdir=/usr/local/protobuf-c-1.4.1 --with-pgconfig=/usr/local/ivorysql/ivorysql-3/bin/pg_config
$ make && make install
如出现PGXS报错, 请根据环境中IvorySQL安装路径, 修改—with-pgconfig的参数值。 |
3. 创建Extension并确认PostGIS版本
psql 连接到数据库,执行如下命令:
ivorysql=# CREATE extension postgis;
CREATE EXTENSION
ivorysql=# SELECT * FROM pg_available_extensions WHERE name = 'postgis';
name | default_version | installed_version | comment
---------+-----------------+-------------------+------------------------------------------------------------
postgis | 3.4.0 | 3.4.0 | PostGIS geometry and geography spatial types and functions
(1 row)
4. 使用
关于PostGIS的使用,请参阅 PostGIS3.4官方文档