参考官网 http://postgis.net/
PostGis版本2.5.3
1.安装libxml2
# yum install libxml2 libxml2-devel
2.安装json-c
# tar zxvf json-c-json-c-0.13.1-20180305.tar.gz
# cd json-c-json-c-0.13.1-20180305
# ./configure && make && make install
3.安装protobuf-c
# tar zxvf protobuf-3.9.2.tar.gz
# cd protobuf-3.9.2
# ./autogen.sh
# ./configure && make && make install
# /usr/local/bin/protoc --version
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
# tar zxvf protobuf-c-1.3.2.tar.gz
# cd protobuf-c-1.3.2
# ./configure && make && make install
4.安装proj
# tar zxvf sqlite-autoconf-3290000.tar.gz
# cd sqlite-autoconf-3290000
# ./configure && make && make install
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
# tar zxvf proj-6.2.0.tar.gz
# cd proj-6.2.0
# ./configure && make && make install
5.安装geos
# tar zxvf geos-3.7.2.tar.gz
# cd geos-3.7.2
# ./autogen.sh
# ./configure
# make && make install
6.安装gdal
# tar zxvf gdal-3.0.1.tar.gz
# cd gdal-3.0.1
# ./configure && make && make install
7.安装postgis
# tar zxvf postgis-2.5.3.tar.gz
# cd postgis-2.5.3
# ./configure \
--with-geosconfig=/usr/local/bin/geos-config \
--with-projdir=/usr/local/ \
--with-gdalconfig=/usr/local/bin/gdal-config
# make && make install
确认postgis组间已安装
$ ll /pgdata/postgres/share/extension/postgis*
8.使用postgis
使用超级用户创建扩展
$ psql -Upostgres postgres
create extension postgis;
create extension postgis_topology;
create extension fuzzystrmatch;
create extension postgis_tiger_geocoder;
--测试SQL
CREATE TABLE gtest ( gid serial primary key, name varchar(20));
SELECT AddGeometryColumn ('gtest', 'geom', 4326,'LINESTRING', 2);
select DropGeometryColumn('gtest','geom');
SELECT AddGeometryColumn ('gtest', 'geom', 0,'LINESTRING', 2);
INSERT INTO gtest (GID, NAME, GEOM)
VALUES (1, 'First Geometry',ST_GeomFromText('LINESTRING(2 3,4 5,6 5,7 8)'));
源码编译比较慢,大约需要几个小时不等,如果只是测试使用建议使用docker安装