本文共 3017 字,大约阅读时间需要 10 分钟。
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 theresudo apt-add-repository ppa:sharpie/for-science # To get GEOS 3.3.2sudo apt-add-repository ppa:sharpie/postgis-nightlysudo apt-get updatesudo apt-get install postgresql-9.1-postgis3. 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 postgrespsql -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.sqlpsql -d template_postgis2 -f /usr/share/postgresql/9.1/contrib/postgis-2.1/spatial_ref_sys.sqlpsql -d template_postgis2 -f /usr/share/postgresql/9.1/contrib/postgis-2.1/rtpostgis.sqlpsql -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_postgis24. 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 postgresEnter new UNIX password: Retype new UNIX password: passwd: password updated successfully$ sudo -s -u postgrespostgres$ psqlpsql (9.1.3)Type "help" for help.postgres=# \password postgresEnter new password: Enter it again: postgres=# \qpostgres$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 postgrespostgres$ createuser --superuser $USER ---- note: createuser is a command line tool to create a PostgreSQL user, not a system account postgres$ createdb $USERpostgres$ psqlpsql (9.1.3)Type "help" for help.postgres=# \password $USEREnter new password: Enter it again: postgres=# \qpostgres$ exit$USER$ psqlpsql (9.1.3)Type "help" for help.$USER=# ---- voila!
转载地址:http://urbvi.baihongyu.com/