spatial data and geographic/spatial databases

32
Spatial Data and Geographic/Spatial Databases Vania Bogorny www.inf.ufsc.br/~vania [email protected]

Upload: faxon

Post on 20-Mar-2016

64 views

Category:

Documents


3 download

DESCRIPTION

Spatial Data and Geographic/Spatial Databases. Vania Bogorny www.inf.ufsc.br/~vania vania @ inf.ufsc.br. What is a Spatial/Geographic Database?. Database that: Stores spatial objects Provides operations to manipulate spatial objects - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Spatial Data and Geographic/Spatial Databases

Spatial Data and Geographic/Spatial Databases

Vania Bogorny

www.inf.ufsc.br/[email protected]

Page 2: Spatial Data and Geographic/Spatial Databases

2

What is a Spatial/Geographic Database?

Database that:• Stores spatial objects• Provides operations to manipulate spatial

objects• Manipulates spatial objects just like other

objects in the database

Page 3: Spatial Data and Geographic/Spatial Databases

3

What is Spatial/Geographic data?

• Data which describes a location or a shape

e.g. House, Hospital, Road, River, Forests, Parks, Soil

• Is something that describes objects or phenomena that happen on the Earth and that have associated a geographic position

Page 4: Spatial Data and Geographic/Spatial Databases

4

• Three main characteristics describe a geographic object: Non-spatial attributes (what): describe either quantitatively or

qualitatively a geographic entity. This data may be treated by non-spatial databases;

Spatial attribute (where): refers to the location and the representation of the geographic object, considering geometry and coordinate system. This aspect requires a specific data type not available in conventional DBMS;

Spatial relationships (how): neighbourhood relationships (e.g. topology, distance). Requires special operations that are not available in conventional DBMS;

What is Spatial/Geographic data?

Page 5: Spatial Data and Geographic/Spatial Databases

5

How are spatial data represented?

• Points, Lines, Polygons, and complex geometries.

Page 6: Spatial Data and Geographic/Spatial Databases

6

Spatial Representation: object

0-dimensional representation: point E.g.: school, hospital,

Uni-dimensional representation: line E.g.: river, road

Bi-dimensional representation: polygon E.g.: state, city

Tri-dimensional representation: surface E.g.:building

Page 7: Spatial Data and Geographic/Spatial Databases

7

Spatial Representation: field

célula

Irregular points (e.g. temperature)

Adjacent polygons (e.g. soil)

Regular Points

Grid

Triangual Network(e.g. )

Isoline (e.g. relief)

Page 8: Spatial Data and Geographic/Spatial Databases

8

Example: Geographic Data and Geographic Database

StreetGid Name Shape1 Ijui Multiline [(x1,y1),(x2,y2),..]2 Lavras Multiline [(x1,y1),(x2,y2),..]

WaterResourceGid Name Shape1 Jacui Multiline [(x1,y1),(x2,y2),..]2 Guaiba Multiline [(x1,y1),(x2,y2),..]3 Uruguai Multiline [(x1,y1),(x2,y2),..]

GasStationGid Name VolDiesel VolGas Shape 1 BR 20000 85000 Point[(x1,y1)]2 IPF 30000 95000 Point[(x1,y1)]3 Esso 25000 120000 Point[(x1,y1)]

Page 9: Spatial Data and Geographic/Spatial Databases

9

Districts are represented as green polygonsSlums are represenetd as yellow polygonsWater bodies are represented as blue lines

Example of geographic data

Page 10: Spatial Data and Geographic/Spatial Databases

10

Districts, Squares and Trees

Example of geographic data

Page 11: Spatial Data and Geographic/Spatial Databases

11

Districts and Slums

Example of geographic data

Page 12: Spatial Data and Geographic/Spatial Databases

12

Districts and Hospitals

Example of geographic data

Page 13: Spatial Data and Geographic/Spatial Databases

13

Combination of some previous data

Overlay of Geographic Data

