地理空间分析
PostGIS 扩展了 PostgreSQL 的功能,增加了对地理空间数据的存储、索引和查询支持。Apache Cloudberry 支持 PostGIS 进行地理空间分析。
本文介绍了如何为你的 Apache Cloudberry 集群编译和构建 PostGIS。
要查看 Apache Cloudberry PostGIS 项目的仓库,请访问 cloudberry-contrib/postgis
。该仓库的 PostGIS 是专门为 Apache Cloudberry 打造的,本文档介绍的编译构建方法,是基于该仓库的代码。
为 Apache Cloudberry 编译 PostGIS
在为 Apache Cloudberry 安装 PostGIS 之前,请先安装所需的依赖项并编译若干组件。目前,仅支持在 CentOS 系统上进行编译构建,未来计划支持 Rocky Linux。
在开始编译之前,请确保 Apache Cloudberry 已正确安装。如果尚未安装,请参阅文档获取安装说明。
-
安装相关依赖。
yum install -y libtool proj-devel boost-devel gmp-devel mpfr-devel pcre-devel protobuf protobuf-c protobuf-devel protobuf-c-devel && \
yum install -y gcc make subversion gcc-c++ sqlite-devel libxml2-devel swig expat-devel libcurl-devel python36-devel json-c -
构建相关组件(GDAL、CGAL、SFCGAL 和 GEOS)。请确保你使用
root
用户进行构建。-
构建 GDAL。
GDAL 是一个用于栅格和矢量地理空间数据格式的转换库。按照以下命令进行安装:
wget https://download.osgeo.org/gdal/2.2.1/gdal-2.2.1.tar.gz --no-check-certificate
tar xf gdal-2.2.1.tar.gz
cd gdal-2.2.1/
./configure --prefix=/usr/local/gdal-2.2.1
make && make install -
构建 CGAL。
CGAL 提供了一个 C++ 库,它以一种易于访问的方式提供了高效且可靠的几何算法。按照以下命令进行安装:
wget https://github.com/CGAL/cgal/archive/releases/CGAL-4.13.tar.gz
tar xf CGAL-4.13.tar.gz
cd cgal-releases-CGAL-4.13/
mkdir build && cd build
cmake ..
make && make install -
构建 SFCGAL。
SFCGAL 是一个围绕 CGAL 的 C++ 封装库,支持 ISO 19107:2013 和 OGC Simple Features Access 1.2 规范,用于 3D 操作。按照命令进行安装:
wget https://github.com/Oslandia/SFCGAL/archive/v1.3.6.tar.gz
tar xf v1.3.6.tar.gz
cd SFCGAL-1.3.6/
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/sfcgal-1.3.6 ..
make && make install -
构建 GEOS。
GEOS 是一个 C/C++ 计算几何库,专注于地理信息系统 (GIS) 软件中使用的算法。按照以下命令进行安装:
wget https://download.osgeo.org/geos/geos-3.7.0.tar.bz2 --no-check-certificate
tar xf geos-3.7.0.tar.bz2
cd geos-3.7.0/
./configure --prefix=/usr/local/geos-3.7.0/
make && make install -
更新
/etc/ld.so.conf
。安装上述组件后,更新
/etc/ld.so.conf
文件,以配置动态加载器搜索组件的目录。cat << EOF >> /etc/ld.so.conf
/usr/lib/
/usr/lib64/
/usr/local/sfcgal-1.3.6/lib64/
/usr/local/gdal-2.2.1/lib/
/usr/local/geos-3.7.0/lib/
EOF然后执行
ldconfig
命令。
-
-
构建并安装 PostGIS.
-
将
cloudberry-contrib/postgis
仓库下载到你的/home/gpadmin
目录中:git clone https://github.com/cloudberry-contrib/postgis.git /home/gpadmin/postgis
chown -R gpadmin:gpadmin /home/gpadmin/postgis -
编译 PostGIS。
在开始编译流程前,执行以下命令,以确保环境变量设置完毕:
source /usr/local/cloudberry/greenplum_path.sh
source /home/gpadmin/cloudberry/gpAux/gpdemo/gpdemo-env.sh
scl enable devtoolset-10 bash
source /opt/rh/devtoolset-10/enable然后继续执行以下命令:
cd /home/gpadmin/postgis/postgis/build/postgis-2.5.4/
./autogen.sh
./configure --prefix="${GPHOME}" --with-pgconfig="${GPHOME}"/bin/pg_config --with-raster --without-topology --with-gdalconfig=/usr/local/gdal-2.2.1/bin/gdal-config --with-sfcgal=/usr/local/sfcgal-1.3.6/bin/sfcgal-config --with-geosconfig=/usr/local/geos-3.7.0/bin/geos-config
make && make install
-
在 Apache Cloudberry 中使用 PostGIS
在 Apache Cloudberry 集群上编译和加载 PostGIS,并已启动演示集群后,你可以运行以下命令来启用 PostGIS 和支持的扩展:
$ psql -p 7000 postgres
postgres=# CREATE EXTENSION postgis; -- 开启 PostGIS 和栅格
postgres=# CREATE EXTENSION fuzzystrmatch; -- 用于安装 Tiger Geocoder
postgres=# CREATE EXTENSION postgis_tiger_geocoder; -- 开启 Tiger Geocoder
postgres=# CREATE EXTENSION address_standardizer; -- 开启 address_standardizer
postgres=# CREATE EXTENSION address_standardizer_data_us;