PostGIS Raster : Extending PostgreSQL for The Support of ...

footmouthΔιαχείριση Δεδομένων

16 Δεκ 2012 (πριν από 4 χρόνια και 8 μήνες)

906 εμφανίσεις

Facult´e de Sciences Appliqu´ees
Service Ing´enierie Informatique
et de la D´ecision (CoDE)
PostGIS Raster:
Extending PostgreSQL for The Support of
Continuous Fields
Thi Ngoc Uyen DANG
Directeur:Prof.Esteban Zim
´
anyi
M´emoire pr´esent´ee en vue de l’obtention
du diplˆome d’Ing´enieur Informaticien
Ann´ee acad´emique 2011–2012
Acknowledgements
I would like to thank all people for helping me in this work and also for those who gave me advice
and ideas when i faced problems.Especially,i would like to thank my promoter Esteban Zimányi for
the help,support and responsibility of which he has shown throughout the year.I also would like to
thank Alejandro Vaisman,who worked with me from start to finish.
The last thanks will go to my family,for allowing me to study,to progress and realize my own
mistakes.
i
Abstract
Nowadays,in many application domains,complex analysis tasks often require to take geographical
information into account.However,there are very few attempts to support continuous fields,a phe-
nomena that are perceived as having a value at each point in space and/or time.Examples of such
phenomena include temperature,altitude or land use.This thesis is intended to introduce PostGIS
Raster,a new raster data type supporting continuous fields in PostgreSQL database.Later,based
on this primitive data type,a new composite type is build,along with a set of functions to take into
account the temporal aspect.Finally,an application that allows user to exploit the temporal feature
of such raster data is also provided.
ii
Contents
Acknowledgements
i
Abstract
ii
Contents
vi
List of Figures
1
1 Introduction
2
1.1 Context
............................................2
1.2 Goals
.............................................2
1.3 Organisation
.........................................3
2 Geographic Information Systems
4
2.1 Introduction
..........................................4
2.2 Elements of GIS
.......................................4
2.2.1 Features
........................................4
2.2.2 Attributes
.......................................5
2.2.3 Imagery
........................................6
2.2.4 Surfaces
........................................7
2.3 Geographic Data Representation
..............................9
2.3.1 Vector Images
.....................................9
2.3.2 Raster Images
....................................10
2.4 Geographic Information Organization
...........................11
2.4.1 Map Layers
......................................11
2.4.2 Data Theme
.....................................12
2.5 Georeference and Coordinate Systems
...........................13
2.5.1 Georeference
.....................................13
2.5.2 What Is a Coordinate System?
...........................13
2.6 GIS Applications
.......................................16
2.6.1 Crime Mapping
....................................16
2.6.2 GIS and Hydrogeology
................................16
2.6.3 Traditional Knowledge GIS
.............................18
3 Why PostGIS Raster?
19
3.1 Goals
.............................................19
3.1.1 Simplicity and Complementarity
..........................19
3.1.2 Transparent Integration with Vector
........................19
3.1.3 Storage Flexibility
..................................19
3.1.4 Interoperability
....................................19
3.2 PostGIS Raster Versus ORACLE GEORaster
.......................20
3.2.1 Architecture
.....................................20
3.2.2 Physical Storage
...................................21
3.2.3 Indexing
........................................23
iii
3.2.4 Overlapping Raster and Vector Layers
.......................24
3.2.5 Loading Raster Data
.................................24
3.2.6 Intersecting Raster and Vector Layers
.......................25
4 PostGIS Raster
27
4.1 Implementation
........................................27
4.2 Structure
...........................................27
4.3 Spatial Reference Identifier
.................................29
4.4 Raster Data
..........................................29
4.4.1 Usage
.........................................29
4.4.2 Cell Representation
.................................31
4.4.3 Zones and Regions
..................................34
4.4.4 Representing Features
................................35
4.5 Spatial Resolution
......................................37
4.6 Spatial Resolution Versus Scale
...............................38
4.7 Bands
.............................................38
4.8 Pixel Types
..........................................41
4.9 Nodata Values
........................................42
4.10 Blocks or Tiles
........................................42
4.11 Pyramids or Overviews
...................................43
4.11.1 Concept
........................................43
4.11.2 Creating Pyramids
..................................43
4.12 Masks
.............................................44
4.13 Arrangements of Raster Layers
...............................44
4.14 Data Formats
.........................................48
4.15 Physical Storage
.......................................49
4.15.1 Storing In-database Raster Versus Storing Out-database Raster
.........49
4.15.2 Registering Out-database Raster
..........................50
4.15.3 Storing In-database Raster
.............................50
4.16 Indexing
............................................53
4.17 Retrieving
...........................................54
4.17.1 In-database Raster Retrieving
............................54
4.17.2 Out-database Raster Retrieving
...........................54
4.18 Conversion
..........................................55
4.18.1 Raster to vector
...................................55
4.18.2 Vector to raster
....................................55
4.19 Intersection
..........................................56
4.20 Temporal Raster
.......................................59
4.20.1 Structure
.......................................59
4.20.2 Operations
......................................59
5 User Guide
62
5.1 Store and Manage Rasters
..................................62
5.1.1 Import Rasters
....................................62
5.1.2 Get and Set The Raster Properties
.........................62
5.1.3 Vector to Raster Conversion
.............................64
5.1.4 Raster to Vector Conversion
.............................64
5.2 Exporting Rasters
......................................65
5.3 Get Raster Statistics
.....................................65
5.4 Display Rasters
........................................65
5.5 Edit and Compute Rasters
.................................66
5.6 Convert Rasters to GDAL Format
.............................67
5.6.1 Raster to TIFF File
.................................67
5.6.2 Raster to JPEG File
.................................67
iv
5.6.3 Raster to PNG File
.................................68
5.7 Intersect Rasters with Vectors
................................68
5.7.1 Intersect Rasters with Points
............................68
5.7.2 Intersect Rasters with Lines
.............................69
5.7.3 Intersect Rasters with Polygons
...........................69
5.8 Aggregate Functions
.....................................70
5.9 Create a High Resolution Analysis Grid
..........................70
5.10 Create a Specialised Web or Desktop GIS Application
..................70
6 Application
72
6.1 Quantum GIS
.........................................72
6.1.1 Advantages
......................................72
6.1.2 Utilisation
.......................................73
6.2 Tools
..............................................74
6.2.1 Interface
........................................74
6.2.2 Color Legend
.....................................76
6.3 Implementation
........................................76
6.3.1 Time Travel
......................................77
6.3.2 Color Legend
.....................................81
7 Conclusion
83
Bibliography
84
Annex
87
A PostGIS Raster Utilisation
88
A.1 Dependencies Installation
..................................88
A.2 Installing and Configuring
..................................88
A.2.1 Linux
.........................................88
A.2.2 Windows
.......................................88
A.3 Creating Database
......................................88
B Python Plugin in QGIS
89
B.1 Necessary Files
........................................89
B.2 Python Code
.........................................89
B.2.1 __init__.py
.....................................89
B.2.2 Plugin.py
.......................................90
B.2.3 Resources.qrc
.....................................91
C Code Implementation
92
C.1 Temporal Raster Functions
.................................92
C.2 Temporal Raster Application
................................93
D Raster Sources
95
D.1 Remote Sensing
........................................95
D.1.1 Introduction
.....................................95
D.1.2 Applications
.....................................95
D.2 Photogrammetry
.......................................96
D.2.1 Introduction
.....................................96
D.2.2 Application
......................................97
D.3 Cartography
..........................................97
D.4 Digital Image Processing
...................................98
D.4.1 Introduction
.....................................98
D.4.2 Digital Camera Images
................................98
v
D.5 Geology,Geophysics and Geochemistry
...........................98
E Raster Resolution
101
F Continuous Surfaces
102
vi
List of Figures
2.1 Point feature [27].
......................................5
2.2 Line feature [27].
.......................................5
2.3 Polygon feature representing parcels [27].
.........................6
2.4 Grid of cells in raster data [27].
...............................6
2.5 Raster data [27].
.......................................6
2.6 Multiband raster data [27].
.................................7
2.7 Surface expressed by contour lines [27].
...........................7
2.8 Surface expressed by contour bands [27].
..........................8
2.9 Surface expressed by raster data [27].
............................8
2.10 Surface expressed by TIN layers [27].
............................8
2.11 Vector image at various scales.
...............................9
2.12 The original vector image is on the left side.The upper-right image illustrates magnifi-
cation of 7x as a vector image.The lower-right image illustrates the same magnification
as a raster image [29].
....................................10
2.13 Raster image in zooming [28].
................................11
2.14 Multiple layers geographic representation.
.........................12
2.15 Themes for a area [30].
....................................12
2.16 Georeferencing a geographic object [26].
..........................13
2.17 The location of the measured point (in red) is latitude plus 40 degrees and longitude
plus 50 degrees [26].
.....................................14
2.18 Parallels lines of latitude and meridians line of longitude [26].
..............14
2.19 2D Cartesian coordinate system.[26].
...........................15
2.20 3D Cartesian coordinate system [26].
............................15
2.21 Different methods for map projection [26].
.........................16
2.22 Distorsion in map projection [26].
..............................16
2.23 Mapping of homicides in Washington D.C.[18]
......................17
2.24 Groundwater level change of the High Plains Aquifer,1980-95 [31].
...........17
3.1 GeoRaster data architecture [3].
...............................20
3.2 PostGIS Raster data architecture.
.............................21
3.3 Physical storage of GeoRaster data [3].
...........................22
3.4 Physical storage of PostGIS Raster data.
..........................22
3.5 Oracle GeoRaster georeference approach [14].
.......................23
3.6 PostGIS Raster georeference approach [14].
........................23
4.1 PostGIS Raster implementation.
..............................29
4.2 Information representation using raster data [16].
.....................30
4.3 Basemap raster for road data [16].
.............................30
4.4 Surface map raster [16].
...................................31
4.5 Thematic map raster [16].
..................................31
4.6 Tree attribute [16].
......................................31
4.7 On the left side:cell values applied at the center point.On the right side:cell values
applied for the whole square.
................................32
4.8 Raster cell values [16].
....................................32
vii
4.9 Raster cell [16].
........................................33
4.10 Raster resolution [16].
....................................33
4.11 Pixel or cell location.
.....................................34
4.12 Raster extent [16].
......................................34
4.13 Raster zones and regions [32].
................................35
4.14 Discrete data represented in raster format [33].
......................35
4.15 Raster point representation [34].
..............................36
4.16 Raster line representation [34].
...............................36
4.17 Raster polygon representation [34].
.............................37
4.18 Raster elevation data for a part of the province of Quebec [8].
..............37
4.19 Spatial resolution.
......................................37
4.20 Raster in different spatial resolutions [11].
.........................38
4.21 Rasters at different scales [11].
...............................39
4.22 Same scaled rasters at different spatial resolution [11].
..................39
4.23 Raster bands.
.........................................39
4.24 Three main ways to display single-band raster [35].
....................40
4.25 Multi-band raster [35].
....................................40
4.26 RGB composite from a three-band raster [35].
.......................41
4.27 Multi-band raster image [35].
................................41
4.28 Raster tiles [23].
.......................................42
4.29 Pyramids (or Overviews) in PostGIS Raster [24].
.....................43
4.30 Pyramids at different levels and scales [36].
........................44
4.31 In the right side:The mask.In the left side:the mask with the transparency set to
70% overlays the digital elevation model raster [10].
...................45
4.32 Image warehouse of untiled and unrelated images (4 images) [6].
............45
4.33 Image warehouse of cars [22].
................................45
4.34 Irregular tiled raster coverage (36 tiles))[6].
........................46
4.35 Regular tiled raster coverage (36 tiles) [6].
.........................46
4.36 Rectangular regular tiled raster coverage (54 tiles) [6].
..................46
4.37 Tiled images (2 tables of 54 tiles) [6].
............................47
4.38 Raster object coverage (9 raster objects corresponding 9 rows in a raster table) [6].
..47
4.39 Vector to raster conversion.
.................................47
4.40 Raster to vector conversion.
.................................48
4.41 Image formed by the raster [17].
..............................48
4.42 Web application with out-database raster [23].
......................50
4.43 Storing in-database raster.
..................................51
4.44 In-database raster.
......................................53
4.45 Conversion from raster to vector [22].
............................55
4.46 Conversion from vector to raster [22].
............................55
4.47 Vector and vector intersection with a resulting vector layer [22].
.............56
4.48 Raster intersection paradigm [22].
..............................57
4.49 Vector and raster intersection with a resulting raster layer [22].
.............57
4.50 Vector and raster intersection with a resulting vector layer [22].
.............57
4.51 Raster and raster intersection with a resulting vector layer [22].
.............58
4.52 Mutual exclusive polygons intersection with a resulting vector layer [22].
........58
4.53 Mutual exclusive vector-raster intersection with a resulting raster layer [22].
......58
4.54 Mutual exclusive vector-raster intersection with a resulting vector layer [22].
......58
4.55 Mutual exclusive raster-raster intersection with a resulting raster layer [22].
......59
5.1 Raster circle [17].
.......................................64
5.2 Clipping raster effect [17].
..................................67
5.3 Algebra operation on rasters [23].
..............................67
5.4 Intersection of raster and geometric points [23].
......................68
5.5 Intersection of raster and roads [23].
............................69
viii
5.6 Intersection of raster polygons [23].
.............................69
5.7 Different temperature values in a polygon [23].
......................70
5.8 Gird of cells of USA map [23].
................................71
5.9 Web GIS application [23].
..................................71
6.1 QGIS interface.
........................................73
6.2 QGIS toolbars.
........................................73
6.3 PostGIS connection.
.....................................74
6.4 Temporal raster window.
...................................74
6.5 Time travel interface.
....................................75
6.6 Band area.
..........................................76
6.7 The temperature color legend.
................................76
6.8 The color legend interface.
..................................77
6.9 The loading map sequential approach.
...........................77
6.10 The loading map parallel approach.
.............................78
6.11 Maps representing world climate [7] are loaded once time.Their visibility is handled
by turning on/off the check boxes list.
...........................78
6.12 Media area.
..........................................79
6.13 Single band rasters.
......................................79
6.14 Maps representing world climate are loaded as single band rasters.They are turned
into color maps by loading a created color palette"worldclim.txt".
...........80
6.15 Map is loaded as multi band raster.
.............................80
6.16 Visualisation of band number 2 of a multi band map.
...................81
6.17 Maps with a color legend.
..................................82
D.1 Synthetic aperture radar image of Death Valley [37].
...................96
D.2 Relief map Sierra Nevada (Spain) [38].
...........................98
D.3 William Smith’s geologic map of England,Wales,and southern Scotland.Completed in
1815,it was the first national-scale geologic map and by far the most accurate of its
time [39].
...........................................99
D.4 Age of the sea floor.Much of the dating information comes from magnetic anomalies
[40].
..............................................100
E.1 Raster data represented at different resolution or cell sizes [11].
.............101
F.1 Elevation represented in raster format [33].
........................102
F.2 Source-concentration surface represented in raster format [33].
..............103
1
Chapter 1
Introduction
1.1 Context
Our daily life is full of situations that require us to make a choice among several alternative
solutions,so-called decision process.For example,we have from simple situations such as shopping,
voting to complicated situations that happen in government and business like resource management,
urban planning and regional planning.But on what do we base to make the best choice?
Due to the complexity of many decisions in government and business that require us to think of
different elements like stakeholders and categories,it leads to the need of using software for decision
making process.Examples of such applications include environmental impact-assessment,geographic
history,population and demographic studies,criminology and military planning.
Among the elements that influence decision making,geographical information represents a relevant
source to decision makers.Whether the issue is the location of a new public or the development of
a new project,decision makers should consider such geographic information as location,character of
environment and landscapes.
Furthermore,in the private sectors,a large group of companies use geographic information as a
tool for their locational decision making.These include retail marketing chains (for example,Dayton-
Hudson,a major retail firm headquartered in Minneapolis),railroads (for example,Southern Pacific
Railroad’s land division),electric power and gas utilities,international import-export firms,trans-
portation and travel service organizations,publishing firms and real estate planners and investors
[19].
1.2 Goals
Not all sources of geographic information are reliable.The precision of geographic information can
be influenced indirectly through scholarly publications.These publications tend to influence decision
makers’s understanding about climate issues.So it is important to have a useful tool,such as a
geographic information system,that helps user to handle directly geographic information and thus
guarantees the correctness of information.
Most of the current geographic information systems provide a vector type for manipulating geo-
graphic information.However,there are very few attempts to support a data type that describes the
distribution of physical phenomena that change continuously in time and space,so-called continuous
fields.Example of such phenomena are temperature,pressure,precipitation,land elevation,land use,
population density and etc.
The main contribution of this thesis is to introduce a new data type PostGIS Raster that supports
continuous fields in PostgreSQL database.In addition,it also describes an application that allows
user to exploit the temporal feature of geographic data using PostGIS Raster.
2
1.3 Organisation
This thesis is organized as follows:Section 2 starts with GIS and its applications.Section 3 describes
the goals of PostGIS Raster,along with some comparisons with the existed plugin supporting raster
Oracle GeoRaster to give users more motivations.The following section describes in detail PostGIS
Raster structure and how this one is stored,indexed,retrieved and overlapped.Section 5 provides
guides for users about utilisation of some PostGIS Raster functions.Section 6 extends PostGIS
Raster by adding temporal feature and describes a set of operators related to aspect temporal.An
implemented application that enhances Quantum Geographic Information System (QGIS) to exploit
the temporal feature of the PostGIS Raster data will be shown in the next section.Finally,Section 8
concludes our work and point out to future perspectives.
3
Chapter 2
Geographic Information Systems
Geographic data is stored,manipulated,analyzed by a Geographic Information System (GIS).This
section describes what is a GIS and different types of geographic data such as raster and vector.Then
there are a short introduction to some interesting GIS applications.
2.1 Introduction
Geographic data is much more than electronic pictures.The geographic data describes not only
real objects and relations in space but contains also spatial reference,geometric and thematic infor-
mation.Nevertheless,to fully exploit these characteristics,an additional tool is needed.A geographic
information system is an information system designed to integrates,stores,edits,analyzes,shares and
displays geographic information for decision makers.GIS applications are tools that allow users to
create interactive queries,analyze spatial information,edit data in maps and present the results of all
these operations.
A GIS is the merging of cartography,statistical analysis and database technology.It is custom-
designed for an organization.A GIS developed for jurisdiction or enterprise purposes may not be
necessarily interoperable or compatible with a GIS that has been developed for some other applications.
2.2 Elements of GIS
All GISs that provide rich behaviors for representing and managing geographic information are based
on four fundamental elements:
• Features
• Attributes
• Imagery
• Surfaces
2.2.1 Features
A feature is used to describe an entity in space-time.Besides a number of additional features,
common geographic features are collections of points,lines and polygons.They represent discrete
things that occur naturally (such as rivers and vegetation) to those of constructions (such as roads,
pipelines,wells and buildings) or subdivisions of land (such as counties,political divisions and land
parcels).
Points
Points define discrete things that are too small to be depicted as lines or areas like locations,
telephone poles and stream gauges.Points can also represent address locations,Global Positioning
System (GPS) coordinates or mountain peaks.
4
Figure 2.1:Point feature [27].
Lines
Lines represent the shape of geographic objects that are too narrow to be depicted as areas (such
as street centerlines and streams).Lines are also used to represent features that have length but no
area such as contour lines and administrative boundaries.
Figure 2.2:Line feature [27].
Polygons
Polygons are enclosed areas that represent the shape of large objects such as states,counties,
parcels,soil types and landuse zones.
2.2.2 Attributes
Geographic data transmits descriptive information through symbols,colors,and labels.For example:
• Roads are displayed based on road class.For instance,line symbols represent divided highways,
main streets,residential streets,unpaved roads and trails.
• Blue is used to indicate water and streams.
• City streets are labeled with their name and often some address.
• Special point and line symbols denote specific features such as rail lines,airports,schools,hos-
pitals and special facilities.
5
Figure 2.3:Polygon feature representing parcels [27].
2.2.3 Imagery
Imagery is organized as a raster data type composed of cells organized in a grid of rows and
columns.In addition to cell values,a raster includes also its cell size and a reference coordinate (the
upper left or lower left corner of the grid).These properties enable a raster to be described by a series
of cell values starting in the upper left row.Each cell location can be automatically located using the
reference coordinate,the cell size and the number of rows and columns.
Figure 2.4:Grid of cells in raster data [27].
Aerial imagery is a raster data structure obtained from various sensors carried in satellites and
aircraft.Digital orthophotography is a typical imagery sources that comes from cameras.
Figure 2.5:Raster data [27].
Imagery is also used to collect data in both the visible and nonvisible portions of the electromagnetic
spectrum.One system is the multispectral scanner carried in landsat satellites that records imagery
in seven bands along with the electromagnetic spectrum.The measures for each band are recorded in
a separate grid.The stack of seven grids makes up a multiband image.
6
Figure 2.6:Multiband raster data [27].
2.2.4 Surfaces
A surface describes a phenomenon that has a value for each point in space.For example,surface
elevation is a continuous area such that every spatial location has a value for ground elevation above
sea level.Other examples include surface rainfall,surface pollution concentration and etc.
The major problem in surface representation is that it is impossible to represent all values for all
locations of a area.Various alternatives exist for representing such surfaces using either features or
rasters.Here are some alternative solutions for surface representation:
Contour Lines
Contour lines:Isolines represent a set of points having an equal value,such as elevation contours.
Figure 2.7:Surface expressed by contour lines [27].
Contour Bands
Contour bands:Each band describes a specified range of values.An area,where each point value
within it belong to a band,will be represented by a corresponding color.Example of such band
consists of all average annual rainfall between 25 cm and 50 cm per year.
Raster Data
Raster data:A matrix of cells where each cell value represents a measure of each point in space.
For example,digital elevation models (DEMs) represented by grids of squares,are frequently used to
describe surface elevation.
Triangulated Irregular Network
A triangulated irregular network (TIN):A data structure represents surfaces as a connected network
of triangles.Each triangle node has x,y coordinates and a surface value z.
The raster and TIN representations can be used to estimate the surface value for any location
using interpolation.
7
Figure 2.8:Surface expressed by contour bands [27].
Figure 2.9:Surface expressed by raster data [27].
Figure 2.10:Surface expressed by TIN layers [27].
8
2.3 Geographic Data Representation
Traditionally,real objects in geographic data can be stored into two forms:discrete objects (such
as roads,houses,trees) using vector and continuous fields (such as rainfall amount,elevations) using
raster.A new hybrid method of storing data identifies point clouds,combines three-dimensional points
with RGB information at each point and returns a 3D color image.However,the following Section
focus only on vector and raster representation.
2.3.1 Vector Images
Vector images use geometrical primitives like points,lines,curves and polygons,which are all based
on mathematical expressions to represent images in computer graphics.
Each geometric primitive is presented by lines and surfaces.All lines,individually,are defined by
characteristic points that define its equation.These characteristic points form a vector.Thus,the
vector representation is expressed in terms of characters of line and color of the surface.This leads
to the notion of drawing multiple layers where planes curves can be overlaid.This phenomenon can
not happen in raster representation since there is only one layer,then each new point overwrites the
previous point.
The advantage of a vector representation is the delicacy and precision of the results.Every line
can be edited very quickly and all at once.Indeed,this representation involves a limited number of
graphical objects,so these graphics files are very light.
Resolution
As vector images are defined by mathematical expressions,they can be zoomed in or out without
any loss of quality.Concretely,the mathematical description of the object is simply multiplied by a
zooming factor.For example a 1 inch square object will be multiplied by a factor of 2 in order to
double in size.The mathematical expression is thus recalculated to produce an object twice the size of
the original.So vector images can be output at any resolution that a printer is capable of producing.
Unlike raster images,quality of vector images is not limited by scanning resolution.This is a big
reason that vector images are so popular for clip art.
Figure 2.11:Vector image at various scales.
Color
Since vector images are composed of objects,coloring vector objects is similar to coloring with crayons
in a coloring book.Using drawing program,users can easily change the color of individual objects
by clicking inside this object and define its color,along with defining width of lines.Coloring vector
images is much easier than coloring raster images.
File Size
Storing vector images need to keep only mathematical descriptions.For this reason vector files are
very small in file size.A 2-inch by 4-inch logo based vector will be the same files size as a 2-foot by
9
4-foot logo.The file size is the same because the only difference in file is one number defining the size
of the file.Most vector-based logos are going to be under 100 KB.For this reason,vector files are
ideally suited for transfer over the Internet.
File Formats
Common vector formats include EPS (Encapsulated PostScript),WMF (Windows Metafile),AI
(Adobe Illustrator),CDR (CorelDraw),DXF (AutoCAD),SVG (Scalable Vector Graphics) and PLT
(Hewlett Packard Graphics Language Plot File).
Modern displays and printers are raster devices,vector formats have to be converted to raster for-
mat before they can be displayed or printed.Or in graphic work,devices such as cameras and scanners
produce essentially continuous-tone raster graphics that are impractical to convert into vectors.So
an image editor will operate on the pixels rather than on drawing objects defined by mathematical
expressions.
2.3.2 Raster Images
A raster image (or bitmap) is a 2-dimensional array data structure representing a rectangular grid
of pixels,or dots or points of color.A raster image is characterized by its width and height in pixels
and by the number of bits per pixel.This number determines the number of colors can be represented
in the image.
Resolution
The resolution of a raster image is expressed in terms of the dots per inch or dpi.Printer resolution
is also measured in dots per inch.Typical desktop laser printers print at 300 - 600 dpi.Printers with
higher dpi are capable of producing smoother and cleaner output.Nevertheless,the quality of a raster
image depends on its resolution (dpi) and the capabilities of the printing technology [9].For example,
a 300 dpi raster image will output at the same quality on a 300 dpi laser printer as on a 2,500 dpi
printer.By increasing size of a 300 dpi raster image,the tiny pixel squares will become bigger and
create jaggy edges as no additional information is added.In this case,the raster image losses quality.
Exammple in Figure
2.12
shows the jaggy edges of raster image through zooming effect.In contrast,
When decreasing the size,the squares get smaller and the image retains its original edge without
jaggies.
Figure 2.12:The original vector image is on the left side.The upper-right image illustrates magnifi-
cation of 7x as a vector image.The lower-right image illustrates the same magnification as a raster
image [29].
Color
As raster images are reproduction of real world,a large number of colors will be required to render
raster images accurate as their original sources.For example,if scanner works at 24-bit color (16
million colors),most human eyes could not distinct the difference between the original image and
the scanned raster image.In contrast,if a smaller color palette with 256 colors is used,it would be
10
impossible to reproduce the original colors.To get around this,scanners use a process called dithering
to approximate colors that don’t occur in the current color palette.
Figure 2.13:Raster image in zooming [28].
The biggest disadvantage when using raster images locates at editing and manipulating image
colors.As vector images are object-oriented while raster images are pixel oriented,in order to change
pixel colors,a specific color or range of colors must be isolated from the rest to be changed.This work
is quite a challenge for even experienced users.
File Size
For each raster image file,a large amount of information,including the exact location and color of
each pixel in the grid,needs to be kept track to reproduce the image.This results in large file sizes
for raster images.Higher resolutions (dpi) and greater color depths (the number of bits per pixel)
produce bigger file sizes.A typical 2"by 3"150 dpi black and white raster image logo will be less than
70 KB in file size.The same file saved as a 300 dpi 24-bit (millions of colors) raster image logo might
be 100 times larger (over 7 MB).When creating and scanning raster images,raster file size becomes
a real issue,as big files tend to make computer processor and hard drive work overtime.Transferring
big files (over 1 MB) over the Internet requires a high speed Internet connection on both ends for
timely uploads and downloads.
In despite of these disadvantages,raster images are more practically than vector images as they
are viewable via monitors or other display medium and it is impossible in practice to obtain vector
images from a photo.
File Formats
Common raster image formats include BMP (Windows Bitmap),PCX (Paintbrush),TIFF (Tag
Interleave Format),JPEG (Joint Photographics Expert Group),GIF (Graphics Interchange Format)
,PNG (Portable Network Graphic),PSD (Adobe PhotoShop) and CPT (Corel Photo PAINT).
Perfect graphical tools will combine images from vector and raster sources and provide editing
tools for both,since some parts of an image could come from a camera source and others could have
been drawn using vector tools.
2.4 Geographic Information Organization
2.4.1 Map Layers
GIS organizes geographic information in terms of layers.A layer is a representation of geographic
data on a map.For example,vector layers are collections of simple geographic elements of same type
such as a road network (represented by lines),parcel boundaries (polygons),soil types (polygons),
well locations (points) and so on.Examples of raster layers include an elevation surface,satellite
imagery,land use and etc.Within the data frame,each layer that represents a specific geographic
data is displayed and overlaid by the other layers to form a significant geographic representation in
real world [5].
11
Figure 2.14:Multiple layers geographic representation.
2.4.2 Data Theme
Based on the data themes concept,geographic information in GIS could be partitioned into a series
of logical information layers rather than a random collection of objects.Hence,users can organize
information in various data themes that described the distribution of a phenomenon and how each
one should be represented across a geographic extent.
Many data themes are best represented by a single layer such as soil types or well locations.Other
themes like a transportation framework,are represented by multiple layers,where each feature (such
as streets,intersections,bridges,highway ramps,railroads and so on) is represented by a separate
layer.
Figure 2.15:Themes for a area [30].
Each GIS can contain multiple themes for a common geographic area.The collection of themes
acts as a stack of layers.Each theme can be managed as an information set independent of other
themes.Each one has its own representation and could be a collection of points,lines,polygons,
surfaces,rasters and so on.Because layers are spatially referenced,maybe they overlap one another
and can be displayed in a common map display.So GIS analysis operations like polygon intersection
can combine information between layers to discover and work with the derived spatial relationships.
The concept of layer-based data themes implies that:
• All layers must be georeferenced to a place on the Earth so that they can be combined together.
The georeferencing process is accomplished by defining the geographic coordinate system for
each dataset.
• Layers can be combined in many ways such as following the ordered layers in a map or by
employing operators or commands.Geographic operators can work with the relationships both
12
within and between layers.
• GIS layers can be combined from many sources and many users.In fact,most users are depen-
dent on one another for portions of the data they want to use.So interoperability becomes a
fundamental feature in GIS.
2.5 Georeference and Coordinate Systems
2.5.1 Georeference
All elements in a map have a specific geographic location and extent that enable them to be
located on the Earth’s surface.So to georeference something means to describe its existence on the
Earth’s surface.The term is used when establishing the relation between raster or vector images and
coordinates or when determining the spatial location of other geographical features.Examples would
include establishing the correct position of an aerial photograph within a map or finding the geo-
graphical coordinates of street address.The georeferencing procedure is thus imperative for modeling
geographical data in the field of geographic information systems.
Figure 2.16:Georeferencing a geographic object [26].
2.5.2 What Is a Coordinate System?
A coordinate system is a system that uses coordinates to uniquely determine the location of a point
or other geographic element on the Earth.There are two common types of coordinate system used in
GIS:
• A global or spherical coordinate system such as latitude-longitude.This system is often referred
to as geographic coordinate system.
• A projected coordinate system based on map projection.There exist different map projections
that provides various mechanisms to project maps of the Earth’s spherical surface onto a two-
dimensional Cartesian coordinate plane.Projected coordinate systems are also referred to as
map projections.
Geographic Coordinate Systems
A geographic coordinate system is a coordinate system that enables every location on the Earth
to be specified by a set of numbers.The coordinates are often chosen such that one number repre-
sents vertical position and two or three numbers represent horizontal position.A common choice of
coordinates is latitude and longitude.
Latitude and Longitude are the angles from the center of the Earth to a measured point on the
Earth’s surface.
Latitude measures are angles in a north-south direction.The equator is at an angle of 0.Often,
the northern hemisphere has positive measures of latitude and the southern hemisphere has negative
13
measures of latitude.Longitude measures are angles in an east-west direction.Longitude measures
are traditionally based on the Prime Meridian,which is an imaginary line running from the North
Pole through Greenwich,England to the South Pole.This line has longitude as 0.West of the Prime
Meridian is often recorded as negative longitude and east is recorded as positive.
Figure 2.17:The location of the measured point (in red) is latitude plus 40 degrees and longitude plus
50 degrees [26].
Although longitude and latitude can locate exactly any positions on the surface of the globe,they
are not uniform in units.Only along the equator,the distance represented by one degree of longitude
approximate the distance represented by one degree of latitude.This is because the equator is the
only parallel line of latitude that is as large as a meridian line of longitude.
Figure 2.18:Parallels lines of latitude and meridians line of longitude [26].
Above and below the equator,the circles defining the parallel lines of latitude get gradually smaller
until they become a single point at the North and South Poles.As the meridians converge toward
the poles,the distance represented by one degree of longitude decreases to zero.For example,one
degree of longitude at the equator equals 111.321 km,while at 60