Page 14: Spatial Data and Geographic/Spatial Databases

14

Maps as Layers

Page 15: Spatial Data and Geographic/Spatial Databases

15

Spatial Relationships

• Main characteristic which differs spatial data from non-spatial data

Page 16: Spatial Data and Geographic/Spatial Databases

16

District contains soccer field

Viaduct intersects road

OR

Road crosses viaduct

Disjunção

Page 17: Spatial Data and Geographic/Spatial Databases

Crosses relationship

17

Page 18: Spatial Data and Geographic/Spatial Databases

18

Spatial Relationships

What is the average distance between industrial repositories and water collecting points?

Page 19: Spatial Data and Geographic/Spatial Databases

19

Spatial Relationships

How distant are water bodies (blue line) from industrial repository

(pink dot) ?

Page 20: Spatial Data and Geographic/Spatial Databases

20

Spatial Relationships

Which is the closest put to my house?

Page 21: Spatial Data and Geographic/Spatial Databases

21

Main Spatial Relationships

B

C

A

B north A

C southeast A

B

C

A

B north A

C southeast A

OrderDistance CB

dCB

d

BA

touches

A B

overlaps

B

inside

A

contains BA

crosses

A Bequals

A B

BA A B

overlaps

inside

A

contains

A B

disjoint

A B

disjoint

BAcrosses

A Bequals

A BTopological

Page 22: Spatial Data and Geographic/Spatial Databases

22

Advantages of Spatial Databases

Spatial querying using SQL– use simple SQL expressions to determine spatial

relationships• distance• order• topology

– use simple SQL expressions to perform spatial operations• area• length• intersection• union• buffer

Page 23: Spatial Data and Geographic/Spatial Databases

23

Original Polygons

Union Intersection

Examples of Spatial Operations

Page 24: Spatial Data and Geographic/Spatial Databases

24

Rivers

Buffered Rivers

Examples of Spatial Operations

Page 25: Spatial Data and Geographic/Spatial Databases

25

Spatial Databases

• ESRI ArcSDE (on top of several different DBs)• Oracle Spatial• IBM DB2 Spatial Extender• Informix Spatial DataBlade• MS SQL Server (with ESRI SDE)• Geomedia on MS Access• PostGIS / PostgreSQL

Page 26: Spatial Data and Geographic/Spatial Databases

26

Spatial Query Language• Spatial query language

• Spatial data types, e.g. point, linestring, polygon, …• Spatial operations, e.g. overlap, distance, nearest neighbor, …• SELECT S.name

FROM States SWHERE area(s.the_geom) > 300

• Standards• OGIS is a standard for spatial data types and operators

Page 27: Spatial Data and Geographic/Spatial Databases

27

Spatial Query Example

Q1: For all rivers in the relation “River”, which countries do they pass?

select r.name,c.cntry_name from river r, country c where crosses (r.the_geom,c.the_geom) = 'True'

          name          |  cntry_name   ---------------------------------+--------------- Pembina             | United States Pembina             | Canada Rainy                  | United States Rainy                  | Canada Souris                 | United States Souris                  | Canada Red River of the North | United States Red River of the North | Canada(8 rows)

Page 28: Spatial Data and Geographic/Spatial Databases

28

Spatial Query Example

Q2: Find the names of all countries which are neighbors of the United States (USA)

select c1.cntry_name as USA_Neighbors from country c1, country c2 where touches(c1.the_geom,c2.the_geom)='True' and 

c2.cntry_name='United States';

 usa_neighbors --------------- Canada(1 row)

Page 29: Spatial Data and Geographic/Spatial Databases

Como criar um BDG no PostgreSQL

•1) createdb -E SQL_ASCII -T template_postgis -Uusername nomeDaBase ou criar via PGADMIN•2) importação dos dados geográficos:

•Transformação dos arquivos shape em .sql (Fazer isso para todos os arquivos .shp)

•a) shp2pgsql -I arquivo.shp nomeDaTabela > tabela.sql

