Download presentation
Presentation is loading. Please wait.
Published byJames Rodgers Modified over 9 years ago
1
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 Principles of GIS Fundamental database concepts
2
2 Database Characteristics Reliability Reliability Integrity Integrity Security Security Concurrency Concurrency Data dependence Data dependence Distributed access Distributed access Interface Interface Self-describing Self-describing
3
3 Database Applications Business Business Engineering Engineering Medicine Medicine Government Government Etc. Etc.
4
4 DBMS User interface and query language User interface and query language Query compiler and optimizer Query compiler and optimizer Constraint enforcer Constraint enforcer Runtime database processor Runtime database processor Stored data manager Stored data manager System catalog System catalog –Metadata
5
5 Metadata Data about data Data about data XML (eXtensible Markup Language) XML (eXtensible Markup Language) GML GML –http://www.opengis.net/gml/ http://www.opengis.net/gml/
6
6 Database Transaction Insert Insert Modify Modify Delete Delete Retrieve Retrieve
7
7 Transaction Support Concurrency Concurrency –Interleaving –Lost update Recovery control Recovery control –Atomicity –Independence DBMS operations DBMS operations –Commit –Rollback
8
8 Database Models Relational Relational Object-oriented Object-oriented Conceptual model Conceptual model –Designers –Machines –Users
9
9 Entity-relationship model (E-R) Entity Entity –Type –Instance –Identifier Relationship Relationship –One-to-one –One-to-many –Many-to-many
10
10 Structured Query Language (SQL) Domain creation Domain creation Relation scheme creation Relation scheme creation Data manipulation Data manipulation –Data retrieval
11
Connecting to DB % ssh username@geo480.cigi.uiuc.edu % ssh username@geo480.cigi.uiuc.edu –Enter password Login to DB Login to DB –% psql -U username -d database_name –Help: %psql --help
12
Some Postgres Commands List all accessible databases List all accessible databases –# \l Connect to a DB named 'tutorial' Connect to a DB named 'tutorial' –# \c tutorial List all the tables in current DB List all the tables in current DB –# \dt, # \d (show all relations) Quit Quit –# \q
13
SQL Commands Create DB Create DB –CREATE DATABASE dbname OWNER rolename; –E.g. # create database tutorial;
14
SQL Commands Create Tables Create Tables –# create table test(key int, attr varchar(20), value float); Delete table Delete table –# drop table test;
15
SQL Commands Insert a row Insert a row –# insert into test values(1, 'attr0', 100); Update table contents Update table contents –# update test set attr='attr1' where key=1; Delete rows Delete rows –# delete from test where key=1;
16
SQL Commands List contents of table List contents of table –# select * from test; –# select * from test where attr='attr1';
17
Documentation Postgres Postgres –http://www.postgresql.org/docs/8.3/interact ive/index.html –http://www.postgresql.org/docs/8.3/interact ive/sql-commands.html An SQL Tutorial An SQL Tutorial –http://www.w3schools.com/sql/default.asp
18
18 Extended Entity- Relationship Model Sub-type Sub-type –Specialization Super-type Super-type –Generalization Inheritance Inheritance
19
19 Object-Orientation Object Object –State –Behavior Class Class –Attributes –Method
20
20 O-O Features Encapsulation Encapsulation –Reduces modeling complexity –Promotes reuse Inheritance and polymorphism Inheritance and polymorphism –Combats impedance mismatch –Metaphorical power
21
21 Relational Databases Attribute Attribute Tuple Tuple Relation scheme Relation scheme Relation Relation
22
22 Relation ID Candidate key Candidate key Primary key Primary key
23
23 Operations on Relations Project Project Restrict Restrict
24
24 Relational Algebra Derived relational operators Derived relational operators –Join Natural join Natural join Performance Performance
25
25 Extensible RDBMS RDBMS problems when handling spatial data RDBMS problems when handling spatial data –Data structure –Performance –Search
26
Importing data from CSV Data format Data format –CSV file –First is assumed to be column names –Data values are separated by, and non numeric values are quoted.
27
Importing data from CSV Create insert file from csv file 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 Getting data to DB – psql -U username -d database < insertfile
28
Logging in to the machine % ssh netid@geog480.cigi.uiuc.edu % ssh netid@geog480.cigi.uiuc.edu –Login name: netid –Password: your password % psql -U username –d tutorial % psql -U username –d tutorial –Login name: geog480 –Password: same
29
29 End of This Class
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.