0% found this document useful (0 votes)
79 views89 pages

Spatial Databases: Esteban ZIM Anyi

This document provides an overview of spatial databases and geographic information systems (GIS). It discusses key topics like georeferencing systems, conceptual and logical modeling for spatial databases, SQL extensions for spatial data, representative systems, and applications of spatial databases. Spatial databases allow storing and querying spatial objects like points, lines, and polygons, and are used in fields like GIS, computer-aided design, facilities management, and more.

Uploaded by

RaViji Yogesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views89 pages

Spatial Databases: Esteban ZIM Anyi

This document provides an overview of spatial databases and geographic information systems (GIS). It discusses key topics like georeferencing systems, conceptual and logical modeling for spatial databases, SQL extensions for spatial data, representative systems, and applications of spatial databases. Spatial databases allow storing and querying spatial objects like points, lines, and polygons, and are used in fields like GIS, computer-aided design, facilities management, and more.

Uploaded by

RaViji Yogesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 89

Spatial Databases

Esteban ZIMÁNYI
Department of Computer & Decision Engineering (CoDE)
Université Libre de Bruxelles
[email protected]

Info-H-415 Advanced Databases


Academic Year 2012-2013

Spatial Databases: Topics


y Introduction
_ Georeferences and Coordinate Systems

_ Conceptual Modeling for Spatial Databases

_ Logical Modeling for Spatial Databases

_ SQL/MM

_ Representative Systems

_ Summary

2
Foreword

_ In 1854 in Soho (London) doctor John


Snow was able to identify the water
point at the origin of the cholera epi-
demy by correlating the location of
the water points and the location of
the victims

Spatial Databases
_ A database that needs to store and query spatial objects, e.g.
• Point: a house, a monument
• Line: a road segment, a road network
• Polygon: a county, a voting area

_ Types of spatial data

GIS Data CAD Data CAM Data

4
Spatial Database Management Systems
_ A Database Management System that manages data existing in some space
_ 2D or 2.5D
• Integrated circuits: VLSI design
• Geographic space (surface of the Earth): GIS, urban planning
_ 2.5 D: Elevation
_ 3D
• Medicine: Brain models
• Biological research: Molecule structures
• Architecture: CAD
• Ground models: Geology
_ Supporting technology able to manage large collections of geometric objects
_ Major commercial and open-source DBMSs provide spatial support

Why Spatial Databases?


_ Queries to databases are posed in high level declarative manner (usually using SQL)

_ SQL is popular in the commercial database world

_ Standard SQL operates on relatively simple data types

_ Additional spatial data types and operations can be defined in spatial database

_ SQL was extended to support spatial data types and operations, e.g., OGC Simple Features for SQL

_ A DBMS is a way of storing information in a manner that


• Enforces consistency
• Facilitates access
• Allows users to relate data from multiple tables together

6
Application Areas
_ Street network-based
• Vehicle routing and scheduling (cars, planes, trains)
• Location analysis, ...
_ Natural resource-based
• Management of areas: agricultural lands, forests, recreation resources, wildlife habitat analysis,
migration routes planning...
• Environmental impact analysis
• Toxic facility siting
• Groundwater modeling, ...
_ Land parcel-based
• Zoning, subdivision plan review
• Environmental impact statements
• Water quality management
• Facility management: electricity, gaz, clean water, used water, network

Interaction with End Users


_ Display data (e.g., maps) on the screen

_ Access other data by clicking on it (hypermaps)

_ Address queries

_ Perform operations

8
Example of Queries
_ On a subway map of Brussels, what is the shortest way from here to the Grand Place?
⇒ shortest path algorithm

_ Overlay the land use map with the map of districts in Belgium

_ Display today’s weather forecast in the Brussels Region

_ Given the map of a neighborhood, find the best spot for opening a drugstore (based on a given set of
optimality criteria) ⇒ allocation problem

Geographic Information Systems


_ A system designed to capture, store, manipulate, analyze, manage, and present geographically-referenced
data as well as non-spatial data

_ Connection between system elements is geography, e.g., location, proximity, spatial distribution

_ Common purpose: decision making for managing use of land, resources, ocean data, transportation,
geomarketing, urban planning, etc.

_ Many commercial and open source systems, but limited temporal support

10
GIS as a Set of Subsystems
_ Data processing
• Data acquisition (from maps, images): input, store

_ Data analysis
• Retrieval, analysis (answers to queries, complex statistical analyses)

_ Information use
• Users: Researchers, planners, managers
• Interaction needed between GIS group and users to plan analytical procedures and data structures

_ Management system
• Organizational role: separate unit in a resource management
• Agency offering spatial database and analysis services
• System manager, system operator, system analysts, digitizer operators

11

Contributing Disciplines and Technologies (1)


_ Convergence of technological fields and traditional disciplines

_ Geography: The study of the Earth

_ Cartography: Display of spatial information


• Computer cartography (digital, automated cartography): methods for digital representation, ma-
nipulation and visualization of cartographic features

_ Remote sensing: Techniques for image acquisition and processing (space images)

_ Photogrammetry: Aerial photos and techniques for accurate measurements

_ Geodesy: The study of the size and shape of the earth

_ Statistics: Statistical techniques for analysis + errors and uncertainty in GIS data

_ Operations Research: Optimizing techniques for decision making

_ Mathematics: (Computational) geometry and graph theory for analysis of spatial data

_ Civil Engineering: Transportation, urban engineering

12
Contributing Disciplines and Technologies (2)
_ Computer Science
• Computer Aided Design (CAD): Software, techniques for data input, display, representation, visu-
alization
• Computer graphics: Hardware, software for handling graphic objects
• Artificial Intelligence (AI): Emulate human intelligence and decision making (computer = “ex-
pert”).
• Database Management Systems (DBMS): Representing, handling large volumes of data (access,
updates)

13

GIS Architectures: Ad Hoc Systems

Application Programs

File Management System

Files

_ Not modular

_ Not reusable

_ Not extensible

_ Not friendly

_ Very efficient

14
GIS Architectures: Loosely Coupled Approach

Application Programs
Standard SQL
Relational Geometric
DBMS Processing

DB Files

_ Structured information and geometry stored at different places


• Relational DBMS for alphanumerical (non spatial) data
• Specific module for spatial data management

_ Modularity (use of a DBMS) BUT:


• Heterogeneous models! Difficult to model, integrate and use
• Partial loss of basic DBMS functionalities e.g., concurrency, optimization, recovery, querying

15

GIS Architectures: Integrated Approach

Application Programs
Standard SQL
+ ADT Spatial
DBMS

DB

_ “Extended relational” system

_ Modular

_ Extensible (add a new operation, a new type)

_ Reusable

_ Friendly (easy change, easy use)

16
Main Database Issues
_ Data modeling

_ (Spatial) query language

_ Query optimization

_ Spatial access methods define index structure to accelerate the retrieval of objects

_ Versioning

_ Data representation (raster/vector)

_ Graphical user interfaces (GUI)

_ Computational geometry for GIS

17

Spatial Databases: Topics


_ Introduction

y Georeferences and Coordinate Systems


_ Conceptual Modeling for Spatial Databases

_ Logical Modeling for Spatial Databases

_ SQL/MM

_ Representative Systems

_ Summary

18
Projected Coordinates Systems
_ Why focus on projections?
• Going from 3 to 2 dimensions for Earth representation always involves a projection
• Information on the projection is essential for applications analyzing spatial relationships
• Choice of the projection can influence the results

_ The Earth is a complex surface whose shape and dimensions can not be described with mathematical
formulas

_ Two main reference surfaces are used to approximate the shape of the Earth: the ellipsoid and the
Geoid

19

The Geoid

_ Reference model for the physical surface of the Earth

_ It is the equipotential surface of the Earth’s gravity field which best fits the global mean sea level and
extended through the continents

_ Used in geodesy, e.g., for measuring heights represented on maps

_ Not very practical to produce maps

_ Since the mathematical description of the geoid is unknown, it is impossible to identify mathematical
relationships for moving from the Earth to the map

20
Ellipsoid

_ A mathematically-defined surface that approximates the geoid


_ Flattening f = a−b
a : how much the symmetry axis is compressed relative to the equatorial radius
_ For the Earth, f is around 1/300: difference of the major and minor semi-axes of approx. 21 km
_ Ellipsoid used to measure locations, the latitude (φ) and longitude (λ), of points of interest
_ These locations on the ellipsoid are then projected onto a mapping plane
_ Different regions of the world use different reference ellipsoids that minimize the differences between
the geoid and the ellipsoid
_ For Belgium (since 2008) ellipsoid GRS80 (=WGS84) with a = 6,378,137 m. and f = 1/298.257222101

21

Difference between the EGM96 Geoide and the WGS84 Ellipsoid

_ The physical Earth has excursions of +8,000 m (Mount Everest) and -11,000 m (Mariana Trench)

_ The geoid’s total variation goes from -107m to +85 m compared to a perfect mathematical ellipsoid

22
Latitude and Longitude

_ Measures of the angles (in degrees) from the center of the Earth to a point on the Earth’s surface
_ Latitude measure angles in a North-South direction: the Equator is at an angle of 0
_ Longitude measures angles in an East-West direction: the Prime Meridian is at angle of 0
_ Prime Meridian: imaginary line running from the North to the South Pole through Greenwich, England
_ For example, the location of Brussels, Belgium is 50.8411◦ N, 4.3564◦ E
_ Longitude and latitude are not uniform units of measure
_ Only along the Equator the distance represented by one degree of longitude approximates the distance
represented by one degree of latitude

23

Map Projections

_ To produce a map, the curved reference surface of the Earth, approximated by an ellipsoid or a sphere,
is transformed into the flat plane of the map by means of a map projection
_ A point on the reference surface of the Earth with geographic coordinates (φ, λ) is transformed into
Cartesian (or map) coordinates (x, y) representing positions on the map plane
_ Each projection causes deformations
_ Map projections can be categorised in four ways: Class, Angle, Fit and Properties

24
Map Projections: Shape of Projection Surface

