Spatial Databases

Document Sample
Spatial Databases Powered By Docstoc
					Spatial Databases

   Reading: None
 In this lecture you will learn
• the need for spatial databases
• some of the special issues regarding
  spatial data
• some of the issues concerning spatial
  database query languages
• some of the techniques used in spatial
  databases

   Dept. of Computing Science, University of Aberdeen   2
Applications of Spatial Databases
• Spatial databases are used to store &
  manipulate data concerning:
  – Geography (2D) - maps, socio-economic, military
  – Engineering (2D/3D) - architectural drawings, CAD
  – Geophysics (3D) - geological strata, oil fields,
    mining
• Here, we will focus on Geographic
  Information Systems (GIS).
• These usually:
  – combine 2D spatial & textual data
  – have a graphical front-end
  – have an extended query language
   Dept. of Computing Science, University of Aberdeen   3
              Special Issues
          With Spatial Databases
• Spatial objects:
  – have geometric shape, size, location (i.e.
    coordinate)
  – might change with time - e.g. land-use, urban areas
• Issues:
  – Representation - how to represent e.g. a lake or a
    hill?
  – Query Languages - how to specify spatial queries?
      • e.g. find all lakes near mountains (a spatial join)
  – Indexing - how to accelerate spatial access
    methods
  – Data Collection - digitise satellite images, paper
    maps
   Dept. of Computing Science, University of Aberdeen         4
               Conceptual Modelling
               for Spatial Databases
• Conceptual modelling for spatial databases is similar to E-R
  modelling:

                      1..1      Has            0..*
       Country                                              Lake



• But there are some important differences:

    Relational                         Spatial
    Simple data types                  Geometric objects - lines, polygons

    Entities                           Themes - lakes, rivers, countries, cities
    Results Tables                     Maps - e.g. map of Scottish lakes (!)

     Dept. of Computing Science, University of Aberdeen                            5
                Logical Modelling - Using
                    Relational Model
Country                                              Boundary
name       capital       population   boundaryId     boundaryId         contourId

Germany    Berlin        80           B1             B1                 C1

                                                     B2                 C2
France     Paris         60           B2
                                                     B2                 C3

…          …             …            …              …                  …


    Contour                                            Point
                                                      pointId     x     y
    contourId        point_num        pointId
                                                      P1          452   1000
    C1               2                P1
    C1               1                P2              P2          365   875
    C1               3                P3              P3          386   985
    …                …                …
                                                      …           …     …

          Dept. of Computing Science, University of Aberdeen                        6
                            Using SQL
• Select the contours of France
       SELECT B.contourId,x,y
       FROM Country C, Boundary B, Contour CO, Point P
       WHERE C.name = ‘France’
       AND C.boundaryId = B.boundaryId
       AND B.contourId = CO.contourId
       AND CO.pointId = P.pointId
       ORDER BY B.contourId,CO.point_num;
• Disadvantages of this approach:
   – Writing this query requires the knowledge of the spatial
     object’s structure – Boundary is made up of contours, contours
     have ordered points etc.
   – Spatial queries (discussed later) cannot be expressed
   – Several relations (tables) to represent spatial information
    Dept. of Computing Science, University of Aberdeen           7
Abstract Data Types for Spatial
            Data
• Clearly, we need some Abstract Data Types
  (ADTs) and associated method functions for
  spatial data, e.g.:
  – Point - Coordinates
  – Line - Coordinates, Length
  – Polygon - Coordinates, Perimeter, Area
• Higher-order ADTs can be built from these
  basic types, e.g.:
  – Arc - a connected line list (start/end pts special)
  – Region - a set of non-overlapping polygons
   Dept. of Computing Science, University of Aberdeen     8
 Geometric Method Functions
• Most GISs provide high-level method
  functions for geometric objects, e.g.:
  –    Boolean  Inside(Point, Polygon)
  –    Boolean  Crosses(Line, Polygon)
  –    Boolean  Overlaps(Region, Region)
  –    Region  Union(Region, Region)
  –    Region  Intersect(Region, Region)
  –    Region  Clip(Region, Polygon)
• We will not be concerned with how these are
  implemented!
      Dept. of Computing Science, University of Aberdeen   9
       Types of Spatial Query
• What kinds of spatial query should spatial
  databases support ? Here are a few:




• Point - select all objects whose geometry contains a
given point
• Window - select all objects within a given rectangle
• Join - select all pairs of objects that satisfy a given
   relationship - overlap, containment, adjacency...
   Dept. of Computing Science, University of Aberdeen   10
          Desirable Features
       for GIS Query Languages
• What features should a spatial database
  query language have ?
  – Extensible - build complex objects from simpler
    ADTs
  – Programmable - supports user-defined functions
  – Reusable Methods - Weak typing (ADO) or object
    inheritance (Java)
  – Easy to learn - ?
  – Looks like SQL - ??
• Which of the above do SQL satisfy ?
   Dept. of Computing Science, University of Aberdeen   11
Existing Spatial Query Languages
• Different groups have attempted to extend
  SQL to handle geometric objects:
  – OQL - Object Query Language (Object Database
    Management Group)
  – SDO - Spatial Database Option (Oracle Corp.)
  – PostgreSQL - open source
• Example: find all lakes (!) in Scotland (in the
  style of OQL):
  SELECT * FROM L in Lakes WHERE EXISTS
  (intersect(L.region, (SELECT C.polygon FROM
  C in Countries WHERE C.name = 'Scotland')));
   Dept. of Computing Science, University of Aberdeen   12
 An Idealised Query Language
• Lets invent a new query language (based on functional
  programming):

   map = null;
   b = border(Countries, "Scotland");
   for each l in Lakes() {
      s = intersect(l, b);
      if (exists(s)) {
        map = union(map, s);
      }
   }
• Which do you prefer - SQL or functional programming?
• Real functional query languages exist, but mostly as research
  tools...



     Dept. of Computing Science, University of Aberdeen           13
                    Spatial Indexes
• Spatial DBs use a variety of techniques to accelerate
  spatial queries:
   – Bounding Boxes - simplify geometry tests: e.g. overlap
   – Grid Indexes - partition space
   – R-Trees - partition objects
(R-Trees are like B-Tree with rectangular objects)
• Ideally, objects close together in space should be:
   – Close together in index; preferably on same index page
• Fundamental idea for indexing is to use
  approximations



    Dept. of Computing Science, University of Aberdeen        14
 Bounding Box Spatial Indexes
• Rectangular boxes allow fast geometric filters to be
  applied - e.g. overlap
• Then, evaluate objects that pass filter using actual
  geometries




  • However, every query requires a scan of the
  entire bounding box index
    Dept. of Computing Science, University of Aberdeen   15
Grid Indexes - Partitioning Space
• Divide space into a grid (the index):




• Simple, fast - provided grid fits into memory
• Works well if objects fit into grid cells...
   Dept. of Computing Science, University of Aberdeen   16
                                 Summary
• Spatial DBs are useful for a wide range of
  applications...
• Special issues:
    – I/O - data collection (input) graphical displays (output)
    – need for abstract geometric data types and functions
    – need for special indexing techniques (R-trees)
•  should existing SQL systems be adapted for
  geometric objects ?
• Overall:
    – spatial DBs aren't (shouldn't be) so different from
      conventional DBs



     Dept. of Computing Science, University of Aberdeen           17