•Importação para o banco de dados:

•b) psql -Uusuario nomeDaBase <tabela.sql

29

Page 30: Spatial Data and Geographic/Spatial Databases

Exercicios

1) Escreva uma consulta que conte as pracas do bairro Botafogo2) Escreva uma consulta que retorne as favelas do bairro Tijuca mostre o resultado no mapa3) Escreva uma consulta que retorne os rios que cruzam o bairro Barra da Tijuca4) Escreva uma consulta que retorne as Favelas que contem escolas, mostrando-as no mapa

30

Page 31: Spatial Data and Geographic/Spatial Databases

31

Exercise I (http://www.spatial.cs.umn.edu/Book/labs/vania/spatialQueries.html)

Spatial Queries using Postgres/Postgis This exercise demonstrates spatial queries from chapter 3 in Prof. Shekhar's book. using Postgresql/PostGIS SDBMS and a spatial dataset

downloaded from ESRI's web-site. It provides a multi-step process to download spatial datasets, convert those to sql, load into postgres/postgis SDBMS, and run queries. Note that one may skip the first two steps for a quick start using the following sql files: Cities (city.sql, city.gif) Countries(country.sql, country.sql) Rivers (river.sql, river.gif) Water (water.sql, water.gif) Streets (street.sql. street.gif) Each sample .sql file is the converted shapefile ready to import into PostGIS using step 3 of the process. The .gif file is the graphical representation

of the shapefiles, created in ArcExplorer, which is a free software for geographic data visualization. Complete Multi-step Process 1. Download suitable spatial datasets in shapefile format from ESRI's web-site : http://www.esri.com/data/download/basemap/index.html 2. Convert shapefiles into sql files shp2pgsql [<options>] <shapefile> [<schema>.]<table> > sqlfilename.sql Example: shp2pgsql

-c  street.shp  street_table my_db > street.sql 3. Import the sql files into PostGIS psql [options]... [dbname [username]] Example: psql -d my_db -f country.sql 4. After import the data login into Postgresql pgsql my_db Example: (sample session output) • List all tables. Example: sample session. • You may look at the schema and contents of various table using other postgres commands. Example Query: List all cities and the

country they belong to in the CITY table Example Postgis expression and output: script 1. Try spatial queries. Following are example of spatial queries from chapter 3 of the Spatial Database book.

2. Query: List the names of the capital cities in the CITY table (script)

3. Query: Find the names of all countries which are neighbors of the United States (USA) in the Country Table (script) 4. Query: For all the rivers listed in the River table, find the countries through which they pass (script)

5. Query: Which city listed in the City table is closest to each river listed in the River table? (script 6. Query: List the name, population, and area of each country listed in the Country table (script)

7. Query: List the length of the rivers in each of the countries they pass through (script)

2. One may consider taking the results of a query back to Arc Explorer for visualization using pg2shp.exe converter available with postgis software.

Page 32: Spatial Data and Geographic/Spatial Databases

32

References• GUTING, R. H. An Introduction to Spatial Database Systems. The International

Journal on Very Large Data Bases, [S.l.], v.3, n.4, p. 357 – 399, Oct. 1994.

• RIGAUX, P.; SCHOLL, M.; VOISARD, A. Spatial Databases: With Application to GIS. San Francisco: Morgan Kaufmann, 2002.

• SHEKHAR, S., CHAWLA, S. Spatial databases: a tour. Upper Saddle River, NJ: Prentice Hall, 2003.

• OPEN GIS CONSORTIUM. Topic 5, the OpenGIS abstract specification–OpenGIS features–Version 4. 1999a. Available at <http://www.OpenGIS.org/techno/specs.htm>.

• OPEN GIS CONSORTIUM. OpenGIS simple features specification for SQL. 1999b. Available at <http://www.opengeospatial.org/docs/99-054.pdf>.

• OPEN GIS CONSORTIUM. Feature Geometry. 2001. Available at <http://www.opengeospatial.org/specs>.