_ Shape of the projection surface, commonly either a flat plane, a cylinder or a cone
_ Cones and cylinders are not flat shapes, but they can be rolled flat without introducing additional
distortion
• Cylindrical: coordinates are projected onto a rolled cylinder
• Conical: coordinates are projected onto a rolled cone
• Azimuthal: coordinates are projected directly onto a flat planar surface
_ Azimuthal projections work best for circular areas (e.g., the poles)
_ Cylindrical projections work best for rectangular areas (e.g., world maps)
_ Conical projections work best for triangle shaped areas (e.g., continents)

25

Map Projections: Angle

_ This refers to the alignment of the projection surface, measured as the angle between the main axis of
the earth and the main symmetry axis of the projection surface.
• Normal: the two axes are parallel
• Transverse: the two axes are perpendicular
• Oblique: the two axes are at some other angle

_ Ideally the plane of projection is aligned as closely as possible with the main axis of the area to be
mapped. This helps to minimise distortion and scale error.

26
Map Projections: Fit

_ A measure of how closely the projection surface fits the surface of the Earth
• Tangent: the projection surface touches the surface of the Earth
• Secant: the projection surface slices through the Earth
_ Distortion occurs wherever the projection surface is not touching or intersecting the surface of the
Earth
_ Secant projections usually reduce scale error because the two surfaces intersect in more places and the
overall fit tends to be closer
_ A globe is the only way to represent the entire Earth without any significant scale error

27

Map Projections: Geometric Deformations


_ What is preserved
• Conformal: preserve shapes and angles
• Equal Area (or equivalent): preserve areas in correct relative size (shapes not preserved)
• Equidistant: preserve distance (this is only possible at certain locations or in certain directions)
• True-direction (or Azimuthal): preserves accurate directions (e.g., angles preserved, but length
of lines is not)

_ It is impossible to construct a map that is both equal-area and conformal

_ Conformal map projections are recommended for navigational charts and topographic maps

_ Equal area projections are generally best for thematic mapping

_ Equidistant map projections should be used when measuring distances from a point: air routes, radio
propagation strength, radiation dispersal

28
Conformal Cylindrical Projection: Mercator Projection

29

Cylindrical Equal-Area Projection: Peters Projection

30
Cylindrical Equal-Area Projection: Behrmann Projection

31

Elliptical Equal-Area projection: Hammer Projection

32
True-direction Azimuthal Projection

33

Belgium: Projection Lambert 2008

Parameters
Ellipsoid Identity GRS80
_ Projection plane: Conical semi-major axis a 6,378,137 m
flattening f 1/298.257222101
_ Direction of the projection axis: Normal Standard Parallels ϕ1 49◦ 50’ N
ϕ2 51◦ 10’ N
_ Nature of the contact: Secant
Origine Origin Latitude 50◦ 47’ 52” 134 N
_ Nature of the deformation: Conformal Central meridian 4◦ 21’ 33” 177 E
Origin Coordinates x0 649,328 m
y0 665,262 m

34
Spatial Databases: Topics
_ Introduction

_ Georeferences and Coordinate Systems

y Conceptual Modeling for Spatial Databases


_ Logical Modeling for Spatial Databases

_ SQL/MM

_ Representative Systems

_ Summary

35

Data Modeling Requirements


_ Multiple views of space
• discrete (objects), continuous (fields)
• 2D, 2.5D, 3D

_ Multiple representations
• different scales, different viewpoints

_ Several spatial abstract data types


• point, line, area, set of points, set of lines, set of areas, . . .

_ Explicit spatial relationships


• crossing, adjacency, . . .

36
Interaction Requirements
_ Visual interactions
• map displays
• information visualization
• graphical queries on maps

_ Flexible, context-dependent interactions

_ Multiple user profiles


• highway: constructor, car driver, truck driver, hiker, ecologist

_ Multiple instantiations
• a building may be a school and a church
• a road segment may be also a segment of a hiking trail

37

Practical Requirements
_ Huge data sets
• Collecting new data is expensive
• Reusing highly heterogeneous existing data sets is a must ... but is very difficult!
• Integration requires understanding, hence a conceptual model

_ Integration of DB with different space/time granularity

_ Coexistence with non-spatial, non-temporal data

_ Reengineering of legacy applications

_ Interoperability

38
Why Conceptual Modeling?
_ Focuses on the application

_ Technology independent
• portability, durability

_ User oriented

_ Formal, unambiguous specification

_ Supports visual interfaces


• data definition and manipulation

_ Best vehicle for information exchange/integration

39

The Spatiotemporal Conceptual Manifesto


_ Good expressive power

_ Simple (understandable) data model


• few clean concepts, with standard, well-known semantics

_ No artificial constructs (e.g., space / time objects)

_ Orthogonality of space, time and data structures

_ Similarity of concepts for space and time

_ Clean, visual notations and intuitive icons / symbols

_ Formal definition

_ Associated query language

40
Orthogonality: What is Spatial

41

Same Space, Different Data Structures

Reservoir On River In Catchment


(1,1) (1,n) (1,n) (1,n)
reservoir_no river_name catchment_no

River

river_name
course
catchments (1,n)
reservoirs (1,n)

River In Catchment
(1,n) (1,n)
river_name catchment_no
reservoirs (1,n)

42
MADS Spatial Data Types: Type Hierarchy

Geo 
partition

Simple s Complex 
Geo Geo c

partition

Point PointBag

Surface
Line Surface LineBag
Bag

Oriented Simple Oriented Simple


Line Surface LineBag SurfaceBag

_ Spatial data types are topologically closed: all geometries include their boundary

_ Geo, SimpleGeo, and ComplexGeo are abstract classes

43

MADS Spatial Data Types (1)


Point

_ Boundary of a point: empty set

Line

simple and open non-simple and partially closed closed and


open simple

_ Boundary of a line: the extreme points, if any

44
MADS Spatial Data Types (2)
Surface

_ Defined by 1 exterior boundary and 0 or more interior boundaries defining its holes

_ Examples of geometries that are not surfaces

several surfaces several surfaces has a cut line has a spike

45

Complex Geometries and Their Boundaries


_ Boundary of a ComplexGeo value is defined (recursively) by the spatial union of
(1) the boundaries of its components that do not intersect with other components
(2) the intersecting boundaries that do not lie in the interior of their union
B(a ∪ b) = B(a) − b ∪ B(b) − a ∪ ( (B(a) ∩ b) ∪ (B(b) ∩ a) − I(a ∪ b) )
Types a Èb B(a È b)
Point/
Point
Point/
Line
Point/
Surface
Line/
Line
Line/
Surface

Surface/
Surface

46
Topological Predicates
_ Specify how two geometries relate to each other

_ Based on the definition of their boundary, interior, and exterior, denoted by I(x), B(x), and E(x)

_ Dim(x): maximum dimension (-1, 0, 1, or 2) of x, -1 corresponds to the dimension of the empty set

_ Dimensionally extended 9-intersection matrix (DE-9IM) for defining topological predicates


Interior Boundary Exterior
Interior Dim(I(a) ∩ I(b)) Dim(I(a) ∩ B(b)) Dim(I(a) ∩ E(b))
Boundary Dim(B(a) ∩ I(b)) Dim(B(a) ∩ B(b)) Dim(B(a) ∩ E(b))
Exterior Dim(E(a) ∩ I(b)) Dim(E(a) ∩ B(b)) Dim(E(a) ∩ E(b))

_ Dense notation use a string of 9 characters to represent the cells of the matrix

_ Possible characters: T (non-empty intersection), F (empty intersection), 0, 1, 2, * (irrelevant)

_ Example: a and b are disjoint if their intersection is empty


I(a) ∩ I(b) = ∅ ∧ I(a) ∩ B(b) = ∅ ∧ B(a) ∩ I(b) = ∅ ∧ B(a) ∩ B(b) = ∅
corresponds to ‘FF*FF****’

47

Topological Predicates (1)


Meets

_ a meets b ⇔ I(a) ∩ I(b) = ∅ ∧ a ∩ b , ∅ ∧ Dim(a ∩ b) = 0

_ Examples of geometries that do not satisfies the meets predicate

48
Topological Predicates (2)
Adjacent

_ a adjacent b ⇔ I(a) ∩ I(b) = ∅ ∧ a ∩ b , ∅ ∧ Dim(a ∩ b) = 1

_ The last example does not satisfies the predicate, their intersection is at the interior of both geometries

Touches

_ a touches b ⇔ I(a) ∩ I(b) = ∅ ∧ a ∩ b , ∅ ⇔ a meets b ∨ a adjacent b

49

Topological Predicates (3)


Crosses

_ a crosses b ⇔ Dim(I(a) ∩ I(b)) < max(Dim(I(a)), Dim(I(b))) ∧ a ∩ b , a ∧ a ∩ b , b ∧ a ∩ b , ∅

Overlaps

_ a overlaps b ⇔ Dim(I(a)) = Dim(I(b)) = Dim(I(a) ∩ I(b)) ∧ a ∩ b , a ∧ a ∩ b , b

50
Topological Predicates (4)
Contains/Within

_ a contains b ⇔ I(a) ∩ I(b) , ∅ ∧ a ∩ b = b ⇔ b within a

Disjoint/Intersects

_ a disjoint b ⇔ a ∩ b = ∅ ⇔ ¬a intersects b

Equals

_ a equals b ⇔ a ∩ b = a ∧ a ∩ b = b ⇔ (a − b) ∪ (b − a) = ∅

51

Topological Predicates (5)


Covers

_ a covers b ⇔ a ∩ b = b ⇔ b − a = ∅

Encloses/Surrounded

_ Definition is quite involved, depends of whether a is a (set of) line(s) or a (set of) surface(s)

52
Spatial Objects

Netherlands
14.8
Ireland Denmark
3.6 5.1
Belgium
9.9
Britain
57.2 Germany
Luxembourg 78.5 Switzerland
6.3
Country 0.4

name Austria
population France 7.4
58
Italy
57.5
Portugal
10.5
Spain
39

53

5.1

Spatial Attributes
3.6 14.8
Client Country Road
57.2
name name name
address population 9.9 responsible
78.5
location capital stations (1,n)
rivers (1,n) 0.4

