Upload
lynga
View
229
Download
0
Embed Size (px)
Citation preview
Marco Ciolli, Dipartimento di Ingegneria Civile e Ambientale
FOSS Relational Database and GeoDatabase FOSS Relational Database and GeoDatabase
Part IIPart II
PostgreSQL, Data Base Open Source and GRASSPostgreSQL, Data Base Open Source and GRASSMarco Ciolli1 Fabio Zottele2
1DICAM Dipartimento di Ingegneria Civile Ambientale e Meccanica, Università di Trento
2 FEM Fondazione Mach, Centro Trasferimento Tecnologico
• 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 engineThis 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 are various procedures regarding GRASS 6.2.x versions interfaced with PostgreSQL.
Marco Ciolli, Dipartimento di Ingegneria Civile e Ambientale
Data Base management in GRASS
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
Marco Ciolli, Dipartimento di Ingegneria Civile e Ambientale
GRASS
InterfaceGRASS/Postgres
PostgreSQL
GRASS
InterfaceGRASS/ODBC
PostgreSQLdriverODBC-
PostgreSQL
ODBC
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.
* Categories: 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
Db commands and db interaction commands:
1. db.connect2. db.test3. db.drivers4. db.login
• DB connections:1. db.columns2. db.copy3. db.describe4. db.tables
5. db.execute6. db.select
• Tables:
• SQL query (operations on tables):
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.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:
commands v.db
1. v.db.connect2. v.to.db
3. v.db.update4. v.db.addtable5. v.db.droptable6. v.db.reconnect.all
• Vector-db connection:
1. Display Manager2. d.vect3. v.extract4. v.reclass
• SQL query:
v.db.addtable – creates and adds a new
attributes table to a certain layer of an
existing vector map
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 directly from table
manager, in this case all Trentino SIC
with more than 4000 ha
surface
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 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.
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
PgAccess
DB-Designer Fork
DB Designer Fork is a fork of the fabFORCE DBDesigner 4. It integrates entity relationship design,front-end (you can run queries) and SQL exporting. DB Designer Fork generates SQL scripts
for Oracle, SQL Server, MySQL, FireBird, SQLite and PostgreSQL.
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