參考
PostGIS Installation
在Linux環(huán)境下編譯安裝配置PostGIS/PostgreSQL全過程
安裝PostGIS(Linux篇)
下載源碼
Postgresql源碼
GDAL源碼
Proj源碼
Geos源碼 依賴gdal
libxml源碼
PostGIS源碼 依賴gdal proj geos libxml
部署
1. Postgresql部署
mkdir /usr/local/pgsql
tar zxf postgresql-8.4.0.tar.gz
cd postgresql-8.4.0
./configure –prefix=/usr/local/pgsql #配置
make #編譯
make install #安裝
2. gdal proj geos libxml
同上
3. postgis
./configure –prefix=/usr/local/postgis
--with-pgconfig=/var/local/pgsql/bin/pg_config
--with-gdalconfig=/var/local/gdal/bin/gdal-config
--with-geosconfig=/var/local/pgsql/bin/geos-config
--with-xml2config=/var/local/libxml/bin/xml2-config
--with-projdir=/var/local/proj
4. postgresql & postgis配置
#1. 創(chuàng)建PostgreSQL的用戶,設定密碼
adduser postgres
#2. 創(chuàng)建PostgreSQL的數(shù)據(jù)庫目錄,修改目錄的權限屬性
mkdir /usr/local/pgsql/data
chown -R postgres /usr/local/pgsql
#3. 初始化數(shù)據(jù)庫并啟動
# 以postgres用戶登陸
su postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
# 啟動數(shù)據(jù)庫服務器
pg_ctl start -D /usr/local/pgsql/data –l pgsql.log
#4. 設置遠程可訪問數(shù)據(jù)庫
vi /usr/local/pgsql/data/postgresql.conf
# 把listen_address = 'localhost' 改為
listen_address = '*'
vi /usr/local/pgsql/data/pg_hba.conf
# 在文件最后加入:
host all all 192.168.1.0/24 md5
# 為postgres用戶設置密碼
su - postgres
-base-4.2$ psql
postgres=# \password postgres
# 停止數(shù)據(jù)庫服務
/usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data
# 重新啟動數(shù)據(jù)庫
/usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data –l pgsql.log
#5. 創(chuàng)建數(shù)據(jù)庫
# 切換到postgres用戶
su postgres
# 創(chuàng)建數(shù)據(jù)庫gisdb
/usr/local/pgsql/bin/createdb gisdb
#6. 增加動態(tài)鏈接庫的搜索路徑
vi /etc/ld.so.conf
# 在最后添加四行:
/usr/local/lib
/usr/local/proj4/lib
/usr/local/geos/lib
/usr/local/pgsql/lib
# 運行l(wèi)dconfig命令,使以上修改生效:
/sbin/ldconfig
#7. 創(chuàng)建postgis空間數(shù)據(jù)庫(使用postgis提供的sql)
# 在gisdb上創(chuàng)建postgis的函數(shù)、數(shù)據(jù)類型等資源
/usr/local/pgsql/bin/psql -h 127.0.0.1 -d gisdb -U postgres -f /usr/local/pgsql/share/contrib/postgis-2.4/postgis.sql
# 在gisdb上創(chuàng)建空間參考表
/usr/local/pgsql/bin/psql -h 127.0.0.1 -d gisdb -U postgres -f /usr/local/pgsql/share/contrib/postgis-2.4/spatial_ref_sys.sql
# 完成postgis空間數(shù)據(jù)庫創(chuàng)建
5. 導入shapefile數(shù)據(jù)到postgresql
shp2pgsql -W "UTF-8" D:\branch.shp branch > D:\branch.sql
#這里的-W "UTF-8"代表字符編碼的轉換。D:\branch.shp則是要生成sql腳本的shp文件.
#branch是創(chuàng)建數(shù)據(jù)表的表名,>不能少, D:\branch.sql則是要生成SQL文件的路徑
#生成成功后命令提示符會顯示如下:
#Shapefile type: Point
#Postgis type: POINT[2]
- 執(zhí)行該SQL語句文件,導入數(shù)據(jù)到數(shù)據(jù)庫template_postgis中
psql -d gisdb -f D:\branch.sql postgres
#其中 gisdb是數(shù)據(jù)庫名,postgres是該數(shù)據(jù)庫的用戶
#執(zhí)行成功后,刷新該數(shù)據(jù)庫,就可以看到表branch
錯誤
1. geos make報錯
postgres install + postgis install(二)
2. psql導入.sql數(shù)據(jù)報錯:psql:...sql relation "branch" does not exist
postgis未正確安裝