7.4
6.3
58 attributes
_ Both non-spatial and spatial object types can have spatial
_ Domain of spatial attribute: a spatial type (point, line, surface, . 57.5
. .)
_ Spatial attributes can be multi-valued
10.5 39
_ A spatial attribute of a spatial object type may induce a topological constraint
• The capital of a country is located within the geometry of its country
_ This is not necessarily the case
• A given country will Figure
keep either
1.3 the full projection:
Theme geometry aoftheme
the rivers flowing
of countries and through it of western
population
Europe
or these geometries will (a) and projection
be projected on the attribute
to the section flowingpopulation
through (b).
the country
• This depends on application semantics
_ The conceptual schema must explicitly state these topological constraints

54
Spatial Complex Attributes
Country

name
population
capital
name
location
provinces (1,n)
name
location

_ Spatial attributes can be a component of a complex and/or multivalued attribute

_ It is usual to keep both thematic (alphanumeric) and location data for attributes, e.g., capital

_ This will allow to print both the name and the location of capitals/rivers/roads/... in a map

_ However, in real maps the toponyms (names of objects appearing in a map) have also a location
• There are precise cartographic rules for placing them, this is a semi-automatic process

55

Spatial Objects vs. Spatial Attributes


Land
Plot
Land (0,n) (1,n)
number Contains Building
Plot
owners (0,n)
buildings (0,n) number buildingNo
buildingNo owners (0,n)
location

_ Representing a concept as a spatial object or as a spatial attribute depends on the application

_ Determined by the relative importance of the concept

_ Has implications in the way of accessing the instances of the concept (e.g. the buildings)
• As spatial objects: the application can access a building one by one
• As spatial attributes: the access to a building must be made through the land plot containing it

56
Generalization: Inheriting Spatiality

Country Antenna
name owner
capital type

G20 Country GSM Antenna


G20_group frequency
representative impedance

_ Spatiality is inherited through generalization


• As any other feature: attributes, methods, relationships, integrity constraints, etc.

_ Based on the well-known susbtitutability principle in OOP

_ For simple inheritance it is not necessary to restate the geometry in the subtype (but see later)

_ As usual, spatiality can be added to a subtype


• Only instances of the subtype will have associated spatiality

57

Generalization: Refining/Redefining Spatiality

Road Road
Land Plot Town  1/10 000 1/10 000

Constructible Road Road


Village City 1/20 000 1/250 000
Land Plot

Refinement Refinement Redefinition Overloading

_ Arise when a spatiality is restated in a subtype

_ Refinement: restricts the inherited property, value remains the same in the supertype and the subtype

_ In redefinition and overloading an instance of the subtype has both a locally defined spatiality and the
inherited one

_ Redefinition: Keeps substitutability wrt typing, allows dynamic binding

_ Overloading: Relaxes substitutability, inhibiting dynamic binding

58
Generalization: Multiple Inheritance

Public
Building
Facility

Public
Building

_ Spatiality is inherited from several supertypes


• Similar situation may arise with any kind of attribute

_ There is ambiguity when referring to the spatiality of the subtype

_ Several policies have been proposed for solving this issue in the OO community

_ Most general policy


• All inherited properties are available in the subtype, user must disambiguate in queries
• PublicFacility.geometry vs Building.geometry for an instance of PublicBuilding

59

Spatial/Non-Spatial Relationships

Surveyor Avalanche
Observed
SSN (1,n) (1,n) cause
name damages

GeoLocalized
Monument
Photo
Depicts
number (1,n) (1,n) name
takenBy constructionDate

_ Spatiality can also be defined for relationship types

_ Spatiality of relationship types is orthogonal to the fact that linked object types are spatial

_ If a spatial relationship type relates spatial type(s), spatial constraints may restrict the geometries

60
Topological Relationships

Country River
Traversed
name (1,n) (1,n) name
capital length

_ Specified on a relationship type that links at least two spatial types


_ Constrain the spatiality of the instances of the related types
Topological
Icon
_ Many topological constraints can be defined using the 9IM Relationship
TopoGeneric
• 5 between complex points
TopoDisjoint
• 8 between simple regions TopoOverlap
• 18 between simple regions with holes TopoWithin
• 33 between complex regions TopoTouch
TopoCross
• 43 between a complex line and a complex region
TopoEqual
• ...
_ Conceptual model depicts only the most general ones

61

Spatial Aggregation

isComposedOf isComponentOf
Country State
Composes
name (1,n) (1,1) name
capital population

MobilePhone isComposedOf isComponentOf


Antena
Network Composes
name (1,n) (1,1) number
capital location

_ Traditional aggregation relationship can link spatial types

_ Usually, aggregation has exclusive semantics (stated by cardinalities in the component role)

_ Usually, the spatiality of the aggregation is partitioned into the spatiality of the components

_ It is not the case for the second example, where the spatiality of Antena corresponds to its coverage
• The same location can be covered by several antennas
• Spatiality of the aggregation is the spatial union of the spatiality of the antennas

62
Space- and Time-Varying Attributes

Country Country Country

name name name


elevation f() capital capital
population f( ) elevation f() elevation (1,n)
temperature f(, ) value
location

_ Also referred to as continuous fields


_ Allow to represent phenonema that change in space and/or in time
• elevation: to each point in space is associated a real number
• population: to each point in time is associated an integer number
• temperature: to each point in space is associated a real number, this value evolves over time
_ At the conceptual level, can be represented as continuous function
• Operators for manipulating fields can be defined at this level
_ At the logical level can be implemented in several ways
• Raster: Discretize the space into regular cells, assign a value to each cell
• TIN: Keep values at particular locations, interpolation used for calculating value at any point

63

Conceptual Schema: Example


Highway
Country
highway_code
country_code highway_name
country_name highway_type

(1,n) isComposedOf (1,n) isComposedOf

Composes Composes

(1,1) isComponentOf (1,n) isComponentOf

State Section Land use

state_code section_code region_name


state_name section_name land_use_type
number_lanes
(1,n) isComposedOf
(1,1) (1,1)
Composes
Starts at Ends at
(1,1) isComponentOf
(1,n) (1,n)
County
City
county_code
county_name city_name
population population

64
Spatial Databases: Topics
_ Introduction

_ Georeferences and Coordinate Systems

_ Conceptual Modeling for Spatial Databases

y Logical Modeling for Spatial Databases


_ SQL/MM

_ Representative Systems

_ Summary

65

Representation Models
_ Representation of infinite point sets of the Euclidean space in a computer

_ Two alternative representations

_ Object-based models (Vector)


• Describes the spatial extent of relevant objects with a set of points
• Uses points, lines, and surfaces for describing spatiality
• Choice of geometric types is arbitrary, varies across systems

_ Field-based models (Raster)


• Each point in space is associated with one/several attribute values, defined as continuous functions
• Examples: altitude, temperature, precipitation, polution, etc.

66
Belgium Map: Vector

67

Belgium Map: Raster

68
Belgium Map: Satellite

69

Organizing Spatial Data: Layers

70
So far, spatial objects have been represented at a rather abstract level,
using primitives such as points or edges. We now study the practical
implementation of geometric information. To state it briefly, the dif-
ficulty to overcome is the representation of infinite point sets of the
Euclidean space in a computer.
There exist different representation modes to solve the problem, ei-
ther by approximating the continuous space by a discrete one (tessella-
tion mode) or by constructing appropriate data structures (vector mode
and half-plane representation). For instance, in a tessellation mode a
city is represented as a set of cells that cover the city’s interior, whereas
in the vector mode it will be represented as a list of points describing the
boundary of a polygon.

2.2.1 Tessellation
A cellular decomposition of the plane (usually, a grid) serves as a ba- 2.2 Representation Modes 39
sis for representing the geometry. The partitioning of the embedding
space into disjoint cells defines a discrete model, sometimes called spatial
resolution model, tiling, or meshes in the field of computer graphics.
Second, there is no apparent distinction between a polyline structure
Raster Model: Tesselation
The approach can be further divided into fixed (or regular) and vari-
and a polygon structure. It is up to the software that manipulates ge-
able (or irregular) tessellation modes. A fixed representation model uses ometric data to interpret properly the structure, and to check that the
a regular grid or raster, which is a collection of polygonal units of equal representation is valid; that is, to verify that the polyline is closed for
_ Decomposition of the plane into polygonal units
size. A variable spatial resolution model handles units of decomposition the polygon.
of various sizes. The size of the units may also change according to the This remark holds for other possible constraints on the polygon type,
level of resolution. Figure 2.3 depicts two cases of regular tessellation,
36 such  convexity.
C as     2 Representation
Neither can we guarantee
of Spatial that a polygon is simple, in
Objects
_ May be regular or irregular, depending on whether the polygonal units are of equal size that the foregoing data structure does not prevent two nonconsecutive
edges to intersect. The structure is unfortunately not powerful enough
to ensure the correctness of the representation (i.e., the satisfiability of
such constraints).
The same situation holds for regions. Again, the structure is rel-
atively permissive. A polygon can be contained in another, and two
polygons can be adjacent, overlapping, or disconnected.
Figure 2.6 shows the representation of polygon P in vector mode.
It is described by an ordered list of pairs of coordinates, such as the
(a) (b) (a) (b)
following:
Figure 2.3
Regular
Regular tessellations: grid squares (a) and hexagonal cells (b). Figure 2.4 Irregular
Irregular tessellations: cadastral zones (a) and Thiessen poly-
gons (b). < [4, 4], [6, 1], [3, 0], [0, 2], [2, 2] >
_ Regular tesselation used for remote sensing data (e.g.,Figure
satellite
one with showsimages)
2.7square cells and one
examples with hexagonal
of polylines cells.vector
using this Figure 2.4 shows
represen-
two For
tation. examples of irregular
the sake tessellations.
of simplicity, we use aThe first different
slightly (Figure 2.4a) consid-
notation,
ers a cadastral
referred
_ Irregular tesselation used for zoning in social, demographic
second
integers
orofpartitioning
to as “vertex
(Figure
instead
notation”ofinthe
economic
2.4b)
givingshows
theplane
data into various
following.
theiracoordinates,
partitioningasinto
zones,
We index
ThiessenWe
previously.
whereas
vertices withthe
can see3
polygons.
In a raster
the following representation,
in Figure 2.7. the rectangular 2D space is partitioned
_ A spatial object is represented by the smallest subset of
intopixels thatofcontains
a finite number itUsually the space is decom-
elementary cells.
posed according to a regular 2D grid of N × M rectangular cells,
2.2 Representation Modes 37
whose sides are parallel to the space coordinate axes. The cells are called
y
pixels. A pixel has an address in the plane, which usually is a pair (x, y)
5 where x ≤ N is the column of the cell in the grid, and y ≤ M is
12 13 14
the row. (4,4)

