Azioni

Differenze tra le versioni di "PostgreSQL PostGIS"

Da MontelLUG WIKI.

 
Riga 68: Riga 68:
 
     -createlang -U postgres plpgsql postgisDB
 
     -createlang -U postgres plpgsql postgisDB
 
     -psql -U postgres -d postgisDB -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql
 
     -psql -U postgres -d postgisDB -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql
 +
    -psql -U postgres -d postgisDB -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql
 
Ora in PgAdmin3, se selezionate il database appena creato (cioè con estensione geografica), potrete importare tranquillamente i file .shp grazie all'estensione '''PostGiIS Shapefile and DBF loader''' che trovate nel menù ''Estensioni'' (o icona puzzle).
 
Ora in PgAdmin3, se selezionate il database appena creato (cioè con estensione geografica), potrete importare tranquillamente i file .shp grazie all'estensione '''PostGiIS Shapefile and DBF loader''' che trovate nel menù ''Estensioni'' (o icona puzzle).
  
 
'''Attenzione''': quando tentate di importare un file .shp che ha coordinate cartesiane, in ''Geometry Column'' al posto di '''the_geom''', scrivere '''geometry'''.
 
'''Attenzione''': quando tentate di importare un file .shp che ha coordinate cartesiane, in ''Geometry Column'' al posto di '''the_geom''', scrivere '''geometry'''.

Versione attuale delle 22:02, 26 mar 2012

HOW TO installare e configurare PostgreSQL e PostGIS con interfaccia PgAdmin3 e estensione shp to pgsql su Xubuntu/Ubuntu 11.10 In particolare questa guida fa riferimento alle versioni: PostgreSQL 9.1 PgAdmin3 1.12.3 PostGIS 1.5.3-1

  • Installare PostgrSQL:
   -sudo apt-get install postgresql
  • Editare /etc/postgresql/9.1/main/pg_hba.conf in modo che ci sia la keyword trust:
   # Database administrative login by Unix domain socket
   local   all             postgres                                trust
   
   # TYPE  DATABASE        USER            ADDRESS                 METHOD
   
   # "local" is for Unix domain socket connections only
   local   all             all                                     trust
   # IPv4 local connections:
   host    all             all             127.0.0.1/32            md5
   # IPv6 local connections:
   host    all             all             ::1/128                 md5
   # Allow replication connections from localhost, by a user with the
   # replication privilege.
   #local   replication     postgres                                peer
   #host    replication     postgres        127.0.0.1/32            md5
   #host    replication     postgres        ::1/128                 md5
  • Restartare PostgreSQL:
   -sudo service postgresql restart
  • Verificare che PostgreSQL funzioni, loggandosi:
   -psql -U postgres

PostgreSQL è in ascolto sulla porta 5432, l'utente è postgres e la password postgres. La password si può cambiare con:

   -ALTER USER postgres WITH PASSWORD 'password';

dove al posto di password, potete mettere la password che volete (sempre tra apici).

Da psql si esce con il comando: \q

  • Installare PgAdmin3:
   -sudo apt-get install pgadmin3

dopo il primo avvio di PgAdmin3 è possibile che vi dica che non è aggiornato...dovrebbe funzionare tutto lo stesso.

  • Installare PostGIS:
   -sudo apt-get install postgresql-9.1-postgis
  • Creare link simbolico a shp2pgsql in /usr/bin. Servirà per importare i file .shp in PostgreSQL
   -sudo ln -s /usr/lib/postgresql/9.1/bin/shp2pgsql-gui /usr/bin/shp2pgsql-gui

Modificare (o creare se assente) il file plugins.ini come segue. Se state usando pgadmin3 1.14.0, il file dovrebbe andar messo in /usr/share/pgadmin3/plugins.d/ le versioni inferiori lo mettono in /usr/share/pgadmin3/:

   ;
   ; pgShapeLoader (Linux):
   ;
   Title=PostGIS Shapefile and DBF loader
   Command=$$PGBINDIR/shp2pgsql-gui -U $$USERNAME -d $$DATABASE -p $$PORT -h $$HOSTNAME
   Description=Open a PostGIS ESRI Shapefile or Plain dbf loader console to the current database.
   KeyFile=$$PGBINDIR/shp2pgsql-gui
   Platform=unix
   ServerType=postgresql
   Database=Yes
   SetPassword=No

In questo modo avrete l'estensione grafica per integrare i file .shp integrata direttamente in PgAdmin3.

  • Comandi per creare un database geografico (direttamente da console):
   -createdb -U postgres postgisDB
   -createlang -U postgres plpgsql postgisDB
   -psql -U postgres -d postgisDB -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql
   -psql -U postgres -d postgisDB -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql 

Ora in PgAdmin3, se selezionate il database appena creato (cioè con estensione geografica), potrete importare tranquillamente i file .shp grazie all'estensione PostGiIS Shapefile and DBF loader che trovate nel menù Estensioni (o icona puzzle).

Attenzione: quando tentate di importare un file .shp che ha coordinate cartesiane, in Geometry Column al posto di the_geom, scrivere geometry.