Transcript GeoARM: an Interoperable Framework to Improve Geographic
Spatial Data and Geographic/Spatial Databases
Vania Bogorny www.inf.ufsc.br/~vania [email protected]
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 2
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
3
What is Spatial/Geographic data?
• 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; 4
How are spatial data represented?
• Points, Lines, Polygons, and complex geometries.
5
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 6
Spatial Representation: field
Irregular points (e.g. temperature) Regular Points Isoline (e.g. relief) Adjacent polygons (e.g. soil) Grid célula Triangual Network(e.g. ) 7
Example: Geographic Data and Geographic Database
Street Gid
1 2
Name
Ijui Lavras
Shape
Multiline [(x1,y1),(x2,y2),..] Multiline [(x1,y1),(x2,y2),..]
WaterResource Gid
1
Name
Jacui 2 3 Guaiba Uruguai
Shape
Multiline [(x1,y1),(x2,y2),..] Multiline [(x1,y1),(x2,y2),..] Multiline [(x1,y1),(x2,y2),..]
GasStation Gid Name VolDiesel VolGas Shape
1 BR 2 IPF 20000 85000 Point[(x1,y1)] 30000 95000 Point[(x1,y1)] 3 Esso 25000 120000 Point[(x1,y1)] 8
Example of geographic data Districts are represented as green polygons Slums are represenetd as yellow polygons Water bodies are represented as blue lines 9
Example of geographic data Districts, Squares and Trees 10
Example of geographic data Districts and Slums 11
Example of geographic data Districts and Hospitals 12
Overlay of Geographic Data Combination of some previous data 13
Maps as Layers
14
Spatial Relationships
• Main characteristic which differs spatial data from non-spatial data 15
Viaduct intersects road OR Road crosses viaduct District contains soccer field Disjunção
16
Crosses relationship
17
Spatial Relationships
What is the average distance between industrial repositories and water collecting points? 18
Spatial Relationships
How distant are water bodies (blue line) from industrial repository (pink dot) ?
19
Spatial Relationships
Which is the closest put to my house?
20
Main Spatial Relationships Topological B
touches
Order Distance
north
A 21
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 22
Examples of Spatial Operations Original Polygons Union Intersection 23
Rivers Examples of Spatial Operations Buffered Rivers 24
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 25
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 S WHERE area(s.the_geom) > 300 • Standards • OGIS is a standard for spatial data types and operators 26
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' Rainy Rainy name | cntry_name ---------------------------------+-------------- Pembina | United States Pembina | Canada | United States | Canada Souris Souris | United States | Canada Red River of the North | United States Red River of the North | Canada (8 rows)
27
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) 28
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 29 1) Escreva uma consulta que conte as pracas do bairro Botafogo 2) Escreva uma consulta que retorne as favelas do bairro Tijuca mostre o resultado no mapa 3) Escreva uma consulta que retorne os rios que cruzam o bairro Barra da Tijuca 4) Escreva uma consulta que retorne as Favelas que contem escolas, mostrando-as no mapa 30 (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 ) 3. 4. 5. 6. 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. 2. 7. Download suitable spatial datasets in shapefile format from ESRI's web-site : Convert shapefiles into sql files shp2pgsql [Exercicios
Exercise I