shaowen wang cyberinfrastructure and geospatial information laboratory (cigi) department of...

29
Shaowen Wang Shaowen Wang CyberInfrastructure and Geospatial Information CyberInfrastructure and Geospatial Information Laboratory (CIGI) Laboratory (CIGI) Department of Geography Department of Geography and and National Center for Supercomputing Applications National Center for Supercomputing Applications (NCSA) (NCSA) University of Illinois at Urbana-Champaign University of Illinois at Urbana-Champaign January - February, 2011 January - February, 2011 Principles of GIS Principles of GIS Fundamental database concepts Fundamental database concepts

Upload: james-rodgers

Post on 29-Dec-2015

219 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

Shaowen WangShaowen Wang

CyberInfrastructure and Geospatial Information CyberInfrastructure and Geospatial Information Laboratory (CIGI)Laboratory (CIGI)

Department of GeographyDepartment of Geographyandand

National Center for Supercomputing Applications (NCSA)National Center for Supercomputing Applications (NCSA)University of Illinois at Urbana-ChampaignUniversity of Illinois at Urbana-Champaign

January - February, 2011January - February, 2011

Principles of GISPrinciples of GIS

Fundamental database conceptsFundamental database concepts

Page 2: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

22

Database Database CharacteristicsCharacteristics

ReliabilityReliability IntegrityIntegrity SecuritySecurity ConcurrencyConcurrency Data dependenceData dependence Distributed accessDistributed access InterfaceInterface Self-describingSelf-describing

Page 3: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

33

Database ApplicationsDatabase Applications

BusinessBusiness EngineeringEngineering MedicineMedicine GovernmentGovernment Etc.Etc.

Page 4: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

44

DBMSDBMS

User interface and query languageUser interface and query language Query compiler and optimizerQuery compiler and optimizer Constraint enforcerConstraint enforcer Runtime database processorRuntime database processor Stored data managerStored data manager System catalogSystem catalog

– MetadataMetadata

Page 5: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

55

MetadataMetadata

Data about dataData about data XML (eXtensible Markup Language)XML (eXtensible Markup Language) GMLGML

– http://www.opengis.net/gml/

Page 6: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

66

Database TransactionDatabase Transaction

InsertInsert ModifyModify DeleteDelete RetrieveRetrieve

Page 7: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

77

Transaction SupportTransaction Support

ConcurrencyConcurrency– InterleavingInterleaving– Lost updateLost update

Recovery controlRecovery control– AtomicityAtomicity– IndependenceIndependence

DBMS operationsDBMS operations– CommitCommit– RollbackRollback

Page 8: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

88

Database ModelsDatabase Models

RelationalRelational Object-orientedObject-oriented Conceptual modelConceptual model

– DesignersDesigners– MachinesMachines– UsersUsers

Page 9: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

99

Entity-relationship Entity-relationship model (E-R)model (E-R)

EntityEntity– TypeType– InstanceInstance– IdentifierIdentifier

RelationshipRelationship– One-to-oneOne-to-one– One-to-manyOne-to-many– Many-to-manyMany-to-many

Page 10: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

1010

Structured Query Structured Query Language (SQL)Language (SQL)

Domain creationDomain creation Relation scheme creationRelation scheme creation Data manipulationData manipulation

– Data retrievalData retrieval

Page 11: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

Connecting to DBConnecting to DB

% ssh % ssh [email protected] [email protected] – Enter passwordEnter password

Login to DBLogin to DB– % psql -U username -d database_name% psql -U username -d database_name– Help: %psql --helpHelp: %psql --help

Page 12: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

Some Postgres Some Postgres CommandsCommands

List all accessible databasesList all accessible databases– # \l# \l

Connect to a DB named 'tutorial'Connect to a DB named 'tutorial'– # \c tutorial # \c tutorial

List all the tables in current DBList all the tables in current DB– # \dt, # \d (show all relations)# \dt, # \d (show all relations)

QuitQuit– # \q# \q

Page 13: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

SQL CommandsSQL Commands

Create DBCreate DB– CREATE DATABASE dbname OWNER CREATE DATABASE dbname OWNER

