Database Management Systems - Università degli Studi di Trento

FOSS Relational Database and GeoDatabase
Part II
PostgreSQL, Data Base Open Source and GRASS
Marco Ciolli, Fabio Zottele
Dipartimento di Ingegneria Civile e Ambientale
Universita' degli Studi di Trento
Marco Ciolli, Dipartimento di Ingegneria Civile e Ambientale
Data Base management in GRASS
• DB management in GRASS may follow different procedures.
• Procedures are not equivalent and the chice of a procedure provides
different data processing and analisys tools
In particular alphanumeric data connected to geographic data may be
managed:
• Directly with GRASS DB engine
This option does not guarantee the respect of DBMS security functions
(coherence, integrity and so on) file format is dbf
• Through an external DBMS interfaced with GRASS in different ways
(directly, not directly)
Data Management by means of an external Data Base is more reliable
and improves analisys and processing capabilities
Here various procedures regarding GRASS 6.2.x versions interfaced with
PostgreSQL.
Marco Ciolli, Dipartimento di Ingegneria Civile e Ambientale
Why an external DBMS is better?
Direct DB management with GRASS nay lead to:
• data redundance and inconsistency;
• data access concurrence problems (multi-user simultaneous access);
• lost of data integrity;
• security problems;
• performance problems under the point of view of time needed to:
- data search;
- data update.
A DBMS, is a tool designed expressely to manage archives, therefore is provided
with all the instruments that are necessary and is flexible and tailorable.
Marco Ciolli, Dipartimento di Ingegneria Civile e Ambientale
Two interface types
GRASS and PostgreSQL interface can be obtained in two ways:
Direct Interface
Interface through ODBC
GRASS
GRASS
Interfaccia
GRASS/Postgres
Interfaccia
GRASS/ODBC
PostgreSQL
PostgreSQL
Marco Ciolli, Dipartimento di Ingegneria Civile e Ambientale
ODBC
driver
ODBCPostgreSQL
http://grass.osgeo.org/grass64/manuals/html64_user/database.html
GRASS can be connected to one or more database management systems (DBMS). db.*
command set provides a base SQL support to manage attributes, while v.db.* command
set operates with vector maps.
Some functions
have been made
available recently
* Categorie: Category number is vector ID. It is used to connect the attribute/s to
each vector object. A vector object can have zero, one, two or more categories.
Category numbers are stored within geometry file and within attributes tablefor each
vector object (generally "cat" column).
Using v.category, category number can be printed or maintained. To connect a
vector object to many different tables, different category numbers for each vector
object are necessary.
* Layers: It is possible to connect geographical objects in a vector map to one
or more tables. Each “link” to a different attribute table is called “layer”. A link
defines which database driver, what database and which table must be used.
Each category number in a geometry file corresponds to a row in the attribute table
(generally “cat" column). Using v.db.connect layers can be listed or maintained.
GRASS layers does not contain geografic objects, but they are link to attribute
tables in which vector object can have zero, one or more categories.
If a vector object has zero categories in a layer, the result is it does not appear in the
layer.
In this way some vector objects can appear in some layers and not in other layers. The
advantage of this system is it allows to locate thematically different object that are
topologically related in a single map (for example forests and lakes, or cultivated areas
and water basins).
These virtual layers are also useful to connect temporal data series to series of objects
that does not change in time.
The first layer is active, for example the first table corresponds to the first layer.
Further tables are tied to following layers.
* SQL support: DBF driver provides a limited support to SQL while other
DBMS backends (PostgreSQL, MySQL ...) give full SQL support because
SQL commands are directly sent through DBMI.
SQL commands can be directly executed with db.execute, db.select and
other db.* modules.
When a new table is created, a new attribute table must be created and
must be populated with a row per each category (using v.to.db). This
operation can be performed in a single pass using v.db.addtable together
with type definition of table column.
Db commands and db interaction commands:
comandi db
• DB connections:
1. db.connect
2. db.test
3. db.drivers
4. db.login
• Tables:
1. db.columns
2. db.copy
3. db.describe
4. db.tables
• SQL query (operations on tables):
1.
2.
db.execute
db.select
db.connect – allows the
connection through a
Dbm interface
db.test
Tests db driver
to check function
db.drivers – Shows the available db driver list
db.login – Sets user and password of a certain db driver
db.columns –
Allows to
display
columns of a
certain
table within a
database
When
database is
connected and
tables are
visible it is
posible to use
graphic
interface, more
user friendly,
to display the
columns of a
certain table in
a database
db.copy – allows the user
to copy a table between two
database that maybe also
connected through different
db drivers
db.describe Allows the user to
display information about
a table. If -c parameter is
used only the names of
the columns are obtained
instead of complete
description
db.tables Fa la lista
di tutte le
tabelle
contenute
in un
database
db.execute –
executes SQL
strings directly
written or
contained in a
text file
db.select – Prints the
result of a selection
made in DataBase
from an SQL string
read from an input
file or written in the
interface
Db commands and interaction vector-db:
comandi v.db
• Vector-db connection:
1.
2.
1.
2.
3.
4.
• SQL query:
v.db.connect
v.to.db
v.db.update
v.db.addtable
v.db.droptable
v.db.reconnect.all
1.
2.
3.
4.
Display Manager
d.vect
v.extract
v.reclass
v.db.connect Prints or sets the
database connection for a
particular vector
v.to.db – Allows to insert in a database data coming from a
vector file
v.db.update Allows to assign a new
value to a column
connected to a certain
map
v.db.addtable – creates
and adds a new
attributes table to a
certain layer of an
existing vector map
v.db.droptable –
removes attibutes table
of an exixting vector
map
v.db.reconnect.all –
reconnects vector
files to a new
database
db.dropcol: Eliminates a column from a selcted attribute table
And:
db.in.ogr: Imports tables in various formats
db.out.ogr: Exports tables in various formats
Attributes table display from layer manager
It is possible to display
the content of a table
connected to the
displayed layer
Query from table manager
It is possible
to create a
query direcly
form table
manager, in
this case all
Trentino SIC
with more
than 4000 ha
surface
Query in table manager
It is possible to
use query builder
in table manager
Query in table manager
Add vector map layers in Table Manager
Delete layers in a vector map in Table Manager
Modify layers in a vector map in Table Manager
Manage tables in vector maps in Table Manager
Esecuting a query with d.vect
si richiede la
visualizzazione delle
zone di censimento
aventi area minore di
500000
Funziona con i monitor
lanciati da d.mon
Esecuting a query with layer manager
SIC in Trentino with surface less than 4000 hectars
Esecuting a query with gis.m (tcltk - old)
Buildings in Trento with roof height less than
10 m
Esecuting a query with v.extract
Asks to create a new
map containing only
streets in with
emission between 8
and 9 in the morning
is more than
5000 (g CO/km)
d.what.vect -help
Description:
Allows the user to interactively query a vector map layer at user-selected
locations within the current geographic region.
Usage:
d.what.vect [-1txdfe] [map=name[,name,...]]
Flags:
-1 Identify just one location
-t Terse output. For parsing by programs.
-x Print information as plain text to terminal window.
-d Print topological information (debugging).
-f Enable flashing (slower).
-e Open form in edit mode.
Xterm:
Vector -> Query with mouse (Form mode, editing enabled)
d.what.vect -e nomefile
Old interface d.m is still active can be invoked with: d.m&
It uses monitor x1, x2, x3
v.db.univar
v.db.join
v.db.renamecol
v.db.dropcol
pgDesigner
http://pgdesigner.sourceforge.net/it/index.html
pgDesigner
pgDesigner
http://www.opengis.org/index.htm
MapServer
http://mapserver.gis.umn.edu/
http://ems-hitech.com/pgmanager/?src=overture
http://www.pgadmin.org/
pgAdminIII
http://www.pgadmin.org/
PgAccess
graphic interface for PostgreSQL written in Tcl/Tk, that allows the
management of ana archive: table operations, queries....
Marco Ciolli, Dipartimento di Ingegneria Civile e Ambientale
http://sourceforge.net/projects/pgaccess
Marco Ciolli, Dipartimento di Ingegneria Civile e Ambientale
DBdesigner4 a tool to easily design data base
(supports MySQL but, at the moment, not PostgreSQL)
phpPgAdmin
phpPgAdmin
http://kandalaya.org/download/oo-pgsql.html
http://users.binary.net/thehaas/pgodbc-ooo-howto.html
http://grass.osgeo.org/wiki/Openoffice.org_with_SQL_Databases
http://www.comunecampagnano.it/gnu/accessless/
http://dba.openoffice.org/
http://mdbtools.sourceforge.net/
Bibliografia
• AA.VV.: "PostgreSQL Programmer's Guide", Regent of the University of California, 1995.
• AA.VV.: "PostgreSQL User's Guide", Regent of the University of California, 1995.
• V.S. Subrahmanian: “Principles of multimedia database system”, Morgan Kaufmann, 1998
• M. A. Brovelli, M. Negretti, C. Saldarini: “GRASS interfacing with DBMSs”, Geomatics Workbooks
• Indexing tree methods and spatial ordering for maps and geographic data: an overview and application to the geodetic gis project, atti del
congresso ISPRS - WG VI/3 "International cooperation and technology transfert", Parma, 15-19 febbraio 1999 L. Biagi, M. A. Brovelli, M.
Negretti and C. Saldarini;
• Nuove metodologie GIS per la stima e l’aggiornamento del geoide, pp.123-165, tesi di Laurea svolta presso il Politecnico di Milano, 1999, M.
Negretti, C.Saldarini.
• Ciolli M. Dispense del Corso GRASS e OPEN SOURCE GIS teoria ed applicazioni 1a edizione - anno 2003, 2a edizione - anno 2004, 3a
edizione - anno 2005, 4a edizione - Roma anno 2006, 5a edizione Trento anno 2006, 6a edizione Trento anno 2007,7a edizione Trento anno 2008,
8a edizione Trento anno 2009,.
• File sorgenti e manuali di PostgreSQL: http://www.postgresql.org e http://techdocs.postgresql.org/
• Interfaccia grafica PgAccess: http://www.flex.ro/pgaccess/ e www.pgaccess.org
• File sorgenti e manuali di GRASS: http://grass.itc.it/
• http://www.html.it/sql
•Suffritti P., Appunti sui DataBase Relazionali e sul linguaggio SQL. http://www.suffritti.it/SQLTutorial.htm
• L.Biagi, M.A.Brovelli, M.Negretti, Caratteristiche di PostgreSQL
http://www.geo.unipr.it/~gis/TUTORIALS/POSTGRESINTRO/postgres.pdf
•M. Zanoni, Implementazione di un sistema integrato gis–database per la gestione dei dati di traffico e produzione di mappe delle emissioni.
applicazione alla città di Trento. Tesi di Laurea Ingegneria Trento 2003
•C. Modena, Analisi e delimitazione delle aree forestali con particolare funzione protettiva in Trentino tramite tecniche GIS. Tesi di Laurea
Ingegneria Trento 2003
•A. Daloli, Strutturazione e sviluppo di un Database in Postgresql per l’analisi dei dati di traffico Tesi di Laurea, Ingegneria Trento 2002
•All the web sites cited in this document must be considered part of this bibliography list.
Marco Ciolli, Dipartimento di Ingegneria Civile e Ambientale