290 likes | 457 Views
Principles of GIS. Fundamental database concepts. Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications (NCSA) University of Illinois at Urbana-Champaign January - February, 2011.
E N D
Principles of GIS Fundamental database concepts Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications (NCSA) University of Illinois at Urbana-Champaign January - February, 2011
Database Characteristics • Reliability • Integrity • Security • Concurrency • Data dependence • Distributed access • Interface • Self-describing
Database Applications • Business • Engineering • Medicine • Government • Etc.
DBMS • User interface and query language • Query compiler and optimizer • Constraint enforcer • Runtime database processor • Stored data manager • System catalog • Metadata
Metadata • Data about data • XML (eXtensible Markup Language) • GML • http://www.opengis.net/gml/
Database Transaction • Insert • Modify • Delete • Retrieve
Transaction Support • Concurrency • Interleaving • Lost update • Recovery control • Atomicity • Independence • DBMS operations • Commit • Rollback
Database Models • Relational • Object-oriented • Conceptual model • Designers • Machines • Users
Entity-relationship model (E-R) • Entity • Type • Instance • Identifier • Relationship • One-to-one • One-to-many • Many-to-many
Structured Query Language (SQL) • Domain creation • Relation scheme creation • Data manipulation • Data retrieval
Connecting to DB % sshusername@geo480.cigi.uiuc.edu Enter password Login to DB % psql -U username -d database_name Help: %psql --help
Some Postgres Commands List all accessible databases # \l Connect to a DB named 'tutorial' # \c tutorial List all the tables in current DB # \dt, # \d (show all relations) Quit # \q
SQL Commands Create DB CREATE DATABASE dbname OWNER rolename; E.g. # create database tutorial;
SQL Commands Create Tables # create table test(key int, attrvarchar(20), value float); Delete table # drop table test;
SQL Commands Insert a row # insert into test values(1, 'attr0', 100); Update table contents # update test set attr='attr1' where key=1; Delete rows # delete from test where key=1;
SQL Commands List contents of table # select * from test; # select * from test where attr='attr1';
Documentation Postgres http://www.postgresql.org/docs/8.3/interactive/index.html http://www.postgresql.org/docs/8.3/interactive/sql-commands.html An SQL Tutorial http://www.w3schools.com/sql/default.asp
Extended Entity-Relationship Model • Sub-type • Specialization • Super-type • Generalization • Inheritance
Object-Orientation • Object • State • Behavior • Class • Attributes • Method
O-O Features • Encapsulation • Reduces modeling complexity • Promotes reuse • Inheritance and polymorphism • Combats impedance mismatch • Metaphorical power
Relational Databases • Attribute • Tuple • Relation scheme • Relation
Relation ID • Candidate key • Primary key
Operations on Relations • Project • Restrict
Relational Algebra • Derived relational operators • Join • Natural join • Performance
Extensible RDBMS • RDBMS problems when handling spatial data • Data structure • Performance • Search
Importing data from CSV Data format CSV file First is assumed to be column names Data values are separated by , and non numeric values are quoted.
Importing data from CSV Create insert file from csv file /srv/cigi/code/csv2insert.pl --csv-file /srv/cigi/code/test.csv --output-file $HOME/insert.sql --table-name test /srv/cigi/code/csv2insert.pl --help Getting data to DB psql -U username -d database < insertfile
Logging in to the machine % sshnetid@geog480.cigi.uiuc.edu Login name: netid Password: your password % psql -U username –d tutorial Login name: geog480 Password: same