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!
转载自:https://blog.csdn.net/sqzhao/article/details/8741010