20
Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring 2013

Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

Embed Size (px)

Citation preview

Page 1: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

Introduction to Spatial Databases

Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department

Advanced Database Applications

Kocaeli UniversitySpring 2013

Page 2: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

What is a SDBMS ?

A SDBMS is a software module thatcan work with an underlying DBMSsupports spatial data models, spatial abstract data types (ADTs) and a query language from which these ADTs are callablesupports spatial indexing, efficient algorithms for processing spatial operations, and domain specific rules for query optimization

Page 3: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

Why Spatial Databases

GIS is the principle technology motivating interest in SDBMS. GIS is not the only area using SDBMSMany important application domains have spatial data and queries. Some Examples

Insurance Risk Manager: Which homes are most likely to be affected in the next great flood on the Brisbane river?Molecular Biologist: Is the topology of the amino acid biosynthesis gene in the genome found in any other sequence feature map in the database ?Medical Doctor: Based on this patient's MRI, have we treated somebody with a similar condition ?

Page 4: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

What is a Spatial Database?

A spatial database is a database system (DBMS) that is optimized to store and query basic spatial objects :

Point: a house, a moving car, a cityLine/Polyline: river, cable, roadPolygon: a county, forest, lake, cityAnd some more – see the nest slide

Page 5: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

Spatial Object Types in OGIS Data Model

Each rectangle shows a distinct spatial object type2-dim geometry

Collection of islandsCollection of

oil wells

Page 6: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

Spatial Data Examples

Examples of non-spatial dataNames, phone numbers, email addresses of people

Examples of Spatial dataNASA satellites imagery - terabytes of data per dayWeather and Climate DataRivers, Farms, ecological impactMedical Imaging

Exercise: Identify spatial and non-spatial data items inA phone book A cookbook with recipes

Page 7: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

Spatial and Non-Spatial Queries

Non-spatial queries:List the names of all bookstore with more than ten thousand titles.List the names of ten customers, in terms of sales, in the year 2001Where is Building 78?Which courses are meeting in GP Building?

Spatial Queries:List the names of all bookstores with ten miles of MinneapolisList all customers who live in Tennessee and its adjoining statesWhich buildings are adjacent to the lake?Which building is adjacent to a lake?

Page 8: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

Spatial Query Example -1

• Spatial query language• Spatial data types, e.g. point, linestring, polygon, …• Spatial operations, e.g. overlap, distance, nearest neighbor, …• Callable from a query language (e.g. SQL3) of underlying DBMS

SELECT S.nameFROM Senator SWHERE S.district.Area() > 300

• Standards• SQL3 (a.k.a. SQL 1999) is a standard for query languages• OGC is a standard for spatial data types and operators• Both standards enjoy wide support in industry

Page 9: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

Spatial Query Example -2

“Display all countries that border Turkiye”. This query can be implemented using the following SQL command:

select c1.name as name,transform(c1.the_geom,4326) as the_geom

from county c1,county c2

Where touches(c1.the_geom,c2.the_geom)

And c2.name=‘Turkiye';

Page 10: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

Result 2

Page 11: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

Spatial Query Example -3

Query: For all the rivers listed in the River table, find the counties through which they pass.

SELECT r.name, r.nameFROM river AS r, county AS cWHERE crosses(r.the_geom,c.the_geom)=True

The spatial predicate “Cross” is used to join River and Country tables

To view this we would add asbinary(R.the_geom,C.the_geom)

Page 12: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

A spatial join associate two tables based on a spatial relationship, rather than an attribute relationship. For example the query:

Summarize the provincial election results by municipality.

SELECT m.name, sum(v.ndp) AS ndp, sum(v.lib) AS liberal, sum(v.gp) AS green, sum(v.upbc) AS unity, sum(v.vtotal) AS total FROM bc_voting_areas v, bc_municipality m, WHERE intersects(v.the_geom, m.the_geom) GROUP BY m.name ORDER BY m.name;

Spatial Query Example -4

Page 13: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

Spatial Query Example -5

• Spatial join exampleSELECT S.name FROM Senator S, Business B

WHERE S.district.Area() > 300 AND Within(B.location, S.district)• Non-Spatial Join example

SELECT S.name FROM Senator S, Business BWHERE S.soc-sec = B.soc-sec AND S.gender = ‘Female’

Page 14: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

SDBMS vs GIS ?

GIS is a software to visualize and analyze spatial data using spatial analysis functions such as

Search Thematic search, search by region, (re-)classificationLocation analysis Buffer, corridor, overlayTerrain analysis Slope/aspect, catchment, drainage networkFlow analysis Connectivity, shortest pathDistribution Change detection, proximity, nearest neighborSpatial analysis/Statistics Pattern, centrality, autocorrelation, indices of similarity, topology: hole descriptionMeasurements Distance, perimeter, shape, adjacency, direction

GIS uses SDBMS to store, search, query, share large spatial data sets

Page 15: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

SDBMS vs GIS ?

SDBMS focuses onEfficient storage, querying, sharing of large spatial datasetsProvides simpler set based query operations Example operations: search by region, overlay, nearest neighbor, distance, adjacency, perimeter etc.Uses spatial indices and query optimization to speedup queries over large spatial datasets.

SDBMS may be used by applications other than GIS

Astronomy, Genomics, Multimedia information systems, …

Page 16: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

Components of a SDBMS

Recall: a SDBMS is a software module thatcan work with an underlying DBMSsupports spatial data models, spatial ADTs and a query language from which these ADTs are callablesupports spatial indexing, algorithms for processing spatial operations, and domain specific rules for query optimization

Components includespatial data model, query language, query processing, file organization and indices, query optimization, etc.

Page 17: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

Three Layer Architecture

Page 18: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

SDBMS Example

Consider a spatial dataset with:County boundary (dashed white line) Census block - name, area, population, boundary (dark line)Water bodies (dark polygons)Satellite Imagery (gray scale pixels)

Storage in a SDBMS table: create table census_blocks (

name string, area float, population number, boundary polyline);

Page 19: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

Modeling Spatial Data in Traditional DBMS

• A row in the table census_blocks• Question: Is Polyline datatype supported in DBMS?

Page 20: Introduction to Spatial Databases Assist. Prof. Dr. Ahmet Sayar Computer Engineering Department Advanced Database Applications Kocaeli University Spring

Mapping “census_table” into a Relational Database