17 18 19 20 21 22 -    


(0,2)
In practice,
a regular tessellation may be encountered in applications
26 27 28 29 30 31 (2,2)
that process image data (6,1) coming from remote sensing
2.2 Representation Modes(satellite images), 43
35 36 37 38
such as weather
(3,0) or pollution forecast. Then field-based data is still rep-
resented as a function from space x to a range such as temperature or
elevation. However, the function domain is no longer the infinite set of
Figure 2.5 Discrete representation of polygon P.
Figure 2.6 Vector representation of polygon P.
points but a finite set of pixels. In other words, space is no longer seen
as a continuous field, but as a discrete one, which permits an explicit
-    representation of data.
71
A spatial object in 2D space is represented by the Ansmallest
irregular(finite)
tessellation
sub- is used, for instance, in zoning (a typical GIS
function)
set of pixels that contains it. A point is described as a in social,
single demographic,
pixel. Its or economic data. Other applications
location is described as the pixel address; thatinclude surface
is, a pair modeling
of integer coor-using triangles or administrative and political
units.
dinates. A polyline, polygon, or region is represented by a finite number
of pixels. In Figure 2.5, the following list of pixels is a representation of
y
3. Given a set of points P, partitioning into Thiessen polygons associates with each
polygon P.
p ∈ P a polygon that is the set of points whose closest point in P is p. The resulting
< 5, 12, 13, 14, 17, 18, 19, 20, 21,partitioning
22, 26, 27, is also
28,called a Voronoi
z diagram.
x
29,2.2 Representation
30, 31, >
35, 36, 37, 38Modes 43
(a)
Digital Elevation
For the sake of simplicity, instead ofModels (DEMs)
using the (x, y) coordinate nota-
tion we referenced cells by an integer identifier.

_ Provide a digital (finite) representation


 of an abstract modeling of space
