the role of gis in the control and prevention of animal...
TRANSCRIPT
Overview
• What is a database?
• DBMS
• Type of database
• Tables, Relationships
• Introduction to Query, Joins
• Working with data in GIS
• Shapefiles
• Geodatabases
• Spatial RDBMS
What is a Database?
The database is a data collection organized in a logical
structure, stored in persistent memory, managed through
specific software called DBMS (Database Management
System).
What is a DBMS?
A software to manage database:
• Manage and interact with data:
• Insert, Update, Delete …
• Query
• Manage database
• Create, Drop …
• Manage users and data access, permission
• Data consistency, relationships between data
Hierarchic DB
• Simple structure (Parent-child) Rigid, not flexible
• Interrogations only from root to leaves
• Redundancy of information
Reticular DB
• Quite efficient structure for interrogations
• Reduce the redundancy of information
• Complex to manage and maintain
Relational DB
• Based on relations
• Flexible logic structure
• Reduce the redundancy of information
• Quite simple to manage and maintain
A
row 1
row 2
…
B
row 1
row 2
…
C
row 1
…
D
row 1
row 2
…
Tables
Logic structure:
• Records
• Fields
• Keys
• Primary *Unique, Mandatory (not null)
UserID Surname Name Born date
RSSMRO97D11C441R Rossi Mario 11/04/1987
CHRGRG98C17F205L Chiari Giorgio 21/08/1982
BNCLRA96A61B333C Bianchi Laura 09/02/1994
Tables – data type
Main data type
• Text / Character
• Numeric
• Date / Time
• Boolean
• …
Different RDMS can have quite different data-type
Relationships
Entities may be related / connected
• Database relationships
• Stable;
• Defined during the database creation
• Prevent database incosistency
• Joins
• Logical relationships (volatile)
• Defined when the user needs, using query or other tools
• Allows to connect external data
Database Relationships
Entities may be related / connected
• 2 structured tables
• Key fields• Primary * is unique, is mandatory (not null)
• Foreign * must have an associated record in the reference table
UserID Surname Name Born date
RSSMRO97D11C441R Rossi Mario 11/04/1987
VRDGRG98C17F205L Verdi Giorgio 21/08/1982
BNCLRA96A61B333C Bianchi Laura 09/02/1994
UserID Address City Country AID
RSSMRO97D11C441R Via Colombo Milano Italy 1
CHRGRG98C17F205L Piazza Capitale Venezia Italy 2
BNCLRA96A61B333C Via Roma Roma Italy 3
Database Relationships
• 1-1
• 1-N
• N-M
UserID Surname Name Born date
RSSMRO97D11C441R Rossi Mario 11/04/1987
VRDGRG98C17F205L Verdi Giorgio 21/08/1982
BNCLRA96A61B333C Bianchi Laura 09/02/1994
UserID Address City Country AID
RSSMRO97D11C441R Via Colombo Milano Italy 1
CHRGRG98C17F205L Piazza
Capitale
Venezia Italy 2
BNCLRA96A61B333C Via Roma Roma Italy 3
1
1UserID Book Title BID
RSSMRO97D11C441R Moby Dick 19229
RSSMRO97D11C441R The Hitchhiker's Guide to the Galaxy 17742
RSSMRO97D11C441R 1984 99180
N
Same type
Same information
Joins
1 – 1
• One element in A is connected to one element in B, and vice versa
Primary Key
A1
A2
A3
A4
A5
Foreign Key
B1
B2
B3
B4
B5
Primary Key
A1
A2
A3
A4
A5
Foreign Key
B1
B2
B3
B4
B5
Joins
1 – N
• One element in A is connected to many elements in B
• There is no viceversa
Primary Key
A1
A2
A3
A4
A5
Foreign Key
B1
B2
B3
B4
B5
B6
B7
Primary Key
A1
A1
A2
A3
A3
A3
A3
A5
Foreign Key
B1
B2
B3
B4
B5
B6
SQL?
SQL (Structured Query Language) is a standard language for
storing, manipulating and retrieving data in databases.
It is composed by:
• DDL - Data Definition Language (Create, Drop)
• DML - Data Manipulation Language (Insert, Update, Delete)
• DQL - Data Query Language (Select)
• DCL - Data Control Language
View data in a database
Query allows to:
• View data
• Filter and create a data-subset
• Create joins
Basic structure
Query
Select … <field list>
From … <table list>
Where … <conditions / filters>
Order by … <field list>
Group by … <field list>
Basic structure
Select• field list
• * all fields
• functions min, max, first, last … (must be useed with group by)
Operators:• Arithmetic + ; - ; / ; *
• Comparisons > ; < ; >=; <=; =; <>;
between … and;
IN; NOT IN; EXISTS; NOT EXISTS; LIKE; IS; IS NOT
• Logic AND, OR, NOT
Query
Select … <field list>
From … <table list>
Where … <conditions / filters>
Examples:
• All information about Closed farms
• Code and owner of Farms with backyard
• All information of active Farms with turkeys that has more than 30000 animals;
• Total number of animals per species
Query data example
code species production_type backyard nanimals owner address date_starting date_ending
001RO134 CHICKENS BROILERS YES 200 Paul Star Via Galli, 7 01/04/2000
045PD145 TURKEYS MEAT TYPE NO 50000 La Faraona Via Roma, 1 01/07/2007
066VE222 TURKEYS MEAT TYPE NO 0 Little Tony Via Bianca, 43 01/01/2006 01/01/2018
022VE201 CHICKENS YES 300000 KFC Via Bella,100 13/05/2006
FARMS
All information about Closed farms
Query data example
Select *
From farms
Where date_ending is not null
code species production_type backyard nanimals owner address date_starting date_ending
066VE222 TURKEYS MEAT TYPE NO 0 Little Tony Via Bianca, 43 01/01/2006 01/01/2018
Code and owner of Farms with backyard
Query data example
Select code, owner
From farms
Where backyard = ‘yes’
code owner
001RO134 Paul Star
022VE201 KFC
All information of Active Farms with turkeys that has more than 30000 animals
Query data example
code species production_type backyard nanimals owner address date_starting date_ending
045PD145 TURKEYS MEAT TYPE NO 50000 La Faraona Via Roma, 1 01/07/2007
Select *
From farms
Where date_end is null
and species = ‘turkeys’
and nanimals > 30000
Total number of animals per species
Query data example
Select species, sum(nanimals) as totnumber
From farms
group by species
species totnumber
TURKEYS 50000
CHICKENS 300200
Shapefiles and Geodatabases
Shapefile
.dbf.shp
Different files
• dbf Attributes (database)
• prj Projection and coordinate system
• shp Geometry
• shx spatial indexes
.shx
Shapefiles and Geodatabases
Personal GeoDatabase
Single file with different tables
Microsoft Access SQLite
How to make RDBMS Spatial
+
RDBMS
Spatial componentAdd to the RDBMS functions and dataTypes to
“understand” and Manage Spatial Data.
A software program for data management;
=
SPATIAL
RDBMS and Geo Database
Geo Database
Farm IDGeo ID Spatial data
In a Spatial RDBMS it is possible to create a database with geographical data
Database
PERSONAL
CON’S
Single user
Limited number of data
Not Web-oriented
PRO’S
Free/Low cost
Graphic interface
PRO’S
Multiusers
Large number of data
Web-oriented
Security
CON’S
Expensive
Advanced Users
ENTERPRISE ORACLE
Postgre SQL
Microsoft Access
SQLite