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

Post on 25-Feb-2016

55 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

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. - PowerPoint PPT Presentation

TRANSCRIPT

Shaowen WangShaowen WangCyberInfrastructure and Geospatial Information CyberInfrastructure and Geospatial Information

Laboratory (CIGI)Laboratory (CIGI)Department of GeographyDepartment of Geography

andandNational 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

22

Database Database CharacteristicsCharacteristics

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

33

Database ApplicationsDatabase Applications

BusinessBusiness EngineeringEngineering MedicineMedicine GovernmentGovernment Etc.Etc.

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

55

MetadataMetadata

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

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

66

Database TransactionDatabase Transaction

InsertInsert ModifyModify DeleteDelete RetrieveRetrieve

77

Transaction SupportTransaction Support

ConcurrencyConcurrency– InterleavingInterleaving– Lost updateLost update

Recovery controlRecovery control– AtomicityAtomicity– IndependenceIndependence

DBMS operationsDBMS operations– CommitCommit– RollbackRollback

88

Database ModelsDatabase Models

RelationalRelational Object-orientedObject-oriented Conceptual modelConceptual model

– DesignersDesigners– MachinesMachines– UsersUsers

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

1010

Structured Query Structured Query Language (SQL)Language (SQL) Domain creationDomain creation Relation scheme creationRelation scheme creation Data manipulationData manipulation

– Data retrievalData retrieval

Connecting to DBConnecting to DB

% ssh % ssh username@geo480.cigi.uiuc.edu username@geo480.cigi.uiuc.edu – 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

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

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;

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;

SQL CommandsSQL Commands

Insert a rowInsert a row– # insert into test values(1, 'attr0', 100);# insert into test values(1, 'attr0', 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;

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';

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

1818

Extended Entity-Extended Entity-Relationship ModelRelationship Model Sub-typeSub-type

– SpecializationSpecialization Super-typeSuper-type

– GeneralizationGeneralization InheritanceInheritance

1919

Object-OrientationObject-Orientation

ObjectObject– StateState– BehaviorBehavior

ClassClass– AttributesAttributes– MethodMethod

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

2121

Relational DatabasesRelational Databases

AttributeAttribute TupleTuple Relation schemeRelation scheme RelationRelation

2222

Relation IDRelation ID

Candidate keyCandidate key Primary keyPrimary key

2323

Operations on Operations on RelationsRelations ProjectProject RestrictRestrict

2424

Relational AlgebraRelational Algebra

Derived relational operatorsDerived relational operators– JoinJoin

Natural joinNatural join PerformancePerformance

2525

Extensible RDBMSExtensible RDBMS

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

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.

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

Logging in to the Logging in to the machinemachine % ssh netid@geog480.cigi.uiuc.edu % ssh netid@geog480.cigi.uiuc.edu

– 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

2929

End of This Class

top related