rolename;rolename;– E.g. # create database tutorial;E.g. # create database tutorial;

Page 14: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

SQL CommandsSQL Commands

Create TablesCreate Tables– # create table test(key int, attr # create table test(key int, attr

varchar(20), value float);varchar(20), value float); Delete tableDelete table

– # drop table test;# drop table test;

Page 15: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

SQL CommandsSQL Commands

Insert a rowInsert a row– # insert into test values(1, 'attr0', # insert into test values(1, 'attr0',

100);100); Update table contents Update table contents

– # # update test set attr='attr1' where update test set attr='attr1' where key=1;key=1;

Delete rowsDelete rows– # delete from test where key=1;# delete from test where key=1;

Page 16: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

SQL CommandsSQL Commands

List contents of tableList contents of table– # select * from test; # select * from test; – # select * from test where attr='attr1'; # select * from test where attr='attr1';

Page 17: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

DocumentationDocumentation

PostgresPostgres– http://www.postgresql.org/docs/8.3/http://www.postgresql.org/docs/8.3/

interactive/index.html interactive/index.html – http://www.postgresql.org/docs/8.3/http://www.postgresql.org/docs/8.3/

interactive/sql-commands.html interactive/sql-commands.html An SQL TutorialAn SQL Tutorial

– http://www.w3schools.com/sql/http://www.w3schools.com/sql/default.aspdefault.asp

Page 18: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

1818

Extended Entity-Extended Entity-Relationship ModelRelationship Model

Sub-typeSub-type– SpecializationSpecialization

Super-typeSuper-type– GeneralizationGeneralization

InheritanceInheritance

Page 19: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

1919

Object-OrientationObject-Orientation

ObjectObject– StateState– BehaviorBehavior

ClassClass– AttributesAttributes– MethodMethod

Page 20: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

2020

O-O FeaturesO-O Features

EncapsulationEncapsulation– Reduces modeling complexityReduces modeling complexity– Promotes reusePromotes reuse

Inheritance and polymorphismInheritance and polymorphism– Combats impedance mismatchCombats impedance mismatch– Metaphorical powerMetaphorical power

Page 21: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

2121

Relational DatabasesRelational Databases

AttributeAttribute TupleTuple Relation schemeRelation scheme RelationRelation

Page 22: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

2222

Relation IDRelation ID

Candidate keyCandidate key Primary keyPrimary key

Page 23: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

2323

Operations on Operations on RelationsRelations

ProjectProject RestrictRestrict

Page 24: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

2424

Relational AlgebraRelational Algebra

Derived relational operatorsDerived relational operators– JoinJoin

Natural joinNatural join

PerformancePerformance

Page 25: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

2525

Extensible RDBMSExtensible RDBMS

RDBMS problems when handling RDBMS problems when handling spatial dataspatial data– Data structureData structure– PerformancePerformance– SearchSearch

Page 26: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

Importing data from Importing data from CSVCSV

Data formatData format– CSV fileCSV file– First is assumed to be column namesFirst is assumed to be column names– Data values are separated by , and Data values are separated by , and

non numeric values are quoted.non numeric values are quoted.

Page 27: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

Importing data from Importing data from CSVCSV

Create insert file from csv fileCreate insert file from csv file– /srv/cigi/code/csv2insert.pl --csv-file /srv/cigi/code/csv2insert.pl --csv-file

/srv/cigi/code/test.csv --output-file /srv/cigi/code/test.csv --output-file $HOME/insert.sql --table-name test$HOME/insert.sql --table-name test

– /srv/cigi/code/csv2insert.pl --help/srv/cigi/code/csv2insert.pl --help Getting data to DBGetting data to DB

– psql -U username -d database < psql -U username -d database < insertfileinsertfile

Page 28: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

Logging in to the Logging in to the machinemachine

% ssh [email protected] % ssh [email protected] – Login name: netidLogin name: netid– Password: your passwordPassword: your password

% psql -U username –d tutorial% psql -U username –d tutorial– Login name: geog480Login name: geog480– Password: samePassword: same

Page 29: Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications

2929

End of This Class