latitude,it is only 55.802 km.Since
degrees of latitude and longitude don’t have a standard length,distances or areas can not be measured
accurately or display the data easily on a flat map.Efficient GIS analysis and mapping applications
require a more stable coordinate framework,which is provided by projected coordinate systems.
Projected Coordinate Systems using Cartesian coordinates
Projected coordinate systems are any coordinate system designed for a flat surface.2D and
3D Cartesian coordinate systems provide the mechanism for describing the geographic location of
geographic objects using x,y and z values.The x,y measurements represent the position on the
Earth’s surface and the z represents the height above or below sea level.
2D Cartesian coordinate system is a coordinate system that uses two axes:one horizontal x
representing east-west and one vertical y representing north-south.The point at which these axes
intersect is the origin.Locations of objects are defined relatively to the origin using the notation
14
(x,y),where x refers to the distance along the horizontal axis and y refers to the distance along the
vertical axis.The origin is defined as (0,0).For example,in Figure
2.19
,the notation (4,3) gives a
point that is four units over in x and three units up in y from the origin.
Figure 2.19:2D Cartesian coordinate system.[26].
3D Cartesian coordinate system is a coordinate system that uses also a z value to measure
elevation above or below sea level.The notation (2,3,4) in Figure
2.20
records a point that is two
units over in x and three units in y from the origin and whose elevation is 4 units above the Earth’s
surface such as 4 meters above sea level.
Figure 2.20:3D Cartesian coordinate system [26].
Since the Earth is spherical,a challenge faced by cartographers is how to represent the real world
using a flat coordinate system.The process of flattening the Earth is called projection,hence the term
map projection is resulted.Examples of various methods for map projection are illustrated in Figure
2.21
.
Unlike a geographic coordinate system,a projected coordinate system has constant lengths,angles
and areas across the two dimensions.However,all map projections representing the Earth’s surface
create distortions in some aspect of distance,area,shape,scale or direction (Figure
2.22
).Depend on
user application,many map projections are designed for specific purposes.One map projection might
be used for preserving shape while another might be used for preserving the area.
These properties of the map projection are important parameters in the definition of the coordinate
system for each GIS dataset and each map.With these properties,the geographic locations of dataset
elements can be reprojected and transformed into an appropriate coordinate system.As a result,it’s
possible to integrate and combine information from multiple GIS layers.This is a fundamental GIS
capability as accurate location forms the basis for almost all GIS operations.
15
Figure 2.21:Different methods for map projection [26].
Figure 2.22:Distorsion in map projection [26].
2.6 GIS Applications
2.6.1 Crime Mapping
Crime mapping is an application used by analysts in law enforcement agencies to map,visualize and
analyse crime incident.Using Geographic Information Systems,crime analysts can overlay different
datasets (such as census demographics,locations of pawn shops,schools and etc.) to identify crime
hot spots,to better understand the underlying causes of crime and thus to devise strategies dealing
with the problem,along with other trends and patterns [18].
2.6.2 GIS and Hydrogeology
Nowadays,with increasing demand on surface water resources and 98% of the world’s available
fresh water is groundwater,it implies that the demand for groundwater will also increase.In fact,in
some places,this resource has already been seriously exploited and even mismanaged (Figure
2.24
).
Hence,more knowledge about its disposition is quickly required.
Hydrogeology,a subset of hydrology,is concerned with the way in which groundwater is stored and
its availability for use.Not as apparent as surface water flows,the description of groundwater is a more
complex task than that of surface water.Groundwater is water located under the Earth’s surface.
Groundwater moves much more slowly than surface water and is 3-dimensional flow (2-dimensional in
the case of surface water flow).Groundwater flow is a function of geology and head.That means it
flows from higher head to lower head and its flow path can be predicted by geology.
Head values,geology and groundwater flow direction are the features which may be presented in
GIS.Then hydrogeology is especially suited to GIS because groundwater can be characterized spatially
in GIS and analyzed by scientists.For example,in a simple application of GIS,the effect of a new
feature can be studied on the groundwater.The results of such study then can be used by decision
makers to determine whether or not to proceed with drilling.
16
Figure 2.23:Mapping of homicides in Washington D.C.[18]
Figure 2.24:Groundwater level change of the High Plains Aquifer,1980-95 [31].
17
2.6.3 Traditional Knowledge GIS
Traditional knowledge GIS is designed to document and utilize local knowledge of communities
around the world.Traditional knowledge includes the experiences of a particular culture or society.
Traditional knowledge GIS is richer than ordinary maps in the sense that they express environmental
and spiritual relationships among real and conceptual entities.
Cultural preservation is the principal application of a traditional knowledge GIS.Its central feature
is language revitalization.Bilingual visual and audible maps are used to describe oral traditions and
historical information of significant cultures on various scales.
18
Chapter 3
Why PostGIS Raster?
ORACLE GEORaster is a component that supports continuous fields in ORACLE.Nevertheless,
it sounds complex and cumbersome for inexperienced users.PostGIS Raster is thus designed to
overcome these limitations.This fact will be demonstrated through PostGIS Raster goals and how
Oracle GeoRaster and PostGIS Raster are different in architecture,physical storage,indexing and
overlapping,along with some principal operations when working with raster data.
3.1 Goals
PostGIS Raster,an extension of PostGIS,implements a new raster data type that adapts to
diversity of applications by achieving four objectives [6]:
3.1.1 Simplicity and Complementarity
Seen a raster type is designed to adapt to diversity of applications,then the first objective of
PostGIS Raster is to provide a simple loader to import rasters into database.The loader allows users
to load a single raster or a set of rasters once.This new data type complements the existing PostGIS
vector type in the sense that it works in the same way as the one of vector type,but instead of
association with geometric elements,raster relates to a matricial data structure.
3.1.2 Transparent Integration with Vector
PostGIS Raster provides a set of similar operators and functions with those available for vector
type to support raster.In this way,users can use their knowledge about vector type to expect similar
behaviors when using these operator and functions.Thus it enhances user’s interaction with geospatial
applications.
About developers,a single SQL paradigm for both raster and vector types will help them write
better GIS applications.Developers will build a unique graphical user interface for both raster and
vector data.
3.1.3 Storage Flexibility
In addition to traditional storage (in-database storage),PostGIS Raster allows user to simply register
only metadata of raster images stored in the filesystem (out-database storage).When retrieving these
out-database rasters from database,they are accessed directly from the filesystem.
3.1.4 Interoperability
PostGIS Raster uses Geospatial Data Abstraction Library (GDAL) [25] to load rasters into the
database and to work with out-database rasters.With GDAL,PostGIS Raster can work with nearly
a hundred file formats
1
).
1
http://www.gdal.org/formats_list.html
.
19
These additional functionalities make PostGIS Raster more than just a new raster format but also
a necessary complement to PostGIS.
3.2 PostGIS Raster Versus ORACLE GEORaster
3.2.1 Architecture
General Architecture
In general,tools supporting raster data include five components [3]:
Characteristics
Oracle GeoRASTER
PostGIS Raster
SQL API
Standard SQL
A single set of SQL
functions for vector and
raster data
Accessing to
raster data
Java,Oracle Call Interface (OCI),Oracle C++Call
Interface (OCCI),and GeoRaster SQL API
PostGIS SQL API
Viewing tools
Oracle Fusion Middleware MapViewer,Open-
JUMP
QGIS and gvGIS
Import/Export
data
Extract,transform and load (ETL)
GDAL allows loading a
single raster or a set of
rasters
Data formats
Six standard image formats:GeoTIFF,DEM,
PNG,BMP,GIF,and JPEG
As many image formats
as GDAL does [21]
Data Architecture
In Oracle GeoRASTER,each image is stored as a single object of type SDO_GEORASTER.AGeoRaster
table is a table which has at least one data column of type SDO_GEORASTER.SDO_GEORASTER objects
include metadata and information about how to retrieve GeoRaster data which is stored in another
table,called a Raster Data Table (RDT).GeoRaster data is an object of type SDO_RASTER which
includes a Binary Larger Object (BLOB) column called RASTERBLOCK storing the raster blocks (The
core of raster data can be partioned into small blocks for optimal storage and retrieval).A block is
also called a tile [3].
Figure 3.1:GeoRaster data architecture [3].
Other information associated with the GeoRaster objects can be stored in separate columns or
tables,such as a Value Attribute Table (VAT).
More simply,PostGIS Raster uses only one type raster to store a raster image.Like the geometry
type,the raster type is a complex type,embedding information about raster itself with its georeference.
In PostGIS Raster,there is no table for storing the raster data (like Oracle Spatial SDO_RASTER)
and another table for storing the georeference and the metadata (like Oracle Spatial SDO_GEORASTER).
20
Figure 3.2:PostGIS Raster data architecture.
Everything is stored in a single attribute and raster attributes composing a table are not necessarily
related to each other to form a significant coverage.
PostGIS Raster uses in addition a raster_columns table to contain information about which
tables have a raster column and the metadata (pixeltype,block size,nodata value and etc.) of the
rasters in these columns.
3.2.2 Physical Storage
GeoRaster data consists of a multidimensional matrix of cells and the GeoRaster metadata.The
multidimensional matrix is blocked into small blocks.A block (or tile) is stored as a BLOB and a
geometry object of type SDO\_GEOMETRY is used to define the spatial extent (footprint) of the block.
Each block and information related to that block are stored in one row.Thus for storing an image
having size greater than block size,at least two rows are necessary to be used in Oracle database table
[3].
To do this,GeoRaster requires two types of object:
• The SDO_GEORASTER type contains spatial extent geometry and metadata.
• The SDO_RASTER contains a BOLB storing a block and the block information.
Each SDO_GEOMETRY data has a pair of attributes (rasterDataTable,rasterID) that identify the
RDT and the rows within the RDT that are used to store the raster data.
For Example,Figure
3.3
shows the storage of GeoRaster object used for an image of Boston,
Massachusetts,where:
• Each row in the table of city images contains information about the image for a specific city
(such as Boston),including an SDO_GEORASTER object.
• The SDO_GEORASTER object includes the spatial extent geometry covering the entire area of the
image,the metadata,the raster ID and the name of the raster data table associated with this
image.
• Each row in the raster data table contains information about a block (or tile) of the image,
including the block’s minimum bounding rectangle (MBR) and image data (stored as a BLOB).
A MBR is defined as a single rectangle that minimally encloses a geometry or a collection of
geometries.
In PostGIS Raster,the raster type is a complex type composed of many attributes like attribute,
georeference information,band information and band data.Thus a single raster attribute can contain
all information about raster itself (width,height,number of bands,pixel type for each band,nodata
21
Figure 3.3:Physical storage of GeoRaster data [3].
value and data values for each band) with its georeference (pixel type,upper left pixel center,rotation
and spatial reference system identifier (SRID)).
A single raster attribute may be composed of many bands having a common size,pixel size and
georeference.The storage used for raster bands is band sequential (BSQ) in which each band has its
pixel type and its nodata value.
One table with a column of type raster is called raster coverage.One table row with a column of
type raster is called tile.Thus there are no differences between rasters and tiles.A tile is a raster and
a raster is a tile in which each tile has all that are necessary to do basic raster operations.
Figure 3.4:Physical storage of PostGIS Raster data.
Another important advantage of PostGIS Raster over Oracle GeoRaster is the georeferencing
approach [14].As Oracle GeoRaster uses a one-georeference-by-layer georeference schema instead of
one-georeference-by-raster one,so non-continuous raster data cannot be stored in the same raster data
table.That means that Oracle GeoRaster requires one raster data table for each raster file loaded
when these raster files are from irregular raster coverage.In contrast,PostGIS Raster allows only one
table for all kinds of raster coverages,regular or not.
In addition to this traditional storing method (storing in-database raster),PostGIS Raster enables
user to simply register basic metadata (path to the actual file,pixeltype,with,height,georeference)
of images stored in the file system,without having to load their data values into the database.This is
22
Figure 3.5:Oracle GeoRaster georeference approach [14].
Figure 3.6:PostGIS Raster georeference approach [14].
referred to as storing out-database raster.With the second method,web or desktop applications may
access out-database rasters directly fromthe filesystem(such as JPEGfiles) and use most transparently
PostGIS Raster operators and functions on those rasters.
3.2.3 Indexing
The most important index is created on a GeoRaster object is a spatial index on the spatial extent
geometry of the GeoRaster object.Oracle GeoRaster creates spatial indexes over the footprint of raster
data while PostGIS Raster creates GiST indexes over the raster data itself.In Oracle GeoRaster,
spatial operations (like intersection) can only be done with the MBR of the data as the indexes are
created over the spatial extent.In PostGIS Raster,user can do really complex operations with raster
data like getting a set of geometry and geometry value froma given raster band (ST_DumAsPolygons()
function).Then,creating indexes over these raster data has more sense [15].
PostGIS Raster uses GDAL driver to calculate the georeferenced coordinates for upper and lower
corners (the spatial extent or footprint) of a raster.In this case,its spatial extent is the enclosing
geometry.Nervertheless,this is not necessarily in this way for Oracle GeoRaster.
In GeoRaster,one of the prerequisites for creating a spatial index over a geometry column is
that the USER_SDO_GEOM_METADATA view must contain an entry with the dimensions and coordinate
boundary information for the table column to be spatially indexed.So the following code will create
spatial index on the spatial extent geometry of the GeoRaster objects stored in table spain_images:
DELETE FROM user_sdo_geom_metadata
WHERE table_name = ’spain_images’
AND column_name = ’IMAGE.SPATIALEXTENT’;
INSERT INTO user_sdo_geom_metadata
VALUES (’spain_images’,’IMAGE.SPATIALEXTENT’,
SDO_DIM_ARRAY(SDO_DIM_ELEMENT(’X’,-180,180,.00000005),
SDO_DIM_ELEMENT(’Y’,-90,90,.00000005)),4326);
23
DROP INDEX spain_images_idx;
CREATE INDEX spain_images_idx
ON spain_images(image.spatialExtent)
INDEXTYPE IS mdsys.spatial_index;
In contrast,PostGIS Raster loads raster data and creates spatial index using simply these two
commands:
python raster2pgsql.py -r *.tif -t spain_images -s 4326 -k 50x50 -I -o spain.sql
psql -d postgis_db -f spain.sql
The first command uses Python loader to import a set of raster images into raster table spain_images
(option -t).Option -I is used to create indexes over these rasters.All necessary code is created and
registered in a SQL file spain.sql (option -o).Then,the second command will execute spain.sql
in PostGIS database.
3.2.4 Overlapping Raster and Vector Layers
Each spatial instance has a spatial reference identifier (SRID).However,the result of any spatial
method from two spatial instances is valid only if those instances that have the same SRID.It is the
same in the case of overlapping operation between vector and raster data.
To reset SRID of a geometry object,GeoRaster uses sdo_cs.transform() function [14]:
SELECT sdo_cs.transform(geom,srid_number) geom FROM geom_table;
In the same way in PostGIS Raster:
SELECT ST_Transform(the_geom,srid_number)) FROM geom_table;
3.2.5 Loading Raster Data
Loading Using Oracle GeoRaster
To load raster image into GeoRaster,firstly users need to create tables to store the raster data.
One table stores the metadata and another one stores the data [14]:
CREATE TABLE spain_images (image_id NUMBER PRIMARY KEY,
image_description VARCHAR2(50),image SDO_GEORASTER);
CREATE TABLE spain_images_rdt OF SDO_RASTER
(PRIMARY KEY (rasterID,pyramidLevel,bandBlockNumber,rowBlockNumber,
columnBlockNumber))
TABLESPACE users LOB(rasterBlock) STORE AS SECUREFILE lobseg (NOCACHE);
Then,the image is loaded using PL/SQL code:
DECLARE
geor SDO_GEORASTER;
BEGIN
-- Initialize an empty GeoRaster object into which the external image
-- is to be imported.
INSERT INTO spain_images
VALUES( 1,’Spain_TIFF_1’,sdo_geor.init(’spain_images_rdt’) );
-- Import the TIFF image.
SELECT image INTO geor FROM spain_images
WHERE image_id = 1 FOR UPDATE;
24
sdo_geor.importFrom(geor,’blocksize=(256,256)’,’TIFF’,’file’,’srtm_new.tif’);
UPDATE spain_images SET image = geor WHERE image_id = 1;
END;
The same operation is repeated for every image file.If these images forma non-continuous coverage,
two new tables are needed for each image file.
Loading Using PostGIS Raster
When loading raster data by using GDAL driver,the loader creates all that are necessary to store
the raster data into a SQL file.It consists of creating the needed tables,the indexes (if it is specified)
and inserting raster data into the tables.A single or a set of raster images can be loaded all only once.
Example:
python raster2pgsql.py -r path\*.tif -t srtm_tiled -s 4326 -k 50x50 -I -M
-o srtm.sql
Next step is to execute the srtm.sql file using psql:
psql -d postgis_db -f srtm.sql -U user -W
3.2.6 Intersecting Raster and Vector Layers
Intersecting in Oracle GeoRaster
It is impossible to intersect directly raster and vector data in Oracle GeoRaster.Instead,what user
can do is to select a sampling window to clip an area of the raster and get raster data over this area.
The sampling windows must be rectangular or the round windows cannot be used (As described in
SDO_GEOR.generateStatistics documentation
2
).So the MBR is used as solution.
In the following example,the sampling windows are the geometry objects stored in sampling_win table.
The request will calculate the intersection between the sampling windows and the spatial extent of
the GeoRaster objects [15]:
DECLARE
cellCoordinate mdsys.sdo_geometry;
ret varchar2(256);
gr sdo_georaster;
BEGIN
-- Intersect spatial extent of the rasters with the sampling windows
(SELECT t.id,t.geom,r.image_id as rid
FROM spain_images r,sampling_win t
WHERE sdo_geom.sdo_intersection(r.image.spatialExtent,t.geom,0.005) is not null)
END;
Intersecting in PostGIS Raster
PostGIS Raster uses st_intersection() and st_intersects() functions,that operate di-
rectly on raster and vector data,to calculate the intersection.Before doing the intersection,the
st_intersects() will check which portion of raster is intesected by vector.So the st_intersection()
intersects vector with raster by vectorizing only the necessary part of the raster [8]:
CREATE TABLE vector_srtm_inter AS
SELECT id,(gv).geom AS the_geom,(gv).val
FROM ( SELECT id,ST_Intersection(rast,the_geom) AS gv
FROM srtm_tiled,vector_data
WHERE ST_Intersects(rast,the_geom)
) inter;
2
http://docs.oracle.com/cd/B28359_01/appdev.111/b28398/geor_ref.htm#CHEDCICI
.
25
In summary,the intersection is much slower than one in GeoRaster for two reasons:
• To intersect vector and raster data,firstly raster has to be polygonized,then the result is the
intersection between these polygons with vector data.In this process,polygonizing is a complex
operation.
• In Oracle,the raster data is sampled using rectangular windows.So the intersection is only
performed between these MBRs with vector data while the vector data intersected by the raster
data in PostGIS Raster are in some forms [15].
26
Chapter 4
PostGIS Raster
This section deals with representing raster structure and explaining from how raster is stored to
the mechanisms used to index,retrieve raster in PostgreSQL.It is also important to address the way
that raster and vector layers overlap - a relevant feature that makes PostGIS Raster more robust than
ORACLE GEORaster.
4.1 Implementation
PostGIS Raster chooses to implement a minimal raster data structure.That means that a raster
type is as simple as a single type and is stored in a single table.This data structure is very similar
to the one of PostGIS vector data and very different from the Oracle Spatial SDO_GEORASTER and
SDO_RASTER raster structures.In PostGIS Raster:
• One table with a column of type raster is referred to as a raster coverage.
• One table row with a column of type raster corresponds to one tile.
The choice of such simple data structure will facilitate the achievement of four objectives described
in Chapter
3
.With a single raster type,it implies that each raster attribute is a complete and self
sufficient georeferenced raster.So raster attributes composing a table are not necessarily related to
each other to form a significant coverage.This also means that:
• Rasters from the same table may have different size.
• The upper left corner and the pixel size of a raster are not necessarily the same values as those
of another rasters.They may therefore snap to different grids.
• Finally,different rasters may overlap like polygons in a vector layer may overlap.This is a
fundamental feature to implement meaningful vector to raster conversions in which all attributes
of a vector are conserved in the resulting raster table.In this case,if the vector features and the
data values part of the resulting raster features do not necessarily overlap,the nodata values of
the raster features will overlap.
In addition,PostGIS Raster provides also a raster_columns table to help application get a quick
overview of raster tables and information (such as metadata) related to the rasters stored in these
tables.
4.2 Structure
PostGIS Raster implements only one type of raster instead of two like SDO_GEORASTER and
SDO_RASTER in Oracle Spatial.It supports no metadata when a raster contains all data about it-
self such as attribute information,georeference information,band information and band data.Figure
??describes these components in details [6].As shown in this figure,a raster has no mask and
27
Table 4.1:PostGIS Raster structure.
Attribute infor-
mation
Description
Storage
version
Raster format version
unsigned 16 bit
integer
band number
Number of raster bands stored in
the raster
unsigned 16 bit
integer
width
Width of the raster
unsigned 16 bit
integer
heigh
Height of the raster
unsigned 16 bit
integer
Georeference in-
formation
Description
Storage
pixelsizex
Pixel size in the x-direction in the
same map units as the coordinate
system
64 bit double
pixelsizey
Pixel size in the y-direction in the
same map units as the coordinate
system
64 bit double
upperleftx
X-coordinate of the center of the up-
per left pixel
64 bit double
upperlefty
Y-coordinate of the center of the up-
per left pixel
64 bit double
rotationx
Rotation about x-axis
64 bit double
rotationy
Rotation about y-axis
64 bit double
srid
Y-coordinate of the center of the up-
per left pixel
32 bit integer
Band information
(one set per band)
Description
Storage
isoffline
Flag specifying if raster data is
stored in the database or as a file
in the file system
1 bit
hasnodatavalue
Flag specifying if nodatavalue exists
or not
1 bit
pixeltype
Pixel type of the band
4 bits
nodatavalue
Nodata value of the band
Depend on band
pixel type
Band data (one
set per band) for
in-db raster
Description
Storage
values[]
An array of pixel values
Depends on band
pixel type and size
Band data (one
set per band) for
out-db raster
Description
Storage
bandnumber
Number of the out-db band
unsigned 8 bit inte-
ger
path
Path to the out-db raster file
string
28
Figure 4.1:PostGIS Raster implementation.
no pyramid propeties when a mask can be created as an independent band and reduced resolution
coverages can be stored as a separate layer.
So a single raster has everything essential to do basic GIS raster operations.It is thus not nec-
essarily related to other rasters in the same table to be georeferenced.This choice makes PostGIS
Raster very simple and flexible.
4.3 Spatial Reference Identifier
A spatial reference system (SRS) or coordinate reference system (CRS) is a coordinate-based local,
regional or global system used to locate geographical entities.A spatial reference system defines a
specific map projection,as well as transformations between different spatial reference systems.
A spatial reference system identifier (SRID) is a unique value used to identify projection and local
spatial coordinate system.These coordinate systems form the heart of all GIS applications.In other
words,SRID values associated with spatial objects can be used to constrain spatial operations.For
instance,spatial operations (such as intersection,transformation and etc.) can not be performed
between spatial objects with different SRIDs.Or,the result of any spatial method derived from two
spatial objects is valid only if they have the same SRID that is based on the same unit of measurement
and projection.
4.4 Raster Data
Raster data is a matrix of cells (or pixels) organized into rows and columns (or a grid) where each
cell contains a value representing information.Unlike vector format,data stored in raster format can
be used to represent various real world phenomena like [16]:
• Land use or soils data which is classified as discrete data.
• Temperature,elevation or spectral data that comes from satellite images and aerial photograph-
swhich are classified as continuous data.
• Pictures such as scanned maps or photographs of drawings and buildings.
4.4.1 Usage
With a simple data structure,raster is exceptionally useful for a wide range of applications.In
GIS,the uses of raster data falls under four main categories:
• Base maps A common way to use raster is as a background for displaying other vector layers.
Three main sources of raster based maps are orthophotos,satellite imagery and scanned maps.
29
Figure 4.2:Information representation using raster data [16].
An thophoto,thophotograph or thoimage is an aerial photograph geometrically corrected such
that the scale is uniform:the photo has the same lack of distortion as a map.Unlike an un-
corrected aerial photograph,an orthophotograph can be used to measure true distances because
it is an accurate representation of the Earth’s surface,being adjusted for topographic relief
1
,
lens distortion
2
and camera tilt
3
.When orthophotographs are displayed underneath other
layers,they provide user with confidence that map layers are spatially aligned and represent real
objects.
Figure 4.3:Basemap raster for road data [16].
• Continuous maps Due to the matrix of cells structure,rasters are well suited for representing
and storing data that changes continuously across a surface.Elevation values measured from
the Earth’s surface are the most common application of surface maps.For example,raster in
Figure
4.4
displays elevation,where green cells show lower elevation and red,pink and white cells
show higher elevation.Other values,such as rainfall,temperature,concentration and population
density,can also be used in spatial analysis as cells representing surfaces are regularly spaced.
• Thematic maps Rasters representing thematic data can be derived from other data through
analyzing operations.A common analysis application is classifying a satellite image by land-
cover categories.Basically,this activity groups the values of data into classes (such as vegetation
type) and assigns a categorical value.Figure
4.5
is an example of a classified raster data that
expresses the human use of land.Thematic maps can also result from geoprocessing operations
that combine data from various sources such as vector,raster and terrain data.For example,
user can process data through a geoprocessing model to create raster data that maps suitability
for a specific activity.
• User-defined attributes Digital photography and scanner are output devices that capture real
world phenomena into digital world for long-term storage.Raster data is means by which digital
1
http://en.wikipedia.org/wiki/Topography
.
2
http://en.wikipedia.org/wiki/Barrel_distortion
.
3
http://en.wikipedia.org/wiki/Camera_tilt
.
30
Figure 4.4:Surface map raster [16].
Figure 4.5:Thematic map raster [16].
photographs,scanned documents or scanned drawings are conserved.Via raster representation,
these real phenomena can also be used as user-defined attributes of a geographic object.For
example,a parcel layer may have scanned legal documents identifying the latest transaction for
that parcel.Or,a layer representing cave openings may have pictures of the actual cave openings
associated with the point features.Concretely,a real tree represented by the digital picture in
Figure
4.6
can be used as an attribute to a landscape layer that a city may maintain.
Figure 4.6:Tree attribute [16].
4.4.2 Cell Representation
Raster data is made up of a matrix of cells (or pixels),where each cell contains a value.In other
words,the cell values are used to represent phenomenon described by the raster data such as a category,
magnitude,height or spectral value.The category can be a land-use class such as grassland,forest
or road.A magnitude might represent gravity,noise pollution or percent rainfall.Height (distance)
can represent surface elevation above mean sea level,which can be used to derive slope,aspect and
watershed properties.Spectral values are used in satellite imagery and aerial photography to represent
light reflectance and color.
Cell values can be either positive or negative,integer or floating point.Integer values are best used
31
for discrete data while floating-point values are suited for continuous data (such as surfaces).Cells
can also have a noData value to indicate the absence of data.
Depend on represented data,there are two ways to apply a value to a cell.Generally,when the cell
value represents a measure as in the case of elevation,it is applied at the center of the cell.However,
in most cases,the cell value is resulted froma sampling of a phenomenon,so it is applied for the whole
cell square.
Figure 4.7:On the left side:cell values applied at the center point.On the right side:cell values
applied for the whole square.
Raster data is stored as an ordered list of cell values.For example,such a raster in Figure
4.8
will
be stored as a list of 80,74,62,45,45,34 and so on.
Figure 4.8:Raster cell values [16].
The area represented by each cell consists of the same width and height and equals a portion of
the entire surface represented by the raster.For example,a raster representing elevation may cover
an area of 100 square kilometers.If there were 100 cells in this raster,each cell would represent one
square kilometer of 1 km in width and 1 km in height.
The dimension of the cell can be as large or as small as needed to represent the surface conveyed
by the raster and the objects within this surface.In other words,the cell size determines how coarse
or fine the objects in the raster will appear.The smaller the cell size is,the smoother the raster will
be.However,when decreasing the cell size to get better image,the number of cell will increase as the
surface size is maintained.A large number of cells will take long time to process and demands more
storage space.In contrast,if a cell size is too large,information may be lost or subtle patterns may
be obscured.For example,if the cell size is larger than the width of a road,the road may not exist
within the raster dataset.In Figure
4.10
,it shows how does the polygon look like as it is represented
at various cell sizes.
The location of each cell is defined by the row or column where it is located within the raster
matrix.Essentially,the matrix is represented by a Cartesian coordinate system,in which the rows of
32
Figure 4.9:Raster cell [16].
Figure 4.10:Raster resolution [16].
33
the matrix are parallel to the x-axis and the columns to the y-axis of the Cartesian plane.Row and
column values begin with 0.
Figure 4.11:Pixel or cell location.
The extent of a raster then is defined by the top,bottom,left and right coordinates of the rectan-
gular covered by the raster,as shown in Figure
4.12
.
Figure 4.12:Raster extent [16].
4.4.3 Zones and Regions
Zones
Any two or more cells with the same value belong to the same zone.A zone consists of cells that are
adjacent,disconnected or both.Zones whose cells are adjacent usually represent a single feature such
as a building,lake,road or water body.Assemblages of entities,such as forest stands in a state,soil
types in a county or single-family houses in a town,are features that will most likely be represented
by zones made up of many disconnected groups of connected cells.
Every cell in a raster belongs to a zone.Some raster data contains only a few zones while others
contain many.
Regions
Each group of connected cells in a zone is considered a region.A zone that consists of a single
group of connected cells has only one region.Zones can be composed of as many regions as necessary
to represent a feature.In the example of Figure
4.13
,zone 2 consists of two regions,zone 4 of three
regions and zone 5 of one region.
34
Figure 4.13:Raster zones and regions [32].
4.4.4 Representing Features
In raster data,the cell typically represents the predominant phenomenon of the area covered by
a cell,whereas vector data can accurately identify individual features.This is due to the fact that
when representing geographic features using raster data,features are nothing more than collections
of cells with the same attribute values and thus lose their unique identities.Raster data is best used
when the primary problem concerns with the locational relationships of the phenomena represented
by geographic features and not the features themselves.
Discrete Data
Discrete data,which is sometimes called thematic,categorical or discontinuous data,is used to
describe discrete objects and can be expressed in both vector and raster formats.A discrete object has
always precise boundaries.So it is easy to define where the object begins and where it ends as well as
how to compose them from discrete features like points,lines and polygons.A lake is a discrete object
surrounded by landscape.Other examples of discrete objects include buildings,roads and parcels.
Figure 4.14:Discrete data represented in raster format [33].
Points
A point is represented by an explicit x,y coordinate in vector format.However,in raster format,
it is a single cell,the smallest unit of a raster.By definition,a point has no area but will represent
an area when it is converted to a cell.For example,a telephone pole or the location of an endangered
plant will occupy the entire area covered by a cell.Therefore,the smaller the cell size,the smaller the
area and thus the closer the representation of the point feature.
As a raster point has the same size as the size of the cell.So the cell size has to be chosen small
enough to capture sufficient input points for the desired analysis.In the case if two or more points
fall within the same cell,the value of one of these points will be randomly selected when assigning a
value to the cell.
35
Figure 4.15:Raster point representation [34].
Lines
In vector format,a line is an ordered list of x,y coordinates whereas in raster format it is represented
as a chain of connected cells with the same value.When there is a break between the chain of same
valued cells,it corresponds a break in the line.A break can also be used to define two roads or two
rivers that do not intersect.
Figure 4.16:Raster line representation [34].
Converting a vector line to raster data is similar to converting a vector point to raster data.For
any line that passes over a cell,this cell will receive the attribute value of this line.If multiple lines
pass through a single cell,one of the lines will be randomly selected to represent that cell.
The same as vector point,the width of vector line will become the width of the cell.For example,
if the line that is being converted represents a road and the cell size is one meter,then the road will
be one meter wide in the output raster data.
Polygons
A vector polygon is an enclosed area defined by an ordered list of x,y coordinates in which the first
and last coordinates are the same.In contrast,a raster polygon is a group of contiguous cells with
the same value that most accurately describe the shape of the area.Examples of polygonal features
include buildings,ponds,soils,forests,swamps and fields.
The accuracy of the raster representation depends on the scale of the data and the size of the cell.
The finer the cell resolution and the greater the number of cells,the more accurate the representation.
Continuous Data
Continuous data is used to describe continuous surfaces.Acontinuous surface represents phenomena
in which each location on the surface has a measure of the concentration level or a value describing its
relationship with a fixed point in space or with an emitting source.Continuous data is also referred
to as field,nondiscrete or surface data.
One type of continuous surface,that is derived from those characteristics that define a surface,is
a surface where each point in the surface is its measured from a fixed reference point.These include
elevation (the fixed reference point is a sea level and the measure at each point is its height above the
36
Figure 4.17:Raster polygon representation [34].
sea level).Another example is temperature where the measure at each point is temperature at a place
on the Earth.
Figure 4.18:Raster elevation data for a part of the province of Quebec [8].
4.5 Spatial Resolution
The detail level of phenomena represented by a raster is often dependent on the spatial resolution
or cell size of the raster.The cell must be small enough to capture the required detaild but it has to
be also large enough so that computer storage and analysis can be performed efficiently.Smaller cell
sizes result in larger raster data set and greater storage space to represent an entire surface,which
often require longer processing time.
Figure 4.19:Spatial resolution.
37
Choosing an appropriate cell size is not always simple.For example,the spatial resolution needed
for applications againsts with the requirements for quick displaying,processing time and storages.In
GIS,the choice is made for the least accurate raster data.For example,for a raster data derived from
30-meter resolution Landsat imagery,a digital elevation model (DEM) at a higher resolution,such as
10 meters,may be unnecessary.
Figure 4.20:Raster in different spatial resolutions [11].
However in most of applications,determining an adequate cell size is not a static process and
depends on what data expected to obtain.In the other hand,a raster can always be resampled to
have a larger cell size but any greater detail can not be obtained by resampling the same raster at a
smaller cell size.So,it is useful to store a copy of the raster at its smallest cell size,then it will be
resampled to match the use in application to increase analysis processing speed.
4.6 Spatial Resolution Versus Scale
Spatial resolution refers to the dimension of the cell size that represents an area on the ground.If
the area covered by a cell is 5 x 5 meters,the resolution is 5 meters.The higher the resolution of a
raster,the smaller the cell size and thus the greater the detail.This is opposite to scale.
A scale model represents a copy of an object that is larger or smaller than its actual size.To do
this,a relative proportion (a scale factor) of the physical size of the original object is maintained for
the restitution.The smaller the scale,the less detail shown.So,an ortho photograph displayed at a
scale of 1:2,000 (that means 1 unit on model is equal to 2,000 units on real object) shows more details
than one displayed at a scale of 1:24,000.However,if the same orthophoto has a cell size of 5 meters,
the resolution will remain the same no matter what scale it is displayed at,as the physical cell size
does not change.
Image shown in Figure
4.21
illustrates well these effect.On the left,the scale of the image (1:50,000)
is smaller than the scale of the one on the right (1:2,500) but their spatial resolutions (cell size) are
the same.Another way to display images is to change the spatial resolution and maintain the scale
like the ones in Figure
4.22
.
4.7 Bands
PostGIS Raster supports multiple bands.So besides the ordinates row and column,each raster can
have the third ordinate band and is identified as a cell in the space of three dimensions (see Figure
4.23
).Band is numbered from 1 to n,where n is the highest band number.Each band has information
about itself such as band data,a pixel type and a nodata value (as described in Figure??).The pixel
type indicates the number of bits used to express the color of a single pixel as well as the nodata value.
Band data is a two-dimensional matrix of cells.The storage used for band data is band sequential
(BSQ).
38
Figure 4.21:Rasters at different scales [11].
Figure 4.22:Same scaled rasters at different spatial resolution [11].
Figure 4.23:Raster bands.
39
The multi-band conception is resulted from the fact that,in practice,a raster image can contain
multiple bands.For example,electromagnetic wave data from remote sensing devices is grouped into
a certain number of channels,where the number of possible channels depends on the capacities of the
sensing device.Or,multispectral images contain multiple channels and hyperspectral images contain
environ 50 or more channels.Then by using raster type to model such data in a geographic information
system,each channel is expressed by a band.
Some rasters have a single band of data,while others have multiple bands.Basically,a band
is represented by a single matrix of cell values and a raster with multiple bands contains multiple
coincident matrices of cell values representing the same spatial area.An example of a single-band raster
dataset is a digital elevation model (DEM).Each cell in a DEMcontains only one value representing
surface elevation.Most satellite imagery has multiple bands,typically containing values within a range
or band of the electromagnetic spectrum.
There are three main ways to display single-band raster data:
• Using two colors:In a binary image,each cell has a value of 0 or 1 and is often displayed using
black and white.This type of display is often used for displaying scanned maps with simple line
work such as parcel maps.
• Grayscale:In a grayscale image,each cell has a value from 0 to 255 or 65535.These are often
used for black and white aerial photographs.
• Color map:One way to represent colors on an image is using a color map.A set of values is
coded to match a defined set of red,green and blue (RGB) values.
Figure 4.24:Three main ways to display single-band raster [35].