Ubuntu12下安装PostGIS

1. Before we begin, you should uninstall your existing postgis packages: 卸载掉原有的postgis和postgresql-9.1-postgis

sudo dpkg --purge postgis postgresql-9.1-postgis

sudo apt-get install postgresql-9.1 postgresql-client-9.1 postgresql-contrib-9.1 postgresql-doc-9.1 pgadmin3

sudo apt-get install uuid libgnomeprintui2.2-0 oidentd libdbd-pg-perl


2. Then add a new repository and install PostGIS from there
sudo apt-add-repository ppa:sharpie/for-science  # To get GEOS 3.3.2

sudo apt-add-repository ppa:sharpie/postgis-nightly

sudo apt-get update

sudo apt-get install postgresql-9.1-postgis


3. Next we should create a new template database (optional but recommended).

sudo su postgres -c'createdb -E UTF8 -U postgres template_postgis2'
sudo su postgres -c'createlang -d template_postgis2 plpgsql;'
sudo su postgres
psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis2'"
psql -d template_postgis2 -f /usr/share/postgresql/9.1/contrib/postgis-2.1/postgis.sql
psql -d template_postgis2 -f /usr/share/postgresql/9.1/contrib/postgis-2.1/spatial_ref_sys.sql
psql -d template_postgis2 -f /usr/share/postgresql/9.1/contrib/postgis-2.1/rtpostgis.sql
psql -d template_postgis2 -c "GRANT ALL ON geometry_columns TO PUBLIC;"
psql -d template_postgis2 -c "GRANT ALL ON geography_columns TO PUBLIC;"
psql -d template_postgis2 -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"
createdb training -T template_postgis2


4. Ok now we can load a raster (see sample data download below):

sudo su postgres -c'raster2pgsql -s 4326 srtm_4326.tif | psql training'
--raster2pgsql -s 4326 srtm_4326.tif | psql training
sudo su postgres -c'shp2pgsql -s 4326 -d -g geom -I places.shp places| psql training'

5. Good – now our spatial database is ready to use – and has raster support! Here is a nice example of what you can do. The query looks up the altitude from the SRTM raster for each place listed using the ST_Value

sudo su postgres
psql training

select ST_Value(rast, geom, true) from places, srtm_4326;


Next steps - start these steps logged in as your user account:NOTE: you do not have to use the same password for the system and PostgreSQL user accounts that share the same name.

$ sudo passwd postgres
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
$ sudo -s -u postgres
postgres$ psql
psql (9.1.3)
Type "help" for help.

postgres=# \password postgres
Enter new password: 
Enter it again: 
postgres=# \q
postgres$ 

If you're going to want to connect to the PostgreSQL database using your own account (so you don't have to fool around with 'postgres'), you may want to do this:

$USER$ sudo -s -u postgres
postgres$ createuser --superuser $USER     ---- note: createuser is a command line tool to create a PostgreSQL user, not a system account  
postgres$ createdb $USER
postgres$ psql
psql (9.1.3)
Type "help" for help.

postgres=# \password $USER
Enter new password: 
Enter it again: 
postgres=# \q
postgres$ exit
$USER$ psql
psql (9.1.3)
Type "help" for help.

$USER=#                        ---- voila! 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值