The tessellation mode makes it possible to approximate a spatial ob-
_ DEMs are useful to representject by a finite number of cells. The larger the grid resolution (i.e., the
natural phenomemon that is a continuous function of the 2D space
smaller the pixel size), the better the approximation but the higher the
number of cells for representing an object.4 A faithful object represen-
• temperature, presure, moisture, ora consequence
tation has as slope that objects occupy much memory space.
In addition, operations on objects are then more time consuming. Thisy
y
_ Based on a finite collection ofissometimes
a clear drawback to this approach. Nevertheless, information may
sample values,
be compressed values
to lead to a moreat other
compact form.points are obtained by interpolation z x
2.2 Representation Modes z this xsection, the tessellation
To conclude 43 mode is of prime impor-
(b)
_ Triangulated Irregular Networks
tance because(TINs) are based
of the exponentially (a) on
growing a triangular
volume of data coming partition of the
from satellite (raster) sources and because of the increasing use of it in
2D space
specific applications, such as environmental fields (pollution, weather,

4. An A4 formatted image, with 12 pts/mm, occupies 9 million pixels.

z
y y
y
z x z x x
(a) (b) (c)

Figure
_ No assumption is made on the distribution and location of the vertices of2.9theProgression
triangles of a triangulated
sample (a), triangulation (b), and TIN (c).
irregular network (TIN): point

_ Elevation value is recorded at each vertex


_ Value at any other point P inferred by linear interpolation of the 3 vertices of the triangle containing P
y z

y
z x x
72
(b) (c)

Figure 2.9 Progression of a triangulated irregular network (TIN): point


sample (a), triangulation (b), and TIN (c).

y
Abstract Data Types 77 3.3 Spatial Abstract Data Types

Geographic data modelRepresenting the Geometry of a Collection of Objects


Geographic data model
o2 o3 o1 o2 o3 o1 o2 o3 o1 o2

Nodes Nodes
Topological Spaghetti
Spaghetti Topological
Topological Spaghetti
Spatial data model a1 a4 Spatial data model
Node
Type support with topological or spaghetti structures. n1Figure 3.4 Type support with topological or spaghetti structures.
a2
a3
Arc Node
eration implementation depends on the representation and that the operation implementation depends on the representa
t choice provides a better support to topological operations.Network that the first choice provides a better support to topological op
instance, whether o 2 is adjacent to o 3 is easily answered, Asking, Topological
_ Three comonly used representations: Spaghetti, Network, for instance, whether o 2 is adjacent to o 3 is easily a
equires a complex, costly, anddiffer
_ Mainly lessinrobust computation
the expression with relationships
of topological whereas itamong
requires a complex,
the component costly, and less robust computat
objects
ructures. spaghetti structures.
73
    
depicts a (non-exhaustive) set of possible choices for geomet- Figure 3.5 depicts a (non-exhaustive) set of possible choices for
here is a trade-off between the modeling power captured by ric types. There is a trade-off between the modeling power cap
and the constraints imposed on the chosen representation. a definition and the constraints imposed on the chosen repres
Spaghetti Model
_ Geometry of any object described independently of other objects

_ No topology is stored in the model, all topological relationships must be computed on demand

_ Implies representation redundancy


(b) • E.g., boundary
(c) of adjacent regions represented twice
(a) (b) (c)
_ Enables heterogeneous representations mixing points, polylines and regions without restrictions
• E.g., polylines may intersect without the intersection points stored explicitly in the database

_ Advantages
• Simplicity
• Provides the end user with easy input of new objects into the collection
(e) _ Drawbacks(f ) (d) (e) (f )
Candidates for geometric • types:
Lack ofpoints
explicity
(a),information about
polyline (b), topological relationships among spatial objects
complex Figure 3.5 Candidates for geometric types: points (a), polyline (b)
polygon (d), polygon set (e), andsharing
• No mixed of
(f ).information ⇒ redundancy, problem
polyline (c),large
with polygon (d), inconsistency
data sets, polygon set (e), and mixed (f ).

74
Network Model
_ Destined for network (graph)-based applications
• transportation services, utility management (electricity, telephone, . . .)

_ Topological relationships among points and polylines are stored

_ Nodes: Distinguished point that connects a list of arcs

_ Arcs: Polyline that starts at a node and ends at a node

_ Nodes allow efficent line connectivity tests and network computations (e.g., shortest paths)

_ Two types of points: regular points and nodes

_ Depending on the implementation, the network is planar or nonplanar

_ Planar network: each edge intersection is recorded as a node, even if does not correspond to a real-
world entity

_ Nonplanar network: edges may cross withoug producing an intersection


• Examples include ground transportation with tunnels and passes

75

Topological Model
_ Similar to the network model, except that the network is plannar

_ Induces a planar subdivision into adjacent polygons, some of which may not correspond to actual
geographic objects

_ Node: represented by a point and the (possibly empty) list of arcs starting/ending at it
• Isolated point: identifies location of point features such as towers, point of interest, . . .

_ Arc: features its ending points, list of vertices and two polygons having the arc as common boundary

_ Polygon: represented by a list of arcs, each arc being shared with a neighbor polygon

_ Region: represented by one or more adjacent polygons

_ No redundacy: each point/line is stored only once

_ Advantages: Efficient computation of topological queries, update consistency

_ Drawbacks: Some database objects have no semantics in real-world, complexity of the structure may
slow down some operations

76
Spatial Databases: Topics
_ Introduction

_ Georeferences and Coordinate Systems

_ Conceptual Modeling for Spatial Databases

_ Logical Modeling for Spatial Databases

y SQL/MM
_ Representative Systems

_ Summary

77

SQL/MM Spatial: Geometry Type Hierarchy


ST_Geometry

ST_Point ST_Curve ST_Surface ST_Geom


Collection

ST_Curve ST_Polyhedral
Polygon Surface

ST_Polygon ST_TIN

ST_Triangle

ST_Circular ST_Compound ST_Multi ST_Multi ST_Multi


ST_LineString
String Curve Point Curve Surface

ST_Multi ST_Multi
LineString Polygon

_ ST_Geometry, ST_Curve, and ST_Surface are not instantiable types

78
ST Geometry
_ Represent 0D, 1D, and 2D geometries that exist in 2D (R2 ), 3D (R3 ) or 4D coordinate space (R4 )

_ Geometries in R2 have points with (x, y) coordinate values

_ Geometries in R3 have points with either (x, y, z) or (x, y, m) coordinate values

_ Geometries in R4 have points with (x, y, z, m) coordinate values

_ The z coordinate of a point typically represent altitude

_ The m coordinate of a point representing arbitrary measurement: key to supporting linear networking
applications such as street routing, transportation, pipeline, . . .

_ Geometry values are topologically closed (they include their boundary)

_ All locations in a geometry are in the same spatial reference system (SRS)

_ Geometric calculations are done in the SRS of the first geometry in the parameter list of a routine

_ If a routine returns a geometry or measurement (e.g., length or area), the value is in the SRS of the
first geometry in the parameter list

79

Methods on ST Geometrya : Metadata (1)


_ ST_Dimension: returns the dimension of a geometry

_ ST_CoordDim: returns the coordinate dimension of a geometry

_ ST_GeometryType: returns the type of the geometry as a CHARACTER VARYING value

_ ST_SRID: observes and mutates the spatial reference system identifier of a geometry

_ ST_Transform: returns the geometry in the specified spatial reference system

_ ST_IsEmpty: tests if a geometry corresponds to the empty set


a 3D versions of some of these methods exists

80
Methods on ST Geometry: Metadata (2)
_ ST_IsSimple: tests if a geometry has no anomalous geometric points
LineString MultilineString

simple not simple not simple simple not


simple simple simple

_ ST_IsValid: tests if a geometry is well formed

Polygons

valid valid invalid invalid invalid

_ ST_Is3D: tests whether a geometry has z coordinates

_ ST_IsMeasured: tests whether a geometry has m coordinate values

81

Methods on ST Geometry: Spatial Analysis (1)


_ ST_Boundary: returns the boundary of a geometry
_ ST_Envelope: returns the bounding rectangle of a geometry

_ ST_ConvexHull: returns the convex hull of a geometry

p p

q
q

_ ST_Buffer: returns the geometry that represents all points whose distance from any point of a geom-
etry is less than or equal to a specified distance

82
Methods on ST Geometry: Spatial Analysis (2)
_ ST_Union: returns the geometry that represents the point set union of two geometries

_ ST_Intersection: returns the geometry that represents the point set intersection of two geometries

_ ST_Difference: returns the geometry that represents the point set difference of two geometries

_ ST_SymDifference: returns the geometry that represents the point set symmetric difference of two
geometries

Geometries Union Intersection Difference Symmetric


Difference

_ ST_Distance: returns the distance between two geometries

83

Methods and Functions on ST Geometry: Input/Output


_ ST_WKTToSQL: returns the geometry for the specified well-known text representation

_ ST_AsText: returns the well-known text representation for the specified geometry

_ ST_WKBToSQL: returns the geometry for the specified well-known binary representation

_ ST_AsBinary: returns the well-known binary representation for the specified geometry

_ ST_GMLToSQL: returns the geometry for the specified GML representation

_ ST_AsGML: returns the GML representation for the specified geometry

_ ST_GeomFromText: returns a geometry, which is transformed from a CHARACTER LARGE OBJECT


value that represents its well-known text representation

_ ST_GeomFromWKB: returns a geometry, which is transformed from a BINARY LARGE OBJECT value
that represents its well-known binary representation

_ ST_GeomFromGML: returns a geometry, which is transformed from a CHARACTER LARGE OBJECT


value that represents its GML representation

84
Boundary, Interior, Exterior
_ Boundary of a geometry: set of geometries of the next lower dimension
• ST_Point or ST_MultiPoint value: empty set
• ST_Curve: start and end ST_Point values if nonclosed, empty set if closed
• ST_MultiCurve: ST_Point values that are in the boundaries of an odd number of its element
ST_Curve values
• ST_Polygon value: its set of linear rings
• ST_MultiPolygon value: set of linear rings of its ST_Polygon values
• Arbitrary collection of geometries whose interiors are disjoint: geometries drawn from the bound-
aries of the element geometries by application of the mod 2 union rule
• The domain of geometries considered consists of those values that are topologically closed

_ Interior of a geometry: points that are left when the boundary points are removed

_ Exterior of a geometry: points not in the interior or boundary

85

Spatial Relationships
_ ST_Equals: tests if a geometry is spatially equal to another geometry

_ ST_Disjoint: tests if a geometry is spatially disjoint from another geometry

_ ST_Intersects: tests if a geometry spatially intersects another geometry

_ ST_Touches: tests if a geometry spatially touches another geometry

_ ST_Crosses: tests if a geometry spatially crosses another geometry

_ ST_Within: tests if a geometry is spatially within another geometry

_ ST_Contains: tests if a geometry spatially contains another geometry

_ ST_Overlaps: tests if a geometry spatially overlaps another geometry

_ ST_Relate: tests if a geometry is spatially related to another geometry by testing for intersections
between their interior, boundary and exterior as specified by the intersection matrix
• a.ST_Disjoint(b) ⇔ (I(a) ∩ I(b) = ∅) ∧ (I(a) ∩ B(b) = ∅) ∧
(B(a) ∩ I(b) = ∅) ∧ (B(a) ∩ B(b) = ∅) ⇔ a.ST_Relate(b,’FF*FF****’)

86
Conceptual Schema: Example
Highway
Country
highway_code
country_code highway_name
country_name highway_type

(1,n) isComposedOf (1,n) isComposedOf

Composes Composes

(1,1) isComponentOf (1,n) isComponentOf

State Section Land use

state_code section_code region_name


state_name section_name land_use_type
number_lanes
(1,n) isComposedOf
(1,1) (1,1)
Composes
Starts at Ends at
(1,1) isComponentOf
(1,n) (1,n)
County
City
county_code
county_name city_name
population population

87

Reference Schemas (1)


Create Table Country
(country_code integer,
country_name varchar (30),
geometry ST_MultiPolygon,
Primary Key (country_code))

Create Table State


(state_code integer,
state_name varchar (30),
country_code integer,
geometry ST_MultiPolygon,
Primary Key (state_code),
Foreign Key (country_code) References Country)

Create Table County


(county_code integer
county_name varchar (30),
state_code integer,
population integer,
geometry ST_MultiPolygon,
Primary Key (county_code),
Foreign Key (state_code) References State)

88
Reference Schemas (2)

/* Table Highway is NOT spatial */


Create Table Highway
(highway_code integer,
highway_name varchar (4),
highway_type varchar (2),
Primary Key (highway_code))

Create Table HighwaySection


(section_code integer,
section_number integer,
highway_code integer,
Primary Key (section_code,highway_code),
Foreign Key (section_code) References Section,
Foreign Key (highway_code) References Highway)

89

Reference Schemas (3)


Create Table Section
(section_code integer,
section_name varchar (4),
number_lanes integer,
city_start varchar (30),
city_end varchar (30),
geometry ST_Line,
Primary Key (section_code),
Foreign Key (city_start) References City,
Foreign Key (city_end) References City)

Create Table City


(city_name varchar (30),
population integer,
geometry ST_MultiPolygon,
Primary Key (city_name))

Create Table LandUse


(region_name varchar (30),
land_use_type varchar (30),
geometry ST_Polygon,
Primary Key (region_name))

90
Reference Queries: Alphanumerical Criteria (1)
_ Number of inhabitants in the county of San Francisco
select population
from County
where county_name = ’San Francisco’

_ List of the counties of the State of California


select county_name
from County, State
from State.state_code = County.state_code
and state_name = ’California’

_ Number of inhabitants in the US


select sum (c2.population)
from Country c1, State s, County c2
where c1.country_name = ’USA’
and c1.country_code = s.country_code
and s.state_code = c2.state_code

91

Reference Queries: Alphanumerical Criteria (2)


_ Number of lanes in the first section of Interstate 99
select s.number_lanes
from Highway h1, HighwaySection h2, Section s
where h1.highway_code = h2.highway_code
and h2.section_code = s.section_code
and h1.highway_name = ’I99’
and h2.section_number = 1

_ Name of all sections that constitute Interstate 99


select s.section_name
from Highway h1, HighwaySection h2, Section s
where h1.highway_name = ’I99’
and h1.highway_code = h2.highway_code
and h2.section_code = s.section_code

92
Reference Queries: Spatial Criteria (1)
_ Counties adjacent to the county of San Francisco in the same state
select c1.county_name
from County c1, County c2
where c2.county_name = ’San Francisco’
and c1.state_code = c2.state_code
and ST_Touches(c1.geometry, c2.geometry)

_ Display of the State of California (supposing that the State table is no spatial)
select ST_Union(c.geometry)
from County c, State s
where s.state_code = c.state_code
and s.state_name = ’California’

93

Reference Queries: Spatial Criteria (2)


_ Counties larger than the largest county in California
select c1.county_name
from County c1
where ST_Area(c1.geometry) >
(select max (ST_Area(c.geometry))
from County c, State s
where s.state_code = c.state_code
and s.state_name = ’California’)

_ Length of Interstate 99
select sum (ST_Length(s.geometry))
from Highway h1, HighwaySection h2, Section s
where h1.highway_name = ’I99’
and h1.highway_code = h2.highway_code
and h2.section_code = s.section_code

94
Reference Queries: Spatial Criteria (3)
_ All highways going through the State of California
select distinct h1.highway_name
from State s1, Highway h1, HighwaySection h2, Section s2
where s1.state_name = ’California’
and h1.highway_code = h2.highway_code
and h2.section_code = s2.section_code
and ST_Overlaps(s2.geometry, s1.geometry)
_ Display of all residential areas in the county of San Jose
select ST_Intersection(l.geometry, c.geometry)
from County c, LandUse l
where c.county_name = ’San Jose’
and l.land_use_type = ’residential area’
and ST_Overlaps(l.geometry, c.geometry)
_ Overlay the map of administrative units and land use
select county_name, land_use_type, ST_Intersection(c.geometry, l.geometry)
from County c, LandUse l
where ST_Overlaps(c.geometry, l.geometry)

95

Reference Queries: Interactive Queries (1)


_ Description of the county pointed to on the screen
select county_name, population
from County
where ST_Contains(geometry, @point)

_ Counties that intersect a given rectangle on the screen


select county_name
from County
where ST_Overlaps(geometry, @rectangle)

_ Part of counties that are within a given rectangle on the screen (clipping)
select ST_Intersection(geometry, @rectangle)
from County
where ST_Overlaps(geometry, @rectangle)

96
Reference Queries: Interactive Queries (2)
_ Description of the highway section pointed to on the screen
select section_name, number_lanes
from Section
where ST_Contains(geometry, @point)

_ Description of the highway(s) of which a section is pointed to on the screen


select h1.highway_name, h1.highway_type
from Highway h1, HighwaySection h2, Section s
where h1.highway_code = h2.highway_code
and h2.section_code = s.section_code
and ST_Contains(s.geometry, @point)

97

SQL/MM: Conclusion
_ SQL/MM provides a standard way to declare and manipulate geometries

_ The last version includes 3D and 4D types

_ Several spatial data type organized in a hierarchy with associated methods

_ These methods can be combined in SQL queries and programs with standard ones

_ We only convered a small part of the standard


• For additional information refer to the document

_ However, systems deviate, sometimes considerably from the standard

98
Spatial Databases: Topics
_ Introduction

_ Georeferences and Coordinate Systems

_ Conceptual Modeling for Spatial Databases

_ Logical Modeling for Spatial Databases

_ SQL/MM

_ Representative Systems
y Oracle
_ Summary

99

Oracle Locator
_ Included in all editions of the database

_ All functions required for standard GIS tools

_ All geometric objects


• Points, lines, polygons
• 2D, 3D, 4D

_ Indexing: quadtrees and rtrees

_ Geometric queries

_ Proximity search

_ Distance calculation

_ Multiple projections

_ Conversion of projections

100
Oracle Spatial
_ Advanced functions: Option of Oracle Database Enterprise Edition

_ = Locator + ...
• Geometric transformations
• Spatial aggregations
• Dynamic segmentation
• Measures
• Network modeling
• Topology
• Raster
• Geocoder
• Spatial Data Mining
• 3D Types (LIDAR, TINS)
• Web Services (WFS, CSW, OpenLS)

101

Oracle Network Model

_ A data model for representing networks in the


database
_ Maintains connectivity
_ Attributes at the link and node levels
_ Used for network management
• Transportation, logistics, utilities, location-
based services, . . .
_ Navigation engine for route calculation

102
Oracle Topological Model

_ Persistent storage of the topology


• Nodes, arcs, faces
• Topological relations
• Allows advanced consistency checks
_ Data model
• Defining objects (features) through topologi-
cal primitives
• New type SDO_TOPO_GEOMETRY
• Use traditional operators (SDO_RELATE ...)
_ Co-existence with traditional spatial data
• Possibility of combining SDO_GEOMETRY and
SDO_TOPO_GEOMETRY

103

Oracle Geo Raster


_ New data type SDO_GEORASTER
• Satellite images, remote sensing data
• Multi-band, multi-layer
• Metadata in XML
• Geo-referencing information
_ Functionality
• Open, general purpose raster data model
• Storage and indexing of raster data
• Querying and analyzing raster data
• Delivering GeoRaster to external consumers:
Publish as JPEG, GIFF images

104
Oracle Geocoding

_ Generates latitude/longitude (points) from address

_ International addressing standardization

_ Formatted and unformatted addresses

_ Tolerance parameters support fuzzy matching

_ Record-level and batch processes

_ Data available from Navteq, TeleAtlas

105

Oracle MapViewer

_ Supplied with all versions of Oracle Application


Server
_ XML interfaces, Java and Javascript (Ajax)
_ Tool for map definition
_ Maps described in the database
• Symbology, visibility, etc.
_ Thematic maps
_ Formats: PNG, GIF, JPEG, SVG
_ OGC WMS compatibility
• Both server and client

106
Oracle: Geometry Type
_ Creation of spatial tables
CREATE TABLE Cells (
Cell_id NUMBER,
Cell_name VARCHAR2(32),
Cell_type NUMBER,
Location SDO_GEOMETRY,
Covered_area SDO_GEOMETRY);

_ Use the SDO_GEOMETRY type

_ No limit to the number of geometrical columns per table

_ The column can contain any type of geometry

107

Oracle: Geometrical Primitives

Point Line string Arc line string Compound line string Self-crossing
line string

Polygon Polygon Compound polygon Optimized polygons Self-crossing


with hole polygon

not valid

108
Geometrical Primitives: Points
_ Points (X1, Y1)

_ Represent des point objects: buildings, clients, agencies, ...

_ 2, 3, or 4 dimensions

109

Geometrical Primitives: Lines

_ Lines (X1, Y1, ... Xn, Yn)

_ Represent linear objects such as roads, cables, rivers, etc.

_ Formed of straight lines or arcs (or their combination)

_ A closed line does not delineate surface

_ Self-crossing lines allowed

110
Geometrical Primitives: Polygones

_ Polygons (X1, Y1, ... Xn, Yn)

_ Represent surface objects: fields, regions, postal codes, etc.

_ The contour must be closed (last point = first point)

_ The interior can contain one or more holes or voids

_ The boundary cannot intersect

_ Boundary formed by straight lines or arcs (or their combination)

_ Also specific forms: rectangle, circle

111

Oracle: Structuring of Spatial Data

112
Oracle: Element

_ Basic component of geometric objects


_ Element type:
• point
• line
• polygon
_ Formed of an ordered sequence of points

A single geometry composed of 6 elements

113

Oracle: Geometry

_ Represent a spatial object


_ Composed of an ordered list of elements
_ May be homogeneous ou heterogeneous

114
Oracle: Layer

_ Represent a geometrical column in a table


_ In general, contain objects of the same nature,
i.e., having the same attributes
• Client layer (points)
• Street layer (lines)
• State layer (polygons)

115

SDO GEOMETRY Type


_ Structure of the SDO_GEOMETRY object
SDO_GTYPE NUMBER
SDO_SRID NUMBER
SDO_POINT SDO_POINT_TYPE
SDO_ELEM_INFO SDO_ELEM_INFO_ARRAY
SDO_ORDINATES SDO_ORDINATE_ARRAY
_ Example of use
CREATE TABLE states (
state VARCHAR2(30),
totpop NUMBER(9),
geom SDO_GEOMETRY);

116
SDO GTYPE

_ Define the nature of the geometric shape contained in the object

117

SDO SRID

_ SRID = Spatial Reference system ID

_ Specifies the coordinate system of the object

_ List of possible values is found in the table MDSYS.CS_SRS


• More than 1,000 different systems

_ A common value: 8307


• “Longitude / Latitude WGS84”
• Used by the GPS system
• Navteq and TeleAtlas data is WGS84

_ All geometries of a layer must have the same SRID

_ Layers may have different SRIDs

_ Automatic conversion for spatial queries

118
SDO POINT
_ Object type SDO_POINT_TYPE
x NUMBER
y NUMBER
z NUMBER

_ Example of use
INSERT INTO TELEPHONE_POLES (col-1, ..., col-n, geom)
VALUES (attribute-1, ..., attribute-n,
SDO_GEOMETRY (
2001, 8307,
SDO_POINT_TYPE (-75.2,43.7,null),
null, null)
);

119

SDO ORDINATES
_ Object type SDO_ORDINATE_ARRAY
VARRAY (1048576) OF NUMBER

_ Store the coordinates of lines et polygons

_ For example, in 2D two entries per point

120
SDO ELEM INFO
_ Object type SDO_ELEM_INFO_ARRAY
VARRAY (1048576) OF NUMBER

_ Specifies the nature of the elements

_ Describes the various components of a complex object

_ Three entries per element


• Ordinate offset: Position of the first number for this element in the array SDO_ORDINATES
• Element type: Type of the element
• Interpretation: Straight line, arc, etc.

121

SDO ELEM INFO: Example

122
Line Examples

123

Polygon Examples (1)

124
Polygon Examples (2)

125

Multi-Point and Multi-Line Examples

126
Multi-Polygon and Polygon with Hole Examples

127

Constructing a Line
INSERT INTO LINES (col-1, ..., col-n, geom) VALUES (
attribute_1, ..., attribute_n,
SDO_GEOMETRY (
2002, 8307, null,
SDO_ELEM_INFO_ARRAY (1,2,1),
SDO_ORDINATE_ARRAY (
10,10, 20,25, 30,10, 40,10))
);

128
Metadata
_ Defines the boundaries of a layer
• Minimum and maximum coordinates for each dimension

_ Sets the tolerance of a layer


• Maximum distance between two points they are considered distinct

_ Defines the coordinate system for a layer

INSERT INTO USER_SDO_GEOM_METADATA


(TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES (
’ROADS’,
’GEOMETRY’,
SDO_DIM_ARRAY (
SDO_DIM_ELEMENT(’Long’, -180, 180, 0.5),
SDO_DIM_ELEMENT(’Lat’, -90, 90, 0.5)),
8307 );

129

Constructing Geometries
_ Standard constructor
INSERT INTO TELEPHONE_POLES (col-1, ..., col-n, geom)
VALUES (attribute-1, ..., attribute-n,
SDO_GEOMETRY (
2001, 8307,
SDO_POINT_TYPE (-75.2,43.7,null),
null, null)
);
_ Well-known Text (WKT) constructor
INSERT INTO TELEPHONE_POLES (col-1, ..., col-n, geom)
VALUES (attribute-1, ..., attribute-n,
SDO_GEOMETRY (’POINT (-75.2 43.7)’,8307)
);
_ Well-known Binary (WKB) constructor
INSERT INTO TELEPHONE_POLES (col-1, ..., col-n, geom)
VALUES (attribute-1, ..., attribute-n,
SDO_GEOMETRY (:my_blob,8307)
);

130
Geometry Extraction: WKT Format

SELECT c.geom.get_wkt()
FROM us_counties c
WHERE county = ’Denver’;

POLYGON (
(-105.052597 39.791199, -105.064606 39.789928, ...
... -105.024757 39.790947,-105.052597 39.791199),
(-104.933578 39.698139, -104.936104 39.698299, ...
... -104.9338 39.696701, -104.933578 39.698139))

_ Do not forget to use an alias!

_ Returns the geometry in a CLOB

131

Geometry Extraction: WKB Format

SELECT county, c.geom.get_wkb()


INTO :my_blob
FROM us_counties c
WHERE state_abrv = ’NH’;

CREATE TABLE us_counties_wkb AS


SELECT county, state_abrv, c.geom.get_wkb() wkb_geom
FROM us_counties c;

_ Do not forget to use an alias!

_ Returns the geometry in a BLOB

132
Geometry Extraction: GML Format

SELECT city, sdo_util.to_gmlgeometry(location)


FROM us_cities
WHERE state_abrv = ’CO’;

<gml:Point srsName="SDO:8307
xmlns:gml="http://www.opengis.net/gml">
<gml:coordinates decimal="." cs="," ts=" ">
-104.872655,39.768035
</gml:coordinates>
</gml:Point>

133

Generation of XML documents: XMLForest (1)

SELECT xmlelement(
"City",
xmlattributes(
’http://www.opengis.net/gml’ as "xmlns:gml"),
xmlforest(
city as "Name",
pop90 as "Population",
xmltype( sdo_util.to_gmlgeometry(location) )
as "gml:geometryProperty")
) AS theXMLElements
FROM us_cities
WHERE state_abrv = (’CO’);

134
Generation of XML documents: XMLForest (2)

<City xmlns:gml="http://www.opengis.net/gml">
<Name>Denver</Name>
<Population>467610</Population>
<gml:geometryProperty><gml:Point srsName="SDO:8307"
xmlns:gml="http://www.opengis.net/gml">
<gml:coordinates decimal="." cs="," ts=" ">
-104.872655,39.768035 </gml:coordinates>
</gml:Point></gml:geometryProperty>
</City>
...
<City xmlns:gml="http://www.opengis.net/gml">
<Name>Lakewood</Name>
<Population>126481</Population>
<gml:geometryProperty><gml:Point srsName="SDO:8307"
xmlns:gml="http://www.opengis.net/gml">
<gml:coordinates decimal="." cs="," ts=" ">
-105.113556,39.6952 </gml:coordinates>
</gml:Point></gml:geometryProperty>
</City>

135

Manipulation of Geometries in Java

_ Java API provided in the kit SDOAPI.JAR

_ Can be distributed with your applications


• As the JDBC driver

_ Class JGeometry

_ load() and store() methods

_ Many utility functions


• Read and write GML
• Read and write shape files

136
Reading Geometries

// Construct SQL query


String sqlQuery = "SELECT GEOM FROM US_COUNTIES"
// Execute query
Statement stmt = dbConnection.createStatement();
OracleResultSet rs = (OracleResultSet)stmt.executeQuery(sqlQuery);
// Fetch results
while (rs.next())
{
// Extract JDBC object from record into structure
STRUCT dbObject = (STRUCT) rs.getObject(1);
// Import from structure into Geometry object
JGeometry geom = JGeometry.load(dbObject);
}

137

Extracting Information from Geometries (1)

int gType = geom.getType();


int gSRID = geom.getSRID();
int gDimensions = geom.getDimensions();
long gNumPoints = geom.getNumPoints();
long gSize = geom.getSize();

boolean isPoint = geom.isPoint();


boolean isCircle = geom.isCircle();
boolean hasCircularArcs = geom.hasCircularArcs();
boolean isGeodeticMBR = geom.isGeodeticMBR();
boolean isLRSGeometry = geom.isLRSGeometry();
boolean isMultiPoint = geom.isMultiPoint();
boolean isRectangle = geom.isRectangle();
// NON EXHAUSTIVE LIST !

138
Extracting Information from Geometries (2)

// Point
double gPoint[] = geom.getPoint();
// Element info array
int gElemInfo[] = geom.getElemInfo();
// Ordinates array
double gOrdinates[] = geom.getOrdinatesArray();
// First and last point
double[] gFirstPoint = geom.getFirstPoint();
double[] gLastPoint = geom.getLastPoint();
// MBR
double[] gMBR = geom.getMBR();
// Java Shape
Shape gShape = geom.createShape();

139

Constructing Geometries (1)

// Point
JGeometry geom = new JGeometry(10,5, 8307);
// Point (3D)
JGeometry geom = new JGeometry(10,5,3, 8307);
// Rectangle
JGeometry geom = new JGeometry(10,135, 20,140, 8307);
// Any geometry (compound linestring)
JGeometry geom = new JGeometry(
2002,8307,
new int[] {1,4,3, 1,2,1, 3,2,2, 7,2,1},
new double[] {10,45, 20,45, 23,48, 20,51, 10,51});

140
Constructing Geometries (2)

// Point
JGeometry geom = JGeometry.createPoint(
new double[] {10,5}, 2, 8307);
// Linestring
JGeometry geom = JGeometry.createLinearLineString(
new double[] {10,25, 20,30, 25,25, 30,30}, 2, 8307);
// Simple polygon
JGeometry geom = JGeometry.createLinearPolygon(
new double[] {10,105, 15,105, 20,110, 10,110, 10,105}, 2, 8307);
// Polygon with voids
JGeometry geom = JGeometry.createLinearPolygon(
new double[][] {{50,105, 55,105, 60,110, 50,110, 50,105},
{52,106, 54,106, 54,108, 52,108, 52,106}}, 2, 8307);

141

Constructing Geometries (3)

// Multi-point
JGeometry geom = JGeometry.createMultiPoint(
new double[][] {{50,5}, {55,7}, {60,5}}, 2, 8307);
// Multi-linestring
JGeometry geom = JGeometry.createLinearMultiLineString(
new double[][] {{50,15, 55,15}, {60,15, 65,15}}, 2, 8307);
// Circle (using 3 points on the circumference)
geom = JGeometry.createCircle(15,145, 10,150, 20,150, 8307);
// Circle (using a center point and radius)
geom = JGeometry.createCircle(10,150, 5, 8307);

142
Writing Geometries

// Construct the SQL statement


String SqlStatement = "INSERT INTO SHAPES (ID, GEOM) VALUES (?,?)";
// Prepare the SQL statement
PreparedStatement stmt = dbConnection.prepareStatement(SqlStatement);
// Convert object into java STRUCT
STRUCT s = JGeometry.store (geom, dbConnection);
// Insert row in the database table
stmt.setInt (1, i);
stmt.setObject (2,s);
stmt.execute();

143

Spatial Indexes

_ R-tree indexing
• Tree rectangles (MBR)
• Indexing in 2 or 3 dimensions
_ Quad-tree indexing
• Use of a regular grid
• No longer documented from 10g
• Do not use, unless exceptions ...
_ A spatial index must exist before we can ask spa-
tial queries on a table!

144
R-Tree Index

_ Based on the Minimum Bounding Rectange (MBR) of objects

145

Creation and Deletion of an R-tree Index


_ Index creation
create index CUSTOMERS_SIDX
on CUSTOMERS (LOCATION)
indextype is MDSYS.SPATIAL_INDEX;

_ CREATE INDEX statement may have additional parameters


• E.g., to specify the number of dimensions and where to store the index information

_ Identifying the SDO_INDEX_TABLE that stores the spatial index on the customers table
SELECT SDO_INDEX_TABLE FROM USER_SDO_INDEX_INFO
WHERE TABLE_NAME = ’CUSTOMERS’ AND COLUMN_NAME=’LOCATION’;
SDO_INDEX_TABLE
--------------------------------
MDRT_D81F$

_ Index deletion
DROP INDEX <index_name>;

146
How to Find Information about Spatial Indexes

_ USER_INDEXES
• INDEX_TYPE = ’DOMAIN’ and ITYP_NAME = ’SPATIAL_INDEX’

_ USER_SDO_INDEX_INFO
• Column SDO_INDEX_TABLE identifies the physical table containing the index proprement: table
whose name is of the form MDRT_xxxx$

_ USER_SDO_INDEX_METADATA
• As above, but with more details: number of nodes, node size, height of the index tree, etc.

147

Query Execution Model

148
Optimized Query Execution Model

149

Writing Spatial Queries

_ Contain a spatial predicate (WHERE clause)


• Find the plots along a river
• Find clients within 5 km of a warehouse
• Find the nearest branch of a client

_ Expressed through specific SQL operators


• SDO_RELATE, SDO_INSIDE, SDO_TOUCH
• SDO_WITHIN_DISTANCE
• SDO_NN

_ The spatial index MUST exist, otherwise


ORA-13226: interface not supported without a spatial index
ORA-06512: at "MDSYS.MD", line 1723
ORA-06512: at "MDSYS.MDERR", line 8
ORA-06512: at "MDSYS.SDO_3GL", line 387

150
Topological Predicates
_ Select objects by their topological relationship with another object
• SDO_INSIDE
• SDO_CONTAINS
• SDO_COVERS
• SDO_COVEREDBY
• SDO_OVERLAPS
• SDO_TOUCH
• SDO_EQUAL
• SDO_ANYINTERACT

_ Example
WHERE SDO_INSIDE ( <geometry-1>, <geometry-2> ) = ’TRUE’

151

Generic Topological Operator


_ SDO_RELATE generic operator with a specific mask
WHERE SDO_RELATE (<geometry-1>, <geometry-2>, ’MASK=xxxx’) = ’TRUE’

_ Mask may be ’INSIDE’, ’CONTAINS’, ’TOUCH’, etc.

_ Or a combination: ’INSIDE+COVEREDBY’

152
Topological Operators

153

Example Queries
_ Which parks are entirely contained in the state of Wyoming?
SELECT p.name
FROM us_parks p, us_states s
WHERE s.state = ’Wyoming’
AND SDO_INSIDE (p.geom, s.geom) = ’TRUE’;

_ Equivalent to
AND SDO_RELATE(p.geom,s.geom,’MASK=INSIDE’) = ’TRUE’;

_ Which states contain all or part of Yellowstone Park?


SELECT s.state
FROM us_states s, us_parks p
WHERE SDO_ANYINTERACT (s.geom, p.geom) = ’TRUE’
AND p.name = ’Yellowstone NP’;

154
Example Queries
_ In which competing jurisdictions is my client?
SELECT s.id, s.name
FROM customers c, competitors_sales_regions s
WHERE c.id = 5514 AND SDO_CONTAINS (s.geom, c.location) = ’TRUE’;

_ Find all counties around Passaic County (NJ)


SELECT c1.county, c1.state_abrv
FROM us_counties c1, us_counties c2
WHERE c2.state = ’New Jersey’ AND c2.county = ’Passaic’
AND SDO_TOUCH (c1.geom, c2.geom) = ’TRUE’;

155

Queries with a Constant Window


_ Find all customers of type “Platinum” in a rectangular area
SELECT name, category
FROM customers
WHERE SDO_INSIDE (
location,
sdo_geometry (2003, 8307, null,
sdo_elem_info_array (1,1003,3),
sdo_ordinate_array (
-122.413, 37.785,-122.403, 37.792))
)=’TRUE’
AND customer_grade = ’PLATINUM’;
_ In which competitors sales territories is located a geographical point?
SELECT id, name
FROM competitors_sales_regions
WHERE SDO_CONTAINS (
geom,
SDO_GEOMETRY(2001, 8307,
SDO_POINT_TYPE(-122.41762, 37.7675089, NULL),
NULL, NULL)
) = ’TRUE’;

156
Queries Based on Distance
_ Select objects according to distance from another object

_ Operator SDO_WITHIN_DISTANCE
SDO_WITHIN_DISTANCE(
<geometry-1>, <geometry-2>,
’DISTANCE=distance UNIT=unit’ ) = ’TRUE

_ Distance can be expressed in any unit of measure

_ If no unit is specified, the distance is expressed in the unit of the coordinate system (if projected)

_ For longitude/latitude data, these are meters

157

Examples of Research on Distance (1)


_ Which agencies are less than 1km from this client?

SELECT b.id, b.phone_number


FROM customers c, branches b
WHERE c.id = 8314
AND SDO_WITHIN_DISTANCE(
b.location, c.location,
’distance=1 unit=km’)
= ’TRUE’;

158
Examples of Research on Distance (2)
_ How many customers in each category are located within 1/4 mile of my office number 77?
SELECT customer_grade, COUNT(*)
FROM branches b, customers c
WHERE b.id=77
AND SDO_WITHIN_DISTANCE (
c.location, b.location,
’DISTANCE=0.25 UNIT=MILE’)=’TRUE’
GROUP BY customer_grade;

159

Research Based on Proximity


_ Selects the N closest objects of another object

_ SDO_NN operator with the number of objects to be returned


WHERE SDO_NN (
<geometry-1>, <geometry-2>,
’SDO_NUM_RES=n’) = ’TRUE

_ ROWNUM can be used to limit results


WHERE SDO_NN (
<geometry-1>, <geometry-2>) = ’TRUE
AND ROWNUM <=n

_ To use when additional filtering

_ SDO_NN_DISTANCE() used to categorize answers by distance

160
Example of Proximity Search
_ What is the nearest office to this client?

SELECT b.id, b.phone_number


FROM customers c,
branches b
WHERE c.id = 8314
AND SDO_NN(
b.location, c.location,
’sdo_num_res=1’)
= ’TRUE’;

161

Example of Proximity Search


_ What are my five customers closest to this competitor?
SELECT c.id, c.name, c.customer_grade
FROM competitors co, customers c
WHERE co.id=1
AND SDO_NN (
c.location, co.location,
’SDO_NUM_RES=5’)=’TRUE’ ;

809 LINCOLN SUITES GOLD


1044 MUSEUM OF THE THIRD DIMENSION SILVER
1526 INTERNATIONAL FINANCE SILVER
1538 MCKENNA AND CUNEO SILVER
8792 DESTINATION HOTEL & RESORTS GOLD

_ This only works if no other selection criterion is present!

162
Classifying Results by Distance
_ What are my five customers closest to this competitor?
SELECT c.id, c.name, c.customer_grade,
SDO_NN_DISTANCE(1) distance
FROM competitors co, customers c
WHERE co.id=1
AND SDO_NN (
c.location, co.location,
’SDO_NUM_RES=5’, 1)=’TRUE’
ORDER BY distance;

1538 MCKENNA AND CUNEO SILVER 88


809 LINCOLN SUITES GOLD 95
1044 MUSEUM OF THE THIRD DIMENSION SILVER 139
8792 DESTINATION HOTEL & RESORTS GOLD 145
1526 INTERNATIONAL FINANCE SILVER 215

163

Additional Selection Criteria: First Attempt


_ What are my five ’GOLD’ clients closest to this competitor?
SELECT c.id, c.name, c.customer_grade
FROM competitors co, customers c
WHERE co.id=1
AND SDO_NN (
c.location, co.location,
’SDO_NUM_RES=5’)=’TRUE’
AND c.customer_grade = ’GOLD’;

809 LINCOLN SUITES GOLD


8792 DESTINATION HOTEL & RESORTS GOLD

_ Results may be incorrect!

_ The 5 closest customers are read, and then those of type ’GOLD’ are selected

164
Additional Selection Criteria: Correct Query
_ What are my five ’GOLD’ clients closest to this competitor?
SELECT c.id, c.name, c.customer_grade
FROM competitors co, customers c
WHERE co.id=1
AND SDO_NN (
c.location, co.location)=’TRUE’
AND c.customer_grade = ’GOLD’
AND ROWNUM <= 5;

809 LINCOLN SUITES GOLD


8792 DESTINATION HOTEL & RESORTS GOLD
810 HOTEL LOMBARDY GOLD
7821 RENAISSANCE MAYFLOWER HOTEL GOLD
6326 HOTEL LOMBARDY GOLD

165

Spatial Joins: SDO JOIN()

_ To find correlations between two tables


• Based on topology or distance

_ Compares all objects in a table with all those of another table

_ Requires an R-Tree index on each table

_ Technically implemented as a function that returns a table

166
SDO JOIN Function
SDO_JOIN( table_name-1, column_name-1,
table_name-2, column_name-2
[,’parameters’] [, preserve_join_order])
RETURN SDO_ROWIDSET;

SQL> DESC sdo_rowidset;


SDO_ROWIDSET TABLE OF MDSYS.SDO_ROWIDPAIR
Name Null? Type
-------------- -------- -----------
ROWID1 VARCHAR2(24)
ROWID2 VARCHAR2(24)

167

SDO JOIN Function Example: Topological Predicate


_ Associate to each GOLD customer the sales territory in which it is located
SELECT s.id, c.id, c.name
FROM customers c,
sales_regions s,
TABLE(SDO_JOIN(
’customers’, ’location’,
’sales_regions’, ’geom’,
’mask=inside’)) j
WHERE j.rowid1 = c.rowid
AND j.rowid2 = s.rowid
AND c.customer_grade = ’GOLD’
ORDER BY s.id, c.id;;

168
SDO JOIN Function Example: Distance Predicate
_ Find all gold customers who are less than 500 meters from one of our branches in San Francisco
SELECT DISTINCT c.id, c.name, b.id
FROM customers c,
branches b,
TABLE(SDO_JOIN(
’CUSTOMERS’, ’LOCATION’,
’BRANCHES’, ’LOCATION’,
’DISTANCE=500 UNIT=METER’)) j
WHERE j.rowid1 = c.rowid
AND j.rowid2 = b.rowid
AND c.customer_grade = ’GOLD’
AND b.city = ’SAN FRANCISCO’;

169

Spatial Functions

Unary Operations Binary Operations


Numerical Result SDO_AREA SDO_DISTANCE
SDO_LENGTH
Results in new object SDO_CENTROID SDO_DIFFERENCE
SDO_CONVEXHULL SDO_INTERSECTION
SDO_POINTONSURFACE SDO_UNION
SDO_BUFFER SDO_XOR

_ Objects must be in the same coordinate system!

170
Calculations: Length, Area and Distance

_ SDO_AREA(g): Calculates the area of a polygon

_ SDO_LENGTH(g): Calculates the length of a line (or the perimeter of a polygon)

_ SDO_DISTANCE(g1,g2): Calculates the distance between two objects

_ The unit of measure of the result can be specified

171

Calculations: Examples
_ What is the total area of Yellowstone National Park?
SELECT sdo_geom.sdo_area(geom,0.005,’unit=sq_km’)
FROM us_parks
WHERE name = ’Yellowstone NP’;

_ What is the length of the Mississippi river?


SELECT sdo_geom.sdo_length(geom,0.005,’unit=km’)
FROM us_rivers
WHERE name = ’Mississippi’;

_ What is the distance between Los Angeles and San Francisco?


SELECT sdo_geom.sdo_distance(a.location, b.location, 0.005, ’unit=mile’)
FROM us_cities a, us_cities b
WHERE a.city = ’Los Angeles’
AND b.city = ’San Francisco’;

172
Generating Objects
_ SDO_BUFFER(g,size): Generates a buffer size chosen
• The dimension (size) can be negative for an internal buffer

_ SDO_CENTROID(g): Calculates the center of gravity of a polygon


• May be outside the polygon!

_ SDO_CONVEXHULL(g): Generates the convex hull of the object (line or polygon)

_ SDO_MBR(g): Generates the bulk of the rectangle object (line or polygon)

173

Combining Objects

Union Intersection Difference XOR


_ SDO_UNION(g1,g2): Produces an object that represents the geometric union of the two given objects

_ SDO_INTERSECTION(g1,g2): Produces an object that represents the geometric intersection of the


two given objects

_ SDO_DIFFERENCE(g1,g2): Produces an object that represents the geometric difference of the two
given objects

_ SDO_XOR(g1,g2): Produces an object that represents the symmetric difference of the two given ob-
jects
• Equivalent to the union minus the intersection

174
Combining Objects: Example
_ What is the area occupied by the Yellowstone Park in the state it occupies?
SELECT s.state, sdo_geom.sdo_area (
sdo_geom.sdo_intersection (s.geom, p.geom, 0.5),
0.5, ’unit=sq_km’) area
FROM us_states s, us_parks p
WHERE SDO_ANYINTERACT (s.geom, p.geom) = ’TRUE’
AND p.name = ’Yellowstone NP’;

STATE AREA
-------------------------- ----------
Wyoming 8100.75346
Montana 640.295989
Idaho 154.659879;

175

Spatial Aggregation

_ Aggregate functions (like SUM, COUNT, AVG ...)

_ Operate on the set of objects

_ SDO_AGGR_MBR: Returns the rectangle of space around a set of objects

_ SDO_AGGR_UNION: Computes the union of a set of geometric objects

_ SDO_AGGR_CENTROID: Calculates the centroid of a set of objects

_ SDO_AGGR_CONVEXHULL: Calculates the convex hull around a set of objects

176
Aggregation Examples
_ Find the focal point of all our customers in Daly City
SELECT SDO_AGGR_CENTROID(SDOAGGRTYPE(location,0.5)) center
FROM customers
WHERE city = ’DALY CITY’;

_ Calculate the number of customers in each zip code, and calculate the focal point for these clients
SELECT COUNT(*), postal_code,
SDO_AGGR_CENTROID(SDOAGGRTYPE(location,0.5)) center
FROM customers
GROUP BY postal_code;

177

Spatial Databases: Conclusions


_ Location information is essential for an increasingly number of applications

_ GIS were initially used for managing spatial data

_ Since 1990s, major DBMS have been extended with spatial capabilities
• Oracle Spatial was first introduced into version 8g
• Open source implementations exist for many years
• SQL Server introduced spatial support in version 2008

_ Since the 1990s the Open Geo Spatial Consortium (OGC) has been working on defining standards
• These standards are also international standards (ISO)

_ Systems vary considerably on the support of standards

178

You might also like