PostGIS Raster : Extending PostgreSQL for The Support of ... - CoDE
PostGIS Raster : Extending PostgreSQL for The Support of ... - CoDE
PostGIS Raster : Extending PostgreSQL for The Support of ... - CoDE
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Faculté de Sciences Appliquées<br />
Service Ingénierie In<strong>for</strong>matique<br />
et de la Décision (<strong>CoDE</strong>)<br />
<strong>PostGIS</strong> <strong>Raster</strong> :<br />
<strong>Extending</strong> <strong>PostgreSQL</strong> <strong>for</strong> <strong>The</strong> <strong>Support</strong> <strong>of</strong><br />
Continuous Fields<br />
Thi Ngoc Uyen DANG<br />
Directeur : Pr<strong>of</strong>. Esteban Zimányi<br />
Mémoire présentée en vue de l’obtention<br />
du diplôme d’Ingénieur In<strong>for</strong>maticien<br />
Année académique 2011–2012
Acknowledgements<br />
I would like to thank all people <strong>for</strong> helping me in this work and also <strong>for</strong> those who gave me advice<br />
and ideas when i faced problems. Especially, i would like to thank my promoter Esteban Zimányi <strong>for</strong><br />
the help, support and responsibility <strong>of</strong> which he has shown throughout the year. I also would like to<br />
thank Alejandro Vaisman, who worked with me from start to finish.<br />
<strong>The</strong> last thanks will go to my family, <strong>for</strong> allowing me to study, to progress and realize my own<br />
mistakes.<br />
i
Abstract<br />
Nowadays, in many application domains, complex analysis tasks <strong>of</strong>ten require to take geographical<br />
in<strong>for</strong>mation into account. However, there are very few attempts to support continuous fields, a phenomena<br />
that are perceived as having a value at each point in space and/or time. Examples <strong>of</strong> such<br />
phenomena include temperature, altitude or land use. This thesis is intended to introduce <strong>PostGIS</strong><br />
<strong>Raster</strong>, a new raster data type supporting continuous fields in <strong>PostgreSQL</strong> database. Later, based<br />
on this primitive data type, a new composite type is build, along with a set <strong>of</strong> functions to take into<br />
account the temporal aspect. Finally, an application that allows user to exploit the temporal feature<br />
<strong>of</strong> such raster data is also provided.<br />
ii
Contents<br />
Acknowledgements i<br />
Abstract ii<br />
Contents vi<br />
List <strong>of</strong> Figures 1<br />
1 Introduction 2<br />
1.1 Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2<br />
1.2 Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2<br />
1.3 Organisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3<br />
2 Geographic In<strong>for</strong>mation Systems 4<br />
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4<br />
2.2 Elements <strong>of</strong> GIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4<br />
2.2.1 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4<br />
2.2.2 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5<br />
2.2.3 Imagery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6<br />
2.2.4 Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7<br />
2.3 Geographic Data Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9<br />
2.3.1 Vector Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9<br />
2.3.2 <strong>Raster</strong> Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10<br />
2.4 Geographic In<strong>for</strong>mation Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . 11<br />
2.4.1 Map Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11<br />
2.4.2 Data <strong>The</strong>me . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12<br />
2.5 Georeference and Coordinate Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />
2.5.1 Georeference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />
2.5.2 What Is a Coordinate System? . . . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />
2.6 GIS Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16<br />
2.6.1 Crime Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16<br />
2.6.2 GIS and Hydrogeology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16<br />
2.6.3 Traditional Knowledge GIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18<br />
3 Why <strong>PostGIS</strong> <strong>Raster</strong> ? 19<br />
3.1 Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19<br />
3.1.1 Simplicity and Complementarity . . . . . . . . . . . . . . . . . . . . . . . . . . 19<br />
3.1.2 Transparent Integration with Vector . . . . . . . . . . . . . . . . . . . . . . . . 19<br />
3.1.3 Storage Flexibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19<br />
3.1.4 Interoperability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19<br />
3.2 <strong>PostGIS</strong> <strong>Raster</strong> Versus ORACLE GEO<strong>Raster</strong> . . . . . . . . . . . . . . . . . . . . . . . 20<br />
3.2.1 Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20<br />
3.2.2 Physical Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21<br />
3.2.3 Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23<br />
iii
3.2.4 Overlapping <strong>Raster</strong> and Vector Layers . . . . . . . . . . . . . . . . . . . . . . . 24<br />
3.2.5 Loading <strong>Raster</strong> Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24<br />
3.2.6 Intersecting <strong>Raster</strong> and Vector Layers . . . . . . . . . . . . . . . . . . . . . . . 25<br />
4 <strong>PostGIS</strong> <strong>Raster</strong> 27<br />
4.1 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27<br />
4.2 Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27<br />
4.3 Spatial Reference Identifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29<br />
4.4 <strong>Raster</strong> Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29<br />
4.4.1 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29<br />
4.4.2 Cell Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31<br />
4.4.3 Zones and Regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34<br />
4.4.4 Representing Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35<br />
4.5 Spatial Resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37<br />
4.6 Spatial Resolution Versus Scale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38<br />
4.7 Bands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38<br />
4.8 Pixel Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41<br />
4.9 Nodata Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42<br />
4.10 Blocks or Tiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42<br />
4.11 Pyramids or Overviews . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43<br />
4.11.1 Concept . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43<br />
4.11.2 Creating Pyramids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43<br />
4.12 Masks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44<br />
4.13 Arrangements <strong>of</strong> <strong>Raster</strong> Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44<br />
4.14 Data Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48<br />
4.15 Physical Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49<br />
4.15.1 Storing In-database <strong>Raster</strong> Versus Storing Out-database <strong>Raster</strong> . . . . . . . . . 49<br />
4.15.2 Registering Out-database <strong>Raster</strong> . . . . . . . . . . . . . . . . . . . . . . . . . . 50<br />
4.15.3 Storing In-database <strong>Raster</strong> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50<br />
4.16 Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53<br />
4.17 Retrieving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54<br />
4.17.1 In-database <strong>Raster</strong> Retrieving . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54<br />
4.17.2 Out-database <strong>Raster</strong> Retrieving . . . . . . . . . . . . . . . . . . . . . . . . . . . 54<br />
4.18 Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55<br />
4.18.1 <strong>Raster</strong> to vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55<br />
4.18.2 Vector to raster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55<br />
4.19 Intersection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56<br />
4.20 Temporal <strong>Raster</strong> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59<br />
4.20.1 Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59<br />
4.20.2 Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59<br />
5 User Guide 62<br />
5.1 Store and Manage <strong>Raster</strong>s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62<br />
5.1.1 Import <strong>Raster</strong>s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62<br />
5.1.2 Get and Set <strong>The</strong> <strong>Raster</strong> Properties . . . . . . . . . . . . . . . . . . . . . . . . . 62<br />
5.1.3 Vector to <strong>Raster</strong> Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64<br />
5.1.4 <strong>Raster</strong> to Vector Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64<br />
5.2 Exporting <strong>Raster</strong>s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65<br />
5.3 Get <strong>Raster</strong> Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65<br />
5.4 Display <strong>Raster</strong>s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65<br />
5.5 Edit and Compute <strong>Raster</strong>s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66<br />
5.6 Convert <strong>Raster</strong>s to GDAL Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67<br />
5.6.1 <strong>Raster</strong> to TIFF File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67<br />
5.6.2 <strong>Raster</strong> to JPEG File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67<br />
iv
5.6.3 <strong>Raster</strong> to PNG File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68<br />
5.7 Intersect <strong>Raster</strong>s with Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68<br />
5.7.1 Intersect <strong>Raster</strong>s with Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68<br />
5.7.2 Intersect <strong>Raster</strong>s with Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69<br />
5.7.3 Intersect <strong>Raster</strong>s with Polygons . . . . . . . . . . . . . . . . . . . . . . . . . . . 69<br />
5.8 Aggregate Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70<br />
5.9 Create a High Resolution Analysis Grid . . . . . . . . . . . . . . . . . . . . . . . . . . 70<br />
5.10 Create a Specialised Web or Desktop GIS Application . . . . . . . . . . . . . . . . . . 70<br />
6 Application 72<br />
6.1 Quantum GIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72<br />
6.1.1 Advantages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72<br />
6.1.2 Utilisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73<br />
6.2 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74<br />
6.2.1 Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74<br />
6.2.2 Color Legend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76<br />
6.3 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76<br />
6.3.1 Time Travel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77<br />
6.3.2 Color Legend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81<br />
7 Conclusion 83<br />
Bibliography 84<br />
Annex 87<br />
A <strong>PostGIS</strong> <strong>Raster</strong> Utilisation 88<br />
A.1 Dependencies Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88<br />
A.2 Installing and Configuring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88<br />
A.2.1 Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88<br />
A.2.2 Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88<br />
A.3 Creating Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88<br />
B Python Plugin in QGIS 89<br />
B.1 Necessary Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89<br />
B.2 Python Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89<br />
B.2.1 __init__.py . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89<br />
B.2.2 Plugin.py . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90<br />
B.2.3 Resources.qrc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91<br />
C Code Implementation 92<br />
C.1 Temporal <strong>Raster</strong> Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92<br />
C.2 Temporal <strong>Raster</strong> Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93<br />
D <strong>Raster</strong> Sources 95<br />
D.1 Remote Sensing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95<br />
D.1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95<br />
D.1.2 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95<br />
D.2 Photogrammetry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96<br />
D.2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96<br />
D.2.2 Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97<br />
D.3 Cartography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97<br />
D.4 Digital Image Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98<br />
D.4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98<br />
D.4.2 Digital Camera Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98<br />
v
D.5 Geology, Geophysics and Geochemistry . . . . . . . . . . . . . . . . . . . . . . . . . . . 98<br />
E <strong>Raster</strong> Resolution 101<br />
F Continuous Surfaces 102<br />
vi
List <strong>of</strong> Figures<br />
2.1 Point feature [27]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5<br />
2.2 Line feature [27]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5<br />
2.3 Polygon feature representing parcels [27]. . . . . . . . . . . . . . . . . . . . . . . . . . 6<br />
2.4 Grid <strong>of</strong> cells in raster data [27]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6<br />
2.5 <strong>Raster</strong> data [27]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6<br />
2.6 Multiband raster data [27]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7<br />
2.7 Surface expressed by contour lines [27]. . . . . . . . . . . . . . . . . . . . . . . . . . . . 7<br />
2.8 Surface expressed by contour bands [27]. . . . . . . . . . . . . . . . . . . . . . . . . . . 8<br />
2.9 Surface expressed by raster data [27]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8<br />
2.10 Surface expressed by TIN layers [27]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8<br />
2.11 Vector image at various scales. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9<br />
2.12 <strong>The</strong> original vector image is on the left side. <strong>The</strong> upper-right image illustrates magnification<br />
<strong>of</strong> 7x as a vector image. <strong>The</strong> lower-right image illustrates the same magnification<br />
as a raster image [29]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10<br />
2.13 <strong>Raster</strong> image in zooming [28]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11<br />
2.14 Multiple layers geographic representation. . . . . . . . . . . . . . . . . . . . . . . . . . 12<br />
2.15 <strong>The</strong>mes <strong>for</strong> a area [30]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12<br />
2.16 Georeferencing a geographic object [26]. . . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />
2.17 <strong>The</strong> location <strong>of</strong> the measured point (in red) is latitude plus 40 degrees and longitude<br />
plus 50 degrees [26]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14<br />
2.18 Parallels lines <strong>of</strong> latitude and meridians line <strong>of</strong> longitude [26]. . . . . . . . . . . . . . . 14<br />
2.19 2D Cartesian coordinate system. [26]. . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
2.20 3D Cartesian coordinate system [26]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
2.21 Different methods <strong>for</strong> map projection [26]. . . . . . . . . . . . . . . . . . . . . . . . . . 16<br />
2.22 Distorsion in map projection [26]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16<br />
2.23 Mapping <strong>of</strong> homicides in Washington D.C. [18] . . . . . . . . . . . . . . . . . . . . . . 17<br />
2.24 Groundwater level change <strong>of</strong> the High Plains Aquifer, 1980-95 [31]. . . . . . . . . . . . 17<br />
3.1 Geo<strong>Raster</strong> data architecture [3]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20<br />
3.2 <strong>PostGIS</strong> <strong>Raster</strong> data architecture. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21<br />
3.3 Physical storage <strong>of</strong> Geo<strong>Raster</strong> data [3]. . . . . . . . . . . . . . . . . . . . . . . . . . . . 22<br />
3.4 Physical storage <strong>of</strong> <strong>PostGIS</strong> <strong>Raster</strong> data. . . . . . . . . . . . . . . . . . . . . . . . . . . 22<br />
3.5 Oracle Geo<strong>Raster</strong> georeference approach [14]. . . . . . . . . . . . . . . . . . . . . . . . 23<br />
3.6 <strong>PostGIS</strong> <strong>Raster</strong> georeference approach [14]. . . . . . . . . . . . . . . . . . . . . . . . . 23<br />
4.1 <strong>PostGIS</strong> <strong>Raster</strong> implementation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29<br />
4.2 In<strong>for</strong>mation representation using raster data [16]. . . . . . . . . . . . . . . . . . . . . . 30<br />
4.3 Basemap raster <strong>for</strong> road data [16]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30<br />
4.4 Surface map raster [16]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31<br />
4.5 <strong>The</strong>matic map raster [16]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31<br />
4.6 Tree attribute [16]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31<br />
4.7 On the left side: cell values applied at the center point. On the right side: cell values<br />
applied <strong>for</strong> the whole square. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32<br />
4.8 <strong>Raster</strong> cell values [16]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32<br />
vii
4.9 <strong>Raster</strong> cell [16]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33<br />
4.10 <strong>Raster</strong> resolution [16]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33<br />
4.11 Pixel or cell location. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34<br />
4.12 <strong>Raster</strong> extent [16]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34<br />
4.13 <strong>Raster</strong> zones and regions [32]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35<br />
4.14 Discrete data represented in raster <strong>for</strong>mat [33]. . . . . . . . . . . . . . . . . . . . . . . 35<br />
4.15 <strong>Raster</strong> point representation [34]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36<br />
4.16 <strong>Raster</strong> line representation [34]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36<br />
4.17 <strong>Raster</strong> polygon representation [34]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37<br />
4.18 <strong>Raster</strong> elevation data <strong>for</strong> a part <strong>of</strong> the province <strong>of</strong> Quebec [8]. . . . . . . . . . . . . . . 37<br />
4.19 Spatial resolution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37<br />
4.20 <strong>Raster</strong> in different spatial resolutions [11]. . . . . . . . . . . . . . . . . . . . . . . . . . 38<br />
4.21 <strong>Raster</strong>s at different scales [11]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39<br />
4.22 Same scaled rasters at different spatial resolution [11]. . . . . . . . . . . . . . . . . . . 39<br />
4.23 <strong>Raster</strong> bands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39<br />
4.24 Three main ways to display single-band raster [35]. . . . . . . . . . . . . . . . . . . . . 40<br />
4.25 Multi-band raster [35]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40<br />
4.26 RGB composite from a three-band raster [35]. . . . . . . . . . . . . . . . . . . . . . . . 41<br />
4.27 Multi-band raster image [35]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41<br />
4.28 <strong>Raster</strong> tiles [23]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42<br />
4.29 Pyramids (or Overviews) in <strong>PostGIS</strong> <strong>Raster</strong> [24]. . . . . . . . . . . . . . . . . . . . . . 43<br />
4.30 Pyramids at different levels and scales [36]. . . . . . . . . . . . . . . . . . . . . . . . . 44<br />
4.31 In the right side: <strong>The</strong> mask. In the left side: the mask with the transparency set to<br />
70% overlays the digital elevation model raster [10]. . . . . . . . . . . . . . . . . . . . 45<br />
4.32 Image warehouse <strong>of</strong> untiled and unrelated images (4 images) [6]. . . . . . . . . . . . . 45<br />
4.33 Image warehouse <strong>of</strong> cars [22]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45<br />
4.34 Irregular tiled raster coverage (36 tiles))[6]. . . . . . . . . . . . . . . . . . . . . . . . . 46<br />
4.35 Regular tiled raster coverage (36 tiles) [6]. . . . . . . . . . . . . . . . . . . . . . . . . . 46<br />
4.36 Rectangular regular tiled raster coverage (54 tiles) [6]. . . . . . . . . . . . . . . . . . . 46<br />
4.37 Tiled images (2 tables <strong>of</strong> 54 tiles) [6]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47<br />
4.38 <strong>Raster</strong> object coverage (9 raster objects corresponding 9 rows in a raster table) [6]. . . 47<br />
4.39 Vector to raster conversion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47<br />
4.40 <strong>Raster</strong> to vector conversion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48<br />
4.41 Image <strong>for</strong>med by the raster [17]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48<br />
4.42 Web application with out-database raster [23]. . . . . . . . . . . . . . . . . . . . . . . 50<br />
4.43 Storing in-database raster. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51<br />
4.44 In-database raster. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53<br />
4.45 Conversion from raster to vector [22]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55<br />
4.46 Conversion from vector to raster [22]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55<br />
4.47 Vector and vector intersection with a resulting vector layer [22]. . . . . . . . . . . . . . 56<br />
4.48 <strong>Raster</strong> intersection paradigm [22]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57<br />
4.49 Vector and raster intersection with a resulting raster layer [22]. . . . . . . . . . . . . . 57<br />
4.50 Vector and raster intersection with a resulting vector layer [22]. . . . . . . . . . . . . . 57<br />
4.51 <strong>Raster</strong> and raster intersection with a resulting vector layer [22]. . . . . . . . . . . . . . 58<br />
4.52 Mutual exclusive polygons intersection with a resulting vector layer [22]. . . . . . . . . 58<br />
4.53 Mutual exclusive vector-raster intersection with a resulting raster layer [22]. . . . . . . 58<br />
4.54 Mutual exclusive vector-raster intersection with a resulting vector layer [22]. . . . . . . 58<br />
4.55 Mutual exclusive raster-raster intersection with a resulting raster layer [22]. . . . . . . 59<br />
5.1 <strong>Raster</strong> circle [17]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64<br />
5.2 Clipping raster effect [17]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67<br />
5.3 Algebra operation on rasters [23]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67<br />
5.4 Intersection <strong>of</strong> raster and geometric points [23]. . . . . . . . . . . . . . . . . . . . . . . 68<br />
5.5 Intersection <strong>of</strong> raster and roads [23]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69<br />
viii
5.6 Intersection <strong>of</strong> raster polygons [23]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69<br />
5.7 Different temperature values in a polygon [23]. . . . . . . . . . . . . . . . . . . . . . . 70<br />
5.8 Gird <strong>of</strong> cells <strong>of</strong> USA map [23]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71<br />
5.9 Web GIS application [23]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71<br />
6.1 QGIS interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73<br />
6.2 QGIS toolbars. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73<br />
6.3 <strong>PostGIS</strong> connection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74<br />
6.4 Temporal raster window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74<br />
6.5 Time travel interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75<br />
6.6 Band area. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76<br />
6.7 <strong>The</strong> temperature color legend. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76<br />
6.8 <strong>The</strong> color legend interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77<br />
6.9 <strong>The</strong> loading map sequential approach. . . . . . . . . . . . . . . . . . . . . . . . . . . . 77<br />
6.10 <strong>The</strong> loading map parallel approach. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78<br />
6.11 Maps representing world climate [7] are loaded once time. <strong>The</strong>ir visibility is handled<br />
by turning on/<strong>of</strong>f the check boxes list. . . . . . . . . . . . . . . . . . . . . . . . . . . . 78<br />
6.12 Media area. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79<br />
6.13 Single band rasters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79<br />
6.14 Maps representing world climate are loaded as single band rasters. <strong>The</strong>y are turned<br />
into color maps by loading a created color palette "worldclim.txt". . . . . . . . . . . . 80<br />
6.15 Map is loaded as multi band raster. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80<br />
6.16 Visualisation <strong>of</strong> band number 2 <strong>of</strong> a multi band map. . . . . . . . . . . . . . . . . . . . 81<br />
6.17 Maps with a color legend. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82<br />
D.1 Synthetic aperture radar image <strong>of</strong> Death Valley [37]. . . . . . . . . . . . . . . . . . . . 96<br />
D.2 Relief map Sierra Nevada (Spain) [38]. . . . . . . . . . . . . . . . . . . . . . . . . . . . 98<br />
D.3 William Smith’s geologic map <strong>of</strong> England,Wales, and southern Scotland. Completed in<br />
1815, it was the first national-scale geologic map and by far the most accurate <strong>of</strong> its<br />
time [39]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99<br />
D.4 Age <strong>of</strong> the sea floor. Much <strong>of</strong> the dating in<strong>for</strong>mation comes from magnetic anomalies<br />
[40]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100<br />
E.1 <strong>Raster</strong> data represented at different resolution or cell sizes [11]. . . . . . . . . . . . . . 101<br />
F.1 Elevation represented in raster <strong>for</strong>mat [33]. . . . . . . . . . . . . . . . . . . . . . . . . 102<br />
F.2 Source-concentration surface represented in raster <strong>for</strong>mat [33]. . . . . . . . . . . . . . . 103<br />
1
Chapter 1<br />
Introduction<br />
1.1 Context<br />
Our daily life is full <strong>of</strong> situations that require us to make a choice among several alternative<br />
solutions, so-called decision process. For example, we have from simple situations such as shopping,<br />
voting to complicated situations that happen in government and business like resource management,<br />
urban planning and regional planning. But on what do we base to make the best choice ?<br />
Due to the complexity <strong>of</strong> many decisions in government and business that require us to think <strong>of</strong><br />
different elements like stakeholders and categories, it leads to the need <strong>of</strong> using s<strong>of</strong>tware <strong>for</strong> decision<br />
making process. Examples <strong>of</strong> such applications include environmental impact-assessment, geographic<br />
history, population and demographic studies, criminology and military planning.<br />
Among the elements that influence decision making, geographical in<strong>for</strong>mation represents a relevant<br />
source to decision makers. Whether the issue is the location <strong>of</strong> a new public or the development <strong>of</strong><br />
a new project, decision makers should consider such geographic in<strong>for</strong>mation as location, character <strong>of</strong><br />
environment and landscapes.<br />
Furthermore, in the private sectors, a large group <strong>of</strong> companies use geographic in<strong>for</strong>mation as a<br />
tool <strong>for</strong> their locational decision making. <strong>The</strong>se include retail marketing chains (<strong>for</strong> example, Dayton-<br />
Hudson, a major retail firm headquartered in Minneapolis), railroads (<strong>for</strong> example, Southern Pacific<br />
Railroad’s land division), electric power and gas utilities, international import-export firms, transportation<br />
and travel service organizations, publishing firms and real estate planners and investors<br />
[19].<br />
1.2 Goals<br />
Not all sources <strong>of</strong> geographic in<strong>for</strong>mation are reliable. <strong>The</strong> precision <strong>of</strong> geographic in<strong>for</strong>mation can<br />
be influenced indirectly through scholarly publications. <strong>The</strong>se publications tend to influence decision<br />
makers’s understanding about climate issues. So it is important to have a useful tool, such as a<br />
geographic in<strong>for</strong>mation system, that helps user to handle directly geographic in<strong>for</strong>mation and thus<br />
guarantees the correctness <strong>of</strong> in<strong>for</strong>mation.<br />
Most <strong>of</strong> the current geographic in<strong>for</strong>mation systems provide a vector type <strong>for</strong> manipulating geographic<br />
in<strong>for</strong>mation. However, there are very few attempts to support a data type that describes the<br />
distribution <strong>of</strong> physical phenomena that change continuously in time and space, so-called continuous<br />
fields. Example <strong>of</strong> such phenomena are temperature, pressure, precipitation, land elevation, land use,<br />
population density and etc.<br />
<strong>The</strong> main contribution <strong>of</strong> this thesis is to introduce a new data type <strong>PostGIS</strong> <strong>Raster</strong> that supports<br />
continuous fields in <strong>PostgreSQL</strong> database. In addition, it also describes an application that allows<br />
user to exploit the temporal feature <strong>of</strong> geographic data using <strong>PostGIS</strong> <strong>Raster</strong>.<br />
2
1.3 Organisation<br />
This thesis is organized as follows : Section 2 starts with GIS and its applications. Section 3 describes<br />
the goals <strong>of</strong> <strong>PostGIS</strong> <strong>Raster</strong>, along with some comparisons with the existed plugin supporting raster<br />
Oracle Geo<strong>Raster</strong> to give users more motivations. <strong>The</strong> following section describes in detail <strong>PostGIS</strong><br />
<strong>Raster</strong> structure and how this one is stored, indexed, retrieved and overlapped. Section 5 provides<br />
guides <strong>for</strong> users about utilisation <strong>of</strong> some <strong>PostGIS</strong> <strong>Raster</strong> functions. Section 6 extends <strong>PostGIS</strong><br />
<strong>Raster</strong> by adding temporal feature and describes a set <strong>of</strong> operators related to aspect temporal. An<br />
implemented application that enhances Quantum Geographic In<strong>for</strong>mation System (QGIS) to exploit<br />
the temporal feature <strong>of</strong> the <strong>PostGIS</strong> <strong>Raster</strong> data will be shown in the next section. Finally, Section 8<br />
concludes our work and point out to future perspectives.<br />
3
Chapter 2<br />
Geographic In<strong>for</strong>mation Systems<br />
Geographic data is stored, manipulated, analyzed by a Geographic In<strong>for</strong>mation System (GIS). This<br />
section describes what is a GIS and different types <strong>of</strong> geographic data such as raster and vector. <strong>The</strong>n<br />
there are a short introduction to some interesting GIS applications.<br />
2.1 Introduction<br />
Geographic data is much more than electronic pictures. <strong>The</strong> geographic data describes not only<br />
real objects and relations in space but contains also spatial reference, geometric and thematic in<strong>for</strong>mation.<br />
Nevertheless, to fully exploit these characteristics, an additional tool is needed. A geographic<br />
in<strong>for</strong>mation system is an in<strong>for</strong>mation system designed to integrates, stores, edits, analyzes, shares and<br />
displays geographic in<strong>for</strong>mation <strong>for</strong> decision makers. GIS applications are tools that allow users to<br />
create interactive queries, analyze spatial in<strong>for</strong>mation, edit data in maps and present the results <strong>of</strong> all<br />
these operations.<br />
A GIS is the merging <strong>of</strong> cartography, statistical analysis and database technology. It is customdesigned<br />
<strong>for</strong> an organization. A GIS developed <strong>for</strong> jurisdiction or enterprise purposes may not be<br />
necessarily interoperable or compatible with a GIS that has been developed <strong>for</strong> some other applications.<br />
2.2 Elements <strong>of</strong> GIS<br />
All GISs that provide rich behaviors <strong>for</strong> representing and managing geographic in<strong>for</strong>mation are based<br />
on four fundamental elements:<br />
• Features<br />
• Attributes<br />
• Imagery<br />
• Surfaces<br />
2.2.1 Features<br />
A feature is used to describe an entity in space-time. Besides a number <strong>of</strong> additional features,<br />
common geographic features are collections <strong>of</strong> points, lines and polygons. <strong>The</strong>y represent discrete<br />
things that occur naturally (such as rivers and vegetation) to those <strong>of</strong> constructions (such as roads,<br />
pipelines, wells and buildings) or subdivisions <strong>of</strong> land (such as counties, political divisions and land<br />
parcels).<br />
Points<br />
Points define discrete things that are too small to be depicted as lines or areas like locations,<br />
telephone poles and stream gauges. Points can also represent address locations, Global Positioning<br />
System (GPS) coordinates or mountain peaks.<br />
4
Lines<br />
Figure 2.1: Point feature [27].<br />
Lines represent the shape <strong>of</strong> geographic objects that are too narrow to be depicted as areas (such<br />
as street centerlines and streams). Lines are also used to represent features that have length but no<br />
area such as contour lines and administrative boundaries.<br />
Polygons<br />
Figure 2.2: Line feature [27].<br />
Polygons are enclosed areas that represent the shape <strong>of</strong> large objects such as states, counties,<br />
parcels, soil types and landuse zones.<br />
2.2.2 Attributes<br />
Geographic data transmits descriptive in<strong>for</strong>mation through symbols, colors, and labels. For example:<br />
• Roads are displayed based on road class. For instance, line symbols represent divided highways,<br />
main streets, residential streets, unpaved roads and trails.<br />
• Blue is used to indicate water and streams.<br />
• City streets are labeled with their name and <strong>of</strong>ten some address.<br />
• Special point and line symbols denote specific features such as rail lines, airports, schools, hospitals<br />
and special facilities.<br />
5
2.2.3 Imagery<br />
Figure 2.3: Polygon feature representing parcels [27].<br />
Imagery is organized as a raster data type composed <strong>of</strong> cells organized in a grid <strong>of</strong> rows and<br />
columns. In addition to cell values, a raster includes also its cell size and a reference coordinate (the<br />
upper left or lower left corner <strong>of</strong> the grid). <strong>The</strong>se properties enable a raster to be described by a series<br />
<strong>of</strong> cell values starting in the upper left row. Each cell location can be automatically located using the<br />
reference coordinate, the cell size and the number <strong>of</strong> rows and columns.<br />
Figure 2.4: Grid <strong>of</strong> cells in raster data [27].<br />
Aerial imagery is a raster data structure obtained from various sensors carried in satellites and<br />
aircraft. Digital orthophotography is a typical imagery sources that comes from cameras.<br />
Figure 2.5: <strong>Raster</strong> data [27].<br />
Imagery is also used to collect data in both the visible and nonvisible portions <strong>of</strong> the electromagnetic<br />
spectrum. One system is the multispectral scanner carried in landsat satellites that records imagery<br />
in seven bands along with the electromagnetic spectrum. <strong>The</strong> measures <strong>for</strong> each band are recorded in<br />
a separate grid. <strong>The</strong> stack <strong>of</strong> seven grids makes up a multiband image.<br />
6
2.2.4 Surfaces<br />
Figure 2.6: Multiband raster data [27].<br />
A surface describes a phenomenon that has a value <strong>for</strong> each point in space. For example, surface<br />
elevation is a continuous area such that every spatial location has a value <strong>for</strong> ground elevation above<br />
sea level. Other examples include surface rainfall, surface pollution concentration and etc.<br />
<strong>The</strong> major problem in surface representation is that it is impossible to represent all values <strong>for</strong> all<br />
locations <strong>of</strong> a area. Various alternatives exist <strong>for</strong> representing such surfaces using either features or<br />
rasters. Here are some alternative solutions <strong>for</strong> surface representation:<br />
Contour Lines<br />
Contour lines: Isolines represent a set <strong>of</strong> points having an equal value, such as elevation contours.<br />
Contour Bands<br />
Figure 2.7: Surface expressed by contour lines [27].<br />
Contour bands: Each band describes a specified range <strong>of</strong> values. An area, where each point value<br />
within it belong to a band, will be represented by a corresponding color. Example <strong>of</strong> such band<br />
consists <strong>of</strong> all average annual rainfall between 25 cm and 50 cm per year.<br />
<strong>Raster</strong> Data<br />
<strong>Raster</strong> data: A matrix <strong>of</strong> cells where each cell value represents a measure <strong>of</strong> each point in space.<br />
For example, digital elevation models (DEMs) represented by grids <strong>of</strong> squares, are frequently used to<br />
describe surface elevation.<br />
Triangulated Irregular Network<br />
A triangulated irregular network (TIN): A data structure represents surfaces as a connected network<br />
<strong>of</strong> triangles. Each triangle node has x,y coordinates and a surface value z.<br />
<strong>The</strong> raster and TIN representations can be used to estimate the surface value <strong>for</strong> any location<br />
using interpolation.<br />
7
Figure 2.8: Surface expressed by contour bands [27].<br />
Figure 2.9: Surface expressed by raster data [27].<br />
Figure 2.10: Surface expressed by TIN layers [27].<br />
8
2.3 Geographic Data Representation<br />
Traditionally, real objects in geographic data can be stored into two <strong>for</strong>ms: discrete objects (such<br />
as roads, houses, trees) using vector and continuous fields (such as rainfall amount, elevations) using<br />
raster. A new hybrid method <strong>of</strong> storing data identifies point clouds, combines three-dimensional points<br />
with RGB in<strong>for</strong>mation at each point and returns a 3D color image. However, the following Section<br />
focus only on vector and raster representation.<br />
2.3.1 Vector Images<br />
Vector images use geometrical primitives like points, lines, curves and polygons, which are all based<br />
on mathematical expressions to represent images in computer graphics.<br />
Each geometric primitive is presented by lines and surfaces. All lines, individually, are defined by<br />
characteristic points that define its equation. <strong>The</strong>se characteristic points <strong>for</strong>m a vector. Thus, the<br />
vector representation is expressed in terms <strong>of</strong> characters <strong>of</strong> line and color <strong>of</strong> the surface. This leads<br />
to the notion <strong>of</strong> drawing multiple layers where planes curves can be overlaid. This phenomenon can<br />
not happen in raster representation since there is only one layer, then each new point overwrites the<br />
previous point.<br />
<strong>The</strong> advantage <strong>of</strong> a vector representation is the delicacy and precision <strong>of</strong> the results. Every line<br />
can be edited very quickly and all at once. Indeed, this representation involves a limited number <strong>of</strong><br />
graphical objects, so these graphics files are very light.<br />
Resolution<br />
As vector images are defined by mathematical expressions, they can be zoomed in or out without<br />
any loss <strong>of</strong> quality. Concretely, the mathematical description <strong>of</strong> the object is simply multiplied by a<br />
zooming factor. For example a 1 inch square object will be multiplied by a factor <strong>of</strong> 2 in order to<br />
double in size. <strong>The</strong> mathematical expression is thus recalculated to produce an object twice the size <strong>of</strong><br />
the original. So vector images can be output at any resolution that a printer is capable <strong>of</strong> producing.<br />
Unlike raster images, quality <strong>of</strong> vector images is not limited by scanning resolution. This is a big<br />
reason that vector images are so popular <strong>for</strong> clip art.<br />
Color<br />
Figure 2.11: Vector image at various scales.<br />
Since vector images are composed <strong>of</strong> objects, coloring vector objects is similar to coloring with crayons<br />
in a coloring book. Using drawing program, users can easily change the color <strong>of</strong> individual objects<br />
by clicking inside this object and define its color, along with defining width <strong>of</strong> lines. Coloring vector<br />
images is much easier than coloring raster images.<br />
File Size<br />
Storing vector images need to keep only mathematical descriptions. For this reason vector files are<br />
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<br />
9
4-foot logo. <strong>The</strong> file size is the same because the only difference in file is one number defining the size<br />
<strong>of</strong> the file. Most vector-based logos are going to be under 100 KB. For this reason, vector files are<br />
ideally suited <strong>for</strong> transfer over the Internet.<br />
File Formats<br />
Common vector <strong>for</strong>mats include EPS (Encapsulated PostScript), WMF (Windows Metafile), AI<br />
(Adobe Illustrator), CDR (CorelDraw), DXF (AutoCAD), SVG (Scalable Vector Graphics) and PLT<br />
(Hewlett Packard Graphics Language Plot File).<br />
Modern displays and printers are raster devices, vector <strong>for</strong>mats have to be converted to raster <strong>for</strong>mat<br />
be<strong>for</strong>e they can be displayed or printed. Or in graphic work, devices such as cameras and scanners<br />
produce essentially continuous-tone raster graphics that are impractical to convert into vectors. So<br />
an image editor will operate on the pixels rather than on drawing objects defined by mathematical<br />
expressions.<br />
2.3.2 <strong>Raster</strong> Images<br />
A raster image (or bitmap) is a 2-dimensional array data structure representing a rectangular grid<br />
<strong>of</strong> pixels, or dots or points <strong>of</strong> color. A raster image is characterized by its width and height in pixels<br />
and by the number <strong>of</strong> bits per pixel. This number determines the number <strong>of</strong> colors can be represented<br />
in the image.<br />
Resolution<br />
<strong>The</strong> resolution <strong>of</strong> a raster image is expressed in terms <strong>of</strong> the dots per inch or dpi. Printer resolution<br />
is also measured in dots per inch. Typical desktop laser printers print at 300 - 600 dpi. Printers with<br />
higher dpi are capable <strong>of</strong> producing smoother and cleaner output. Nevertheless, the quality <strong>of</strong> a raster<br />
image depends on its resolution (dpi) and the capabilities <strong>of</strong> the printing technology [9]. For example,<br />
a 300 dpi raster image will output at the same quality on a 300 dpi laser printer as on a 2,500 dpi<br />
printer. By increasing size <strong>of</strong> a 300 dpi raster image, the tiny pixel squares will become bigger and<br />
create jaggy edges as no additional in<strong>for</strong>mation is added. In this case, the raster image losses quality.<br />
Exammple in Figure 2.12 shows the jaggy edges <strong>of</strong> raster image through zooming effect. In contrast,<br />
When decreasing the size, the squares get smaller and the image retains its original edge without<br />
jaggies.<br />
Figure 2.12: <strong>The</strong> original vector image is on the left side. <strong>The</strong> upper-right image illustrates magnification<br />
<strong>of</strong> 7x as a vector image. <strong>The</strong> lower-right image illustrates the same magnification as a raster<br />
image [29].<br />
Color<br />
As raster images are reproduction <strong>of</strong> real world, a large number <strong>of</strong> colors will be required to render<br />
raster images accurate as their original sources. For example, if scanner works at 24-bit color (16<br />
million colors), most human eyes could not distinct the difference between the original image and<br />
the scanned raster image. In contrast, if a smaller color palette with 256 colors is used, it would be<br />
10
impossible to reproduce the original colors. To get around this, scanners use a process called dithering<br />
to approximate colors that don’t occur in the current color palette.<br />
Figure 2.13: <strong>Raster</strong> image in zooming [28].<br />
<strong>The</strong> biggest disadvantage when using raster images locates at editing and manipulating image<br />
colors. As vector images are object-oriented while raster images are pixel oriented, in order to change<br />
pixel colors, a specific color or range <strong>of</strong> colors must be isolated from the rest to be changed. This work<br />
is quite a challenge <strong>for</strong> even experienced users.<br />
File Size<br />
For each raster image file, a large amount <strong>of</strong> in<strong>for</strong>mation, including the exact location and color <strong>of</strong><br />
each pixel in the grid, needs to be kept track to reproduce the image. This results in large file sizes<br />
<strong>for</strong> raster images. Higher resolutions (dpi) and greater color depths (the number <strong>of</strong> bits per pixel)<br />
produce bigger file sizes. A typical 2" by 3" 150 dpi black and white raster image logo will be less than<br />
70 KB in file size. <strong>The</strong> same file saved as a 300 dpi 24-bit (millions <strong>of</strong> colors) raster image logo might<br />
be 100 times larger (over 7 MB). When creating and scanning raster images, raster file size becomes<br />
a real issue, as big files tend to make computer processor and hard drive work overtime. Transferring<br />
big files (over 1 MB) over the Internet requires a high speed Internet connection on both ends <strong>for</strong><br />
timely uploads and downloads.<br />
In despite <strong>of</strong> these disadvantages, raster images are more practically than vector images as they<br />
are viewable via monitors or other display medium and it is impossible in practice to obtain vector<br />
images from a photo.<br />
File Formats<br />
Common raster image <strong>for</strong>mats include BMP (Windows Bitmap), PCX (Paintbrush), TIFF (Tag<br />
Interleave Format), JPEG (Joint Photographics Expert Group), GIF (Graphics Interchange Format)<br />
, PNG (Portable Network Graphic), PSD (Adobe PhotoShop) and CPT (Corel Photo PAINT).<br />
Perfect graphical tools will combine images from vector and raster sources and provide editing<br />
tools <strong>for</strong> both, since some parts <strong>of</strong> an image could come from a camera source and others could have<br />
been drawn using vector tools.<br />
2.4 Geographic In<strong>for</strong>mation Organization<br />
2.4.1 Map Layers<br />
GIS organizes geographic in<strong>for</strong>mation in terms <strong>of</strong> layers. A layer is a representation <strong>of</strong> geographic<br />
data on a map. For example, vector layers are collections <strong>of</strong> simple geographic elements <strong>of</strong> same type<br />
such as a road network (represented by lines), parcel boundaries (polygons), soil types (polygons),<br />
well locations (points) and so on. Examples <strong>of</strong> raster layers include an elevation surface, satellite<br />
imagery, land use and etc. Within the data frame, each layer that represents a specific geographic<br />
data is displayed and overlaid by the other layers to <strong>for</strong>m a significant geographic representation in<br />
real world [5].<br />
11
2.4.2 Data <strong>The</strong>me<br />
Figure 2.14: Multiple layers geographic representation.<br />
Based on the data themes concept, geographic in<strong>for</strong>mation in GIS could be partitioned into a series<br />
<strong>of</strong> logical in<strong>for</strong>mation layers rather than a random collection <strong>of</strong> objects. Hence, users can organize<br />
in<strong>for</strong>mation in various data themes that described the distribution <strong>of</strong> a phenomenon and how each<br />
one should be represented across a geographic extent.<br />
Many data themes are best represented by a single layer such as soil types or well locations. Other<br />
themes like a transportation framework, are represented by multiple layers, where each feature (such<br />
as streets, intersections, bridges, highway ramps, railroads and so on) is represented by a separate<br />
layer.<br />
Figure 2.15: <strong>The</strong>mes <strong>for</strong> a area [30].<br />
Each GIS can contain multiple themes <strong>for</strong> a common geographic area. <strong>The</strong> collection <strong>of</strong> themes<br />
acts as a stack <strong>of</strong> layers. Each theme can be managed as an in<strong>for</strong>mation set independent <strong>of</strong> other<br />
themes. Each one has its own representation and could be a collection <strong>of</strong> points, lines, polygons,<br />
surfaces, rasters and so on. Because layers are spatially referenced, maybe they overlap one another<br />
and can be displayed in a common map display. So GIS analysis operations like polygon intersection<br />
can combine in<strong>for</strong>mation between layers to discover and work with the derived spatial relationships.<br />
<strong>The</strong> concept <strong>of</strong> layer-based data themes implies that:<br />
• All layers must be georeferenced to a place on the Earth so that they can be combined together.<br />
<strong>The</strong> georeferencing process is accomplished by defining the geographic coordinate system <strong>for</strong><br />
each dataset.<br />
• Layers can be combined in many ways such as following the ordered layers in a map or by<br />
employing operators or commands. Geographic operators can work with the relationships both<br />
12
within and between layers.<br />
• GIS layers can be combined from many sources and many users. In fact, most users are dependent<br />
on one another <strong>for</strong> portions <strong>of</strong> the data they want to use. So interoperability becomes a<br />
fundamental feature in GIS.<br />
2.5 Georeference and Coordinate Systems<br />
2.5.1 Georeference<br />
All elements in a map have a specific geographic location and extent that enable them to be<br />
located on the Earth’s surface. So to georeference something means to describe its existence on the<br />
Earth’s surface. <strong>The</strong> term is used when establishing the relation between raster or vector images and<br />
coordinates or when determining the spatial location <strong>of</strong> other geographical features. Examples would<br />
include establishing the correct position <strong>of</strong> an aerial photograph within a map or finding the geographical<br />
coordinates <strong>of</strong> street address. <strong>The</strong> georeferencing procedure is thus imperative <strong>for</strong> modeling<br />
geographical data in the field <strong>of</strong> geographic in<strong>for</strong>mation systems.<br />
2.5.2 What Is a Coordinate System?<br />
Figure 2.16: Georeferencing a geographic object [26].<br />
A coordinate system is a system that uses coordinates to uniquely determine the location <strong>of</strong> a point<br />
or other geographic element on the Earth. <strong>The</strong>re are two common types <strong>of</strong> coordinate system used in<br />
GIS:<br />
• A global or spherical coordinate system such as latitude-longitude. This system is <strong>of</strong>ten referred<br />
to as geographic coordinate system.<br />
• A projected coordinate system based on map projection. <strong>The</strong>re exist different map projections<br />
that provides various mechanisms to project maps <strong>of</strong> the Earth’s spherical surface onto a twodimensional<br />
Cartesian coordinate plane. Projected coordinate systems are also referred to as<br />
map projections.<br />
Geographic Coordinate Systems<br />
A geographic coordinate system is a coordinate system that enables every location on the Earth<br />
to be specified by a set <strong>of</strong> numbers. <strong>The</strong> coordinates are <strong>of</strong>ten chosen such that one number represents<br />
vertical position and two or three numbers represent horizontal position. A common choice <strong>of</strong><br />
coordinates is latitude and longitude.<br />
Latitude and Longitude are the angles from the center <strong>of</strong> the Earth to a measured point on the<br />
Earth’s surface.<br />
Latitude measures are angles in a north-south direction. <strong>The</strong> equator is at an angle <strong>of</strong> 0. Often,<br />
the northern hemisphere has positive measures <strong>of</strong> latitude and the southern hemisphere has negative<br />
13
measures <strong>of</strong> latitude. Longitude measures are angles in an east-west direction. Longitude measures<br />
are traditionally based on the Prime Meridian, which is an imaginary line running from the North<br />
Pole through Greenwich, England to the South Pole. This line has longitude as 0. West <strong>of</strong> the Prime<br />
Meridian is <strong>of</strong>ten recorded as negative longitude and east is recorded as positive.<br />
Figure 2.17: <strong>The</strong> location <strong>of</strong> the measured point (in red) is latitude plus 40 degrees and longitude plus<br />
50 degrees [26].<br />
Although longitude and latitude can locate exactly any positions on the surface <strong>of</strong> the globe, they<br />
are not uni<strong>for</strong>m in units. Only along the equator, the distance represented by one degree <strong>of</strong> longitude<br />
approximate the distance represented by one degree <strong>of</strong> latitude. This is because the equator is the<br />
only parallel line <strong>of</strong> latitude that is as large as a meridian line <strong>of</strong> longitude.<br />
Figure 2.18: Parallels lines <strong>of</strong> latitude and meridians line <strong>of</strong> longitude [26].<br />
Above and below the equator, the circles defining the parallel lines <strong>of</strong> latitude get gradually smaller<br />
until they become a single point at the North and South Poles. As the meridians converge toward<br />
the poles, the distance represented by one degree <strong>of</strong> longitude decreases to zero. For example, one<br />
degree <strong>of</strong> longitude at the equator equals 111.321 km, while at 60 ◦ latitude, it is only 55.802 km. Since<br />
degrees <strong>of</strong> latitude and longitude don’t have a standard length, distances or areas can not be measured<br />
accurately or display the data easily on a flat map. Efficient GIS analysis and mapping applications<br />
require a more stable coordinate framework, which is provided by projected coordinate systems.<br />
Projected Coordinate Systems using Cartesian coordinates<br />
Projected coordinate systems are any coordinate system designed <strong>for</strong> a flat surface. 2D and<br />
3D Cartesian coordinate systems provide the mechanism <strong>for</strong> describing the geographic location <strong>of</strong><br />
geographic objects using x, y and z values. <strong>The</strong> x,y measurements represent the position on the<br />
Earth’s surface and the z represents the height above or below sea level.<br />
2D Cartesian coordinate system is a coordinate system that uses two axes: one horizontal x<br />
representing east-west and one vertical y representing north-south. <strong>The</strong> point at which these axes<br />
intersect is the origin. Locations <strong>of</strong> objects are defined relatively to the origin using the notation<br />
14
(x,y), where x refers to the distance along the horizontal axis and y refers to the distance along the<br />
vertical axis. <strong>The</strong> origin is defined as (0,0). For example, in Figure 2.19, the notation (4, 3) gives a<br />
point that is four units over in x and three units up in y from the origin.<br />
Figure 2.19: 2D Cartesian coordinate system. [26].<br />
3D Cartesian coordinate system is a coordinate system that uses also a z value to measure<br />
elevation above or below sea level. <strong>The</strong> notation (2, 3, 4) in Figure 2.20 records a point that is two<br />
units over in x and three units in y from the origin and whose elevation is 4 units above the Earth’s<br />
surface such as 4 meters above sea level.<br />
Figure 2.20: 3D Cartesian coordinate system [26].<br />
Since the Earth is spherical, a challenge faced by cartographers is how to represent the real world<br />
using a flat coordinate system. <strong>The</strong> process <strong>of</strong> flattening the Earth is called projection, hence the term<br />
map projection is resulted. Examples <strong>of</strong> various methods <strong>for</strong> map projection are illustrated in Figure<br />
2.21.<br />
Unlike a geographic coordinate system, a projected coordinate system has constant lengths, angles<br />
and areas across the two dimensions. However, all map projections representing the Earth’s surface<br />
create distortions in some aspect <strong>of</strong> distance, area, shape, scale or direction (Figure 2.22). Depend on<br />
user application, many map projections are designed <strong>for</strong> specific purposes. One map projection might<br />
be used <strong>for</strong> preserving shape while another might be used <strong>for</strong> preserving the area.<br />
<strong>The</strong>se properties <strong>of</strong> the map projection are important parameters in the definition <strong>of</strong> the coordinate<br />
system <strong>for</strong> each GIS dataset and each map. With these properties, the geographic locations <strong>of</strong> dataset<br />
elements can be reprojected and trans<strong>for</strong>med into an appropriate coordinate system. As a result, it’s<br />
possible to integrate and combine in<strong>for</strong>mation from multiple GIS layers. This is a fundamental GIS<br />
capability as accurate location <strong>for</strong>ms the basis <strong>for</strong> almost all GIS operations.<br />
15
2.6 GIS Applications<br />
2.6.1 Crime Mapping<br />
Figure 2.21: Different methods <strong>for</strong> map projection [26].<br />
Figure 2.22: Distorsion in map projection [26].<br />
Crime mapping is an application used by analysts in law en<strong>for</strong>cement agencies to map, visualize and<br />
analyse crime incident. Using Geographic In<strong>for</strong>mation Systems, crime analysts can overlay different<br />
datasets (such as census demographics, locations <strong>of</strong> pawn shops, schools and etc.) to identify crime<br />
hot spots, to better understand the underlying causes <strong>of</strong> crime and thus to devise strategies dealing<br />
with the problem, along with other trends and patterns [18].<br />
2.6.2 GIS and Hydrogeology<br />
Nowadays, with increasing demand on surface water resources and 98% <strong>of</strong> the world’s available<br />
fresh water is groundwater, it implies that the demand <strong>for</strong> groundwater will also increase. In fact, in<br />
some places, this resource has already been seriously exploited and even mismanaged (Figure 2.24).<br />
Hence, more knowledge about its disposition is quickly required.<br />
Hydrogeology, a subset <strong>of</strong> hydrology, is concerned with the way in which groundwater is stored and<br />
its availability <strong>for</strong> use. Not as apparent as surface water flows, the description <strong>of</strong> groundwater is a more<br />
complex task than that <strong>of</strong> surface water. Groundwater is water located under the Earth’s surface.<br />
Groundwater moves much more slowly than surface water and is 3-dimensional flow (2-dimensional in<br />
the case <strong>of</strong> surface water flow). Groundwater flow is a function <strong>of</strong> geology and head. That means it<br />
flows from higher head to lower head and its flow path can be predicted by geology.<br />
Head values, geology and groundwater flow direction are the features which may be presented in<br />
GIS. <strong>The</strong>n hydrogeology is especially suited to GIS because groundwater can be characterized spatially<br />
in GIS and analyzed by scientists. For example, in a simple application <strong>of</strong> GIS, the effect <strong>of</strong> a new<br />
feature can be studied on the groundwater. <strong>The</strong> results <strong>of</strong> such study then can be used by decision<br />
makers to determine whether or not to proceed with drilling.<br />
16
Figure 2.23: Mapping <strong>of</strong> homicides in Washington D.C. [18]<br />
Figure 2.24: Groundwater level change <strong>of</strong> the High Plains Aquifer, 1980-95 [31].<br />
17
2.6.3 Traditional Knowledge GIS<br />
Traditional knowledge GIS is designed to document and utilize local knowledge <strong>of</strong> communities<br />
around the world. Traditional knowledge includes the experiences <strong>of</strong> a particular culture or society.<br />
Traditional knowledge GIS is richer than ordinary maps in the sense that they express environmental<br />
and spiritual relationships among real and conceptual entities.<br />
Cultural preservation is the principal application <strong>of</strong> a traditional knowledge GIS. Its central feature<br />
is language revitalization. Bilingual visual and audible maps are used to describe oral traditions and<br />
historical in<strong>for</strong>mation <strong>of</strong> significant cultures on various scales.<br />
18
Chapter 3<br />
Why <strong>PostGIS</strong> <strong>Raster</strong> ?<br />
ORACLE GEO<strong>Raster</strong> is a component that supports continuous fields in ORACLE. Nevertheless,<br />
it sounds complex and cumbersome <strong>for</strong> inexperienced users. <strong>PostGIS</strong> <strong>Raster</strong> is thus designed to<br />
overcome these limitations. This fact will be demonstrated through <strong>PostGIS</strong> <strong>Raster</strong> goals and how<br />
Oracle Geo<strong>Raster</strong> and <strong>PostGIS</strong> <strong>Raster</strong> are different in architecture, physical storage, indexing and<br />
overlapping, along with some principal operations when working with raster data.<br />
3.1 Goals<br />
<strong>PostGIS</strong> <strong>Raster</strong>, an extension <strong>of</strong> <strong>PostGIS</strong>, implements a new raster data type that adapts to<br />
diversity <strong>of</strong> applications by achieving four objectives [6]:<br />
3.1.1 Simplicity and Complementarity<br />
Seen a raster type is designed to adapt to diversity <strong>of</strong> applications, then the first objective <strong>of</strong><br />
<strong>PostGIS</strong> <strong>Raster</strong> is to provide a simple loader to import rasters into database. <strong>The</strong> loader allows users<br />
to load a single raster or a set <strong>of</strong> rasters once. This new data type complements the existing <strong>PostGIS</strong><br />
vector type in the sense that it works in the same way as the one <strong>of</strong> vector type, but instead <strong>of</strong><br />
association with geometric elements, raster relates to a matricial data structure.<br />
3.1.2 Transparent Integration with Vector<br />
<strong>PostGIS</strong> <strong>Raster</strong> provides a set <strong>of</strong> similar operators and functions with those available <strong>for</strong> vector<br />
type to support raster. In this way, users can use their knowledge about vector type to expect similar<br />
behaviors when using these operator and functions. Thus it enhances user’s interaction with geospatial<br />
applications.<br />
About developers, a single SQL paradigm <strong>for</strong> both raster and vector types will help them write<br />
better GIS applications. Developers will build a unique graphical user interface <strong>for</strong> both raster and<br />
vector data.<br />
3.1.3 Storage Flexibility<br />
In addition to traditional storage (in-database storage), <strong>PostGIS</strong> <strong>Raster</strong> allows user to simply register<br />
only metadata <strong>of</strong> raster images stored in the filesystem (out-database storage). When retrieving these<br />
out-database rasters from database, they are accessed directly from the filesystem.<br />
3.1.4 Interoperability<br />
<strong>PostGIS</strong> <strong>Raster</strong> uses Geospatial Data Abstraction Library (GDAL) [25] to load rasters into the<br />
database and to work with out-database rasters. With GDAL, <strong>PostGIS</strong> <strong>Raster</strong> can work with nearly<br />
a hundred file <strong>for</strong>mats 1 ).<br />
1 http://www.gdal.org/<strong>for</strong>mats_list.html.<br />
19
<strong>The</strong>se additional functionalities make <strong>PostGIS</strong> <strong>Raster</strong> more than just a new raster <strong>for</strong>mat but also<br />
a necessary complement to <strong>PostGIS</strong>.<br />
3.2 <strong>PostGIS</strong> <strong>Raster</strong> Versus ORACLE GEO<strong>Raster</strong><br />
3.2.1 Architecture<br />
General Architecture<br />
In general, tools supporting raster data include five components [3]:<br />
Characteristics Oracle GeoRASTER <strong>PostGIS</strong> <strong>Raster</strong><br />
SQL API Standard SQL A single set <strong>of</strong> SQL<br />
functions <strong>for</strong> vector and<br />
raster data<br />
Accessing to Java, Oracle Call Interface (OCI), Oracle C++ Call <strong>PostGIS</strong> SQL API<br />
raster data Interface (OCCI), and Geo<strong>Raster</strong> SQL API<br />
Viewing tools Oracle Fusion Middleware MapViewer, Open- QGIS and gvGIS<br />
Import/Export<br />
data<br />
JUMP<br />
Extract, trans<strong>for</strong>m and load (ETL) GDAL allows loading a<br />
single raster or a set <strong>of</strong><br />
Data <strong>for</strong>mats Six standard image <strong>for</strong>mats: GeoTIFF, DEM,<br />
PNG, BMP, GIF, and JPEG<br />
Data Architecture<br />
rasters<br />
As many image <strong>for</strong>mats<br />
as GDAL does [21]<br />
In Oracle GeoRASTER, each image is stored as a single object <strong>of</strong> type SDO_GEORASTER. A Geo<strong>Raster</strong><br />
table is a table which has at least one data column <strong>of</strong> type SDO_GEORASTER. SDO_GEORASTER objects<br />
include metadata and in<strong>for</strong>mation about how to retrieve Geo<strong>Raster</strong> data which is stored in another<br />
table, called a <strong>Raster</strong> Data Table (RDT). Geo<strong>Raster</strong> data is an object <strong>of</strong> type SDO_RASTER which<br />
includes a Binary Larger Object (BLOB) column called RASTERBLOCK storing the raster blocks (<strong>The</strong><br />
core <strong>of</strong> raster data can be partioned into small blocks <strong>for</strong> optimal storage and retrieval). A block is<br />
also called a tile [3].<br />
Figure 3.1: Geo<strong>Raster</strong> data architecture [3].<br />
Other in<strong>for</strong>mation associated with the Geo<strong>Raster</strong> objects can be stored in separate columns or<br />
tables, such as a Value Attribute Table (VAT).<br />
More simply, <strong>PostGIS</strong> <strong>Raster</strong> uses only one type raster to store a raster image. Like the geometry<br />
type, the raster type is a complex type, embedding in<strong>for</strong>mation about raster itself with its georeference.<br />
In <strong>PostGIS</strong> <strong>Raster</strong>, there is no table <strong>for</strong> storing the raster data (like Oracle Spatial SDO_RASTER)<br />
and another table <strong>for</strong> storing the georeference and the metadata (like Oracle Spatial SDO_GEORASTER).<br />
20
Figure 3.2: <strong>PostGIS</strong> <strong>Raster</strong> data architecture.<br />
Everything is stored in a single attribute and raster attributes composing a table are not necessarily<br />
related to each other to <strong>for</strong>m a significant coverage.<br />
<strong>PostGIS</strong> <strong>Raster</strong> uses in addition a raster_columns table to contain in<strong>for</strong>mation about which<br />
tables have a raster column and the metadata (pixeltype, block size, nodata value and etc.) <strong>of</strong> the<br />
rasters in these columns.<br />
3.2.2 Physical Storage<br />
Geo<strong>Raster</strong> data consists <strong>of</strong> a multidimensional matrix <strong>of</strong> cells and the Geo<strong>Raster</strong> metadata. <strong>The</strong><br />
multidimensional matrix is blocked into small blocks. A block (or tile) is stored as a BLOB and a<br />
geometry object <strong>of</strong> type SDO\_GEOMETRY is used to define the spatial extent (footprint) <strong>of</strong> the block.<br />
Each block and in<strong>for</strong>mation related to that block are stored in one row. Thus <strong>for</strong> storing an image<br />
having size greater than block size, at least two rows are necessary to be used in Oracle database table<br />
[3].<br />
To do this, Geo<strong>Raster</strong> requires two types <strong>of</strong> object:<br />
• <strong>The</strong> SDO_GEORASTER type contains spatial extent geometry and metadata.<br />
• <strong>The</strong> SDO_RASTER contains a BOLB storing a block and the block in<strong>for</strong>mation.<br />
Each SDO_GEOMETRY data has a pair <strong>of</strong> attributes (rasterDataTable, rasterID) that identify the<br />
RDT and the rows within the RDT that are used to store the raster data.<br />
For Example, Figure 3.3 shows the storage <strong>of</strong> Geo<strong>Raster</strong> object used <strong>for</strong> an image <strong>of</strong> Boston,<br />
Massachusetts, where:<br />
• Each row in the table <strong>of</strong> city images contains in<strong>for</strong>mation about the image <strong>for</strong> a specific city<br />
(such as Boston), including an SDO_GEORASTER object.<br />
• <strong>The</strong> SDO_GEORASTER object includes the spatial extent geometry covering the entire area <strong>of</strong> the<br />
image, the metadata, the raster ID and the name <strong>of</strong> the raster data table associated with this<br />
image.<br />
• Each row in the raster data table contains in<strong>for</strong>mation about a block (or tile) <strong>of</strong> the image,<br />
including the block’s minimum bounding rectangle (MBR) and image data (stored as a BLOB).<br />
A MBR is defined as a single rectangle that minimally encloses a geometry or a collection <strong>of</strong><br />
geometries.<br />
In <strong>PostGIS</strong> <strong>Raster</strong>, the raster type is a complex type composed <strong>of</strong> many attributes like attribute,<br />
georeference in<strong>for</strong>mation, band in<strong>for</strong>mation and band data. Thus a single raster attribute can contain<br />
all in<strong>for</strong>mation about raster itself (width, height, number <strong>of</strong> bands, pixel type <strong>for</strong> each band, nodata<br />
21
Figure 3.3: Physical storage <strong>of</strong> Geo<strong>Raster</strong> data [3].<br />
value and data values <strong>for</strong> each band) with its georeference (pixel type, upper left pixel center, rotation<br />
and spatial reference system identifier (SRID)).<br />
A single raster attribute may be composed <strong>of</strong> many bands having a common size, pixel size and<br />
georeference. <strong>The</strong> storage used <strong>for</strong> raster bands is band sequential (BSQ) in which each band has its<br />
pixel type and its nodata value.<br />
One table with a column <strong>of</strong> type raster is called raster coverage. One table row with a column <strong>of</strong><br />
type raster is called tile. Thus there are no differences between rasters and tiles. A tile is a raster and<br />
a raster is a tile in which each tile has all that are necessary to do basic raster operations.<br />
Figure 3.4: Physical storage <strong>of</strong> <strong>PostGIS</strong> <strong>Raster</strong> data.<br />
Another important advantage <strong>of</strong> <strong>PostGIS</strong> <strong>Raster</strong> over Oracle Geo<strong>Raster</strong> is the georeferencing<br />
approach [14]. As Oracle Geo<strong>Raster</strong> uses a one-georeference-by-layer georeference schema instead <strong>of</strong><br />
one-georeference-by-raster one, so non-continuous raster data cannot be stored in the same raster data<br />
table. That means that Oracle Geo<strong>Raster</strong> requires one raster data table <strong>for</strong> each raster file loaded<br />
when these raster files are from irregular raster coverage. In contrast, <strong>PostGIS</strong> <strong>Raster</strong> allows only one<br />
table <strong>for</strong> all kinds <strong>of</strong> raster coverages, regular or not.<br />
In addition to this traditional storing method (storing in-database raster), <strong>PostGIS</strong> <strong>Raster</strong> enables<br />
user to simply register basic metadata (path to the actual file, pixeltype, with, height, georeference)<br />
<strong>of</strong> images stored in the file system, without having to load their data values into the database. This is<br />
22
Figure 3.5: Oracle Geo<strong>Raster</strong> georeference approach [14].<br />
Figure 3.6: <strong>PostGIS</strong> <strong>Raster</strong> georeference approach [14].<br />
referred to as storing out-database raster. With the second method, web or desktop applications may<br />
access out-database rasters directly from the filesystem (such as JPEG files) and use most transparently<br />
<strong>PostGIS</strong> <strong>Raster</strong> operators and functions on those rasters.<br />
3.2.3 Indexing<br />
<strong>The</strong> most important index is created on a Geo<strong>Raster</strong> object is a spatial index on the spatial extent<br />
geometry <strong>of</strong> the Geo<strong>Raster</strong> object. Oracle Geo<strong>Raster</strong> creates spatial indexes over the footprint <strong>of</strong> raster<br />
data while <strong>PostGIS</strong> <strong>Raster</strong> creates GiST indexes over the raster data itself. In Oracle Geo<strong>Raster</strong>,<br />
spatial operations (like intersection) can only be done with the MBR <strong>of</strong> the data as the indexes are<br />
created over the spatial extent. In <strong>PostGIS</strong> <strong>Raster</strong>, user can do really complex operations with raster<br />
data like getting a set <strong>of</strong> geometry and geometry value from a given raster band (ST_DumAsPolygons()<br />
function). <strong>The</strong>n, creating indexes over these raster data has more sense [15].<br />
<strong>PostGIS</strong> <strong>Raster</strong> uses GDAL driver to calculate the georeferenced coordinates <strong>for</strong> upper and lower<br />
corners (the spatial extent or footprint) <strong>of</strong> a raster. In this case, its spatial extent is the enclosing<br />
geometry. Nervertheless, this is not necessarily in this way <strong>for</strong> Oracle Geo<strong>Raster</strong>.<br />
In Geo<strong>Raster</strong>, one <strong>of</strong> the prerequisites <strong>for</strong> creating a spatial index over a geometry column is<br />
that the USER_SDO_GEOM_METADATA view must contain an entry with the dimensions and coordinate<br />
boundary in<strong>for</strong>mation <strong>for</strong> the table column to be spatially indexed. So the following code will create<br />
spatial index on the spatial extent geometry <strong>of</strong> the Geo<strong>Raster</strong> objects stored in table spain_images:<br />
DELETE FROM user_sdo_geom_metadata<br />
WHERE table_name = ’spain_images’<br />
AND column_name = ’IMAGE.SPATIALEXTENT’;<br />
INSERT INTO user_sdo_geom_metadata<br />
VALUES (’spain_images’,’IMAGE.SPATIALEXTENT’,<br />
SDO_DIM_ARRAY(SDO_DIM_ELEMENT(’X’, -180, 180, .00000005),<br />
SDO_DIM_ELEMENT(’Y’, -90, 90, .00000005)), 4326);<br />
23
DROP INDEX spain_images_idx;<br />
CREATE INDEX spain_images_idx<br />
ON spain_images(image.spatialExtent)<br />
INDEXTYPE IS mdsys.spatial_index;<br />
In contrast, <strong>PostGIS</strong> <strong>Raster</strong> loads raster data and creates spatial index using simply these two<br />
commands:<br />
python raster2pgsql.py -r *.tif -t spain_images -s 4326 -k 50x50 -I -o spain.sql<br />
psql -d postgis_db -f spain.sql<br />
<strong>The</strong> first command uses Python loader to import a set <strong>of</strong> raster images into raster table spain_images<br />
(option -t). Option -I is used to create indexes over these rasters. All necessary code is created and<br />
registered in a SQL file spain.sql (option -o). <strong>The</strong>n, the second command will execute spain.sql<br />
in <strong>PostGIS</strong> database.<br />
3.2.4 Overlapping <strong>Raster</strong> and Vector Layers<br />
Each spatial instance has a spatial reference identifier (SRID). However, the result <strong>of</strong> any spatial<br />
method from two spatial instances is valid only if those instances that have the same SRID. It is the<br />
same in the case <strong>of</strong> overlapping operation between vector and raster data.<br />
To reset SRID <strong>of</strong> a geometry object, Geo<strong>Raster</strong> uses sdo_cs.trans<strong>for</strong>m() function [14]:<br />
SELECT sdo_cs.trans<strong>for</strong>m(geom, srid_number) geom FROM geom_table ;<br />
In the same way in <strong>PostGIS</strong> <strong>Raster</strong>:<br />
SELECT ST_Trans<strong>for</strong>m(the_geom, srid_number)) FROM geom_table;<br />
3.2.5 Loading <strong>Raster</strong> Data<br />
Loading Using Oracle Geo<strong>Raster</strong><br />
To load raster image into Geo<strong>Raster</strong>, firstly users need to create tables to store the raster data.<br />
One table stores the metadata and another one stores the data [14]:<br />
CREATE TABLE spain_images (image_id NUMBER PRIMARY KEY,<br />
image_description VARCHAR2(50), image SDO_GEORASTER);<br />
CREATE TABLE spain_images_rdt OF SDO_RASTER<br />
(PRIMARY KEY (rasterID, pyramidLevel, bandBlockNumber, rowBlockNumber,<br />
columnBlockNumber))<br />
TABLESPACE users LOB(rasterBlock) STORE AS SECUREFILE lobseg (NOCACHE);<br />
<strong>The</strong>n, the image is loaded using PL/SQL code:<br />
DECLARE<br />
geor SDO_GEORASTER;<br />
BEGIN<br />
-- Initialize an empty Geo<strong>Raster</strong> object into which the external image<br />
-- is to be imported.<br />
INSERT INTO spain_images<br />
VALUES( 1, ’Spain_TIFF_1’, sdo_geor.init(’spain_images_rdt’) );<br />
-- Import the TIFF image.<br />
SELECT image INTO geor FROM spain_images<br />
WHERE image_id = 1 FOR UPDATE;<br />
24
sdo_geor.importFrom(geor, ’blocksize=(256,256)’, ’TIFF’, ’file’, ’srtm_new.tif’);<br />
UPDATE spain_images SET image = geor WHERE image_id = 1;<br />
END;<br />
<strong>The</strong> same operation is repeated <strong>for</strong> every image file. If these images <strong>for</strong>m a non-continuous coverage,<br />
two new tables are needed <strong>for</strong> each image file.<br />
Loading Using <strong>PostGIS</strong> <strong>Raster</strong><br />
When loading raster data by using GDAL driver, the loader creates all that are necessary to store<br />
the raster data into a SQL file. It consists <strong>of</strong> creating the needed tables, the indexes (if it is specified)<br />
and inserting raster data into the tables. A single or a set <strong>of</strong> raster images can be loaded all only once.<br />
Example:<br />
python raster2pgsql.py -r path\*.tif -t srtm_tiled -s 4326 -k 50x50 -I -M<br />
-o srtm.sql<br />
Next step is to execute the srtm.sql file using psql:<br />
psql -d postgis_db -f srtm.sql -U user -W<br />
3.2.6 Intersecting <strong>Raster</strong> and Vector Layers<br />
Intersecting in Oracle Geo<strong>Raster</strong><br />
It is impossible to intersect directly raster and vector data in Oracle Geo<strong>Raster</strong>. Instead, what user<br />
can do is to select a sampling window to clip an area <strong>of</strong> the raster and get raster data over this area.<br />
<strong>The</strong> sampling windows must be rectangular or the round windows cannot be used (As described in<br />
SDO_GEOR.generateStatistics documentation 2 ). So the MBR is used as solution.<br />
In the following example, the sampling windows are the geometry objects stored in sampling_win table.<br />
<strong>The</strong> request will calculate the intersection between the sampling windows and the spatial extent <strong>of</strong><br />
the Geo<strong>Raster</strong> objects [15]:<br />
DECLARE<br />
cellCoordinate mdsys.sdo_geometry;<br />
ret varchar2(256);<br />
gr sdo_georaster;<br />
BEGIN<br />
-- Intersect spatial extent <strong>of</strong> the rasters with the sampling windows<br />
(SELECT t.id, t.geom, r.image_id as rid<br />
FROM spain_images r, sampling_win t<br />
WHERE sdo_geom.sdo_intersection(r.image.spatialExtent, t.geom, 0.005) is not null)<br />
END;<br />
Intersecting in <strong>PostGIS</strong> <strong>Raster</strong><br />
<strong>PostGIS</strong> <strong>Raster</strong> uses st_intersection() and st_intersects() functions, that operate directly<br />
on raster and vector data, to calculate the intersection. Be<strong>for</strong>e doing the intersection, the<br />
st_intersects() will check which portion <strong>of</strong> raster is intesected by vector. So the st_intersection()<br />
intersects vector with raster by vectorizing only the necessary part <strong>of</strong> the raster [8]:<br />
CREATE TABLE vector_srtm_inter AS<br />
SELECT id, (gv).geom AS the_geom, (gv).val<br />
FROM ( SELECT id, ST_Intersection(rast, the_geom) AS gv<br />
FROM srtm_tiled, vector_data<br />
WHERE ST_Intersects(rast, the_geom)<br />
) inter;<br />
2 http://docs.oracle.com/cd/B28359_01/appdev.111/b28398/geor_ref.htm#CHEDCICI.<br />
25
In summary, the intersection is much slower than one in Geo<strong>Raster</strong> <strong>for</strong> two reasons:<br />
• To intersect vector and raster data, firstly raster has to be polygonized, then the result is the<br />
intersection between these polygons with vector data. In this process, polygonizing is a complex<br />
operation.<br />
• In Oracle, the raster data is sampled using rectangular windows. So the intersection is only<br />
per<strong>for</strong>med between these MBRs with vector data while the vector data intersected by the raster<br />
data in <strong>PostGIS</strong> <strong>Raster</strong> are in some <strong>for</strong>ms [15].<br />
26
Chapter 4<br />
<strong>PostGIS</strong> <strong>Raster</strong><br />
This section deals with representing raster structure and explaining from how raster is stored to<br />
the mechanisms used to index, retrieve raster in <strong>PostgreSQL</strong>. It is also important to address the way<br />
that raster and vector layers overlap - a relevant feature that makes <strong>PostGIS</strong> <strong>Raster</strong> more robust than<br />
ORACLE GEO<strong>Raster</strong>.<br />
4.1 Implementation<br />
<strong>PostGIS</strong> <strong>Raster</strong> chooses to implement a minimal raster data structure. That means that a raster<br />
type is as simple as a single type and is stored in a single table. This data structure is very similar<br />
to the one <strong>of</strong> <strong>PostGIS</strong> vector data and very different from the Oracle Spatial SDO_GEORASTER and<br />
SDO_RASTER raster structures. In <strong>PostGIS</strong> <strong>Raster</strong>:<br />
• One table with a column <strong>of</strong> type raster is referred to as a raster coverage.<br />
• One table row with a column <strong>of</strong> type raster corresponds to one tile.<br />
<strong>The</strong> choice <strong>of</strong> such simple data structure will facilitate the achievement <strong>of</strong> four objectives described<br />
in Chapter 3. With a single raster type, it implies that each raster attribute is a complete and self<br />
sufficient georeferenced raster. So raster attributes composing a table are not necessarily related to<br />
each other to <strong>for</strong>m a significant coverage. This also means that:<br />
• <strong>Raster</strong>s from the same table may have different size.<br />
• <strong>The</strong> upper left corner and the pixel size <strong>of</strong> a raster are not necessarily the same values as those<br />
<strong>of</strong> another rasters. <strong>The</strong>y may there<strong>for</strong>e snap to different grids.<br />
• Finally, different rasters may overlap like polygons in a vector layer may overlap. This is a<br />
fundamental feature to implement meaningful vector to raster conversions in which all attributes<br />
<strong>of</strong> a vector are conserved in the resulting raster table. In this case, if the vector features and the<br />
data values part <strong>of</strong> the resulting raster features do not necessarily overlap, the nodata values <strong>of</strong><br />
the raster features will overlap.<br />
In addition, <strong>PostGIS</strong> <strong>Raster</strong> provides also a raster_columns table to help application get a quick<br />
overview <strong>of</strong> raster tables and in<strong>for</strong>mation (such as metadata) related to the rasters stored in these<br />
tables.<br />
4.2 Structure<br />
<strong>PostGIS</strong> <strong>Raster</strong> implements only one type <strong>of</strong> raster instead <strong>of</strong> two like SDO_GEORASTER and<br />
SDO_RASTER in Oracle Spatial. It supports no metadata when a raster contains all data about itself<br />
such as attribute in<strong>for</strong>mation, georeference in<strong>for</strong>mation, band in<strong>for</strong>mation and band data. Figure<br />
?? describes these components in details [6]. As shown in this figure, a raster has no mask and<br />
27
Attribute in<strong>for</strong>mation<br />
Table 4.1: <strong>PostGIS</strong> <strong>Raster</strong> structure.<br />
Description Storage<br />
version <strong>Raster</strong> <strong>for</strong>mat version unsigned 16 bit<br />
integer<br />
band number Number <strong>of</strong> raster bands stored in<br />
the raster<br />
unsigned 16 bit<br />
integer<br />
width Width <strong>of</strong> the raster unsigned 16 bit<br />
integer<br />
heigh Height <strong>of</strong> the raster unsigned 16 bit<br />
integer<br />
Georeference in<strong>for</strong>mation<br />
Description Storage<br />
pixelsizex Pixel size in the x-direction in the<br />
same map units as the coordinate<br />
system<br />
pixelsizey Pixel size in the y-direction in the<br />
same map units as the coordinate<br />
system<br />
upperleftx X-coordinate <strong>of</strong> the center <strong>of</strong> the upper<br />
left pixel<br />
upperlefty Y-coordinate <strong>of</strong> the center <strong>of</strong> the upper<br />
left pixel<br />
64 bit double<br />
64 bit double<br />
64 bit double<br />
64 bit double<br />
rotationx Rotation about x-axis 64 bit double<br />
rotationy Rotation about y-axis 64 bit double<br />
srid Y-coordinate <strong>of</strong> the center <strong>of</strong> the upper<br />
left pixel<br />
32 bit integer<br />
Band in<strong>for</strong>mation<br />
(one set per band)<br />
Description Storage<br />
is<strong>of</strong>fline Flag specifying if raster data is<br />
stored in the database or as a file<br />
in the file system<br />
1 bit<br />
hasnodatavalue Flag specifying if nodatavalue exists<br />
or not<br />
1 bit<br />
pixeltype Pixel type <strong>of</strong> the band 4 bits<br />
nodatavalue Nodata value <strong>of</strong> the band Depend on band<br />
pixel type<br />
Band data (one<br />
set per band) <strong>for</strong><br />
in-db raster<br />
Description Storage<br />
values[] An array <strong>of</strong> pixel values Depends on band<br />
pixel type and size<br />
Band data (one<br />
set per band) <strong>for</strong><br />
out-db raster<br />
Description Storage<br />
bandnumber Number <strong>of</strong> the out-db band unsigned 8 bit integer<br />
path Path to the out-db raster file string<br />
28
Figure 4.1: <strong>PostGIS</strong> <strong>Raster</strong> implementation.<br />
no pyramid propeties when a mask can be created as an independent band and reduced resolution<br />
coverages can be stored as a separate layer.<br />
So a single raster has everything essential to do basic GIS raster operations. It is thus not necessarily<br />
related to other rasters in the same table to be georeferenced. This choice makes <strong>PostGIS</strong><br />
<strong>Raster</strong> very simple and flexible.<br />
4.3 Spatial Reference Identifier<br />
A spatial reference system (SRS) or coordinate reference system (CRS) is a coordinate-based local,<br />
regional or global system used to locate geographical entities. A spatial reference system defines a<br />
specific map projection, as well as trans<strong>for</strong>mations between different spatial reference systems.<br />
A spatial reference system identifier (SRID) is a unique value used to identify projection and local<br />
spatial coordinate system. <strong>The</strong>se coordinate systems <strong>for</strong>m the heart <strong>of</strong> all GIS applications. In other<br />
words, SRID values associated with spatial objects can be used to constrain spatial operations. For<br />
instance, spatial operations (such as intersection, trans<strong>for</strong>mation and etc.) can not be per<strong>for</strong>med<br />
between spatial objects with different SRIDs. Or, the result <strong>of</strong> any spatial method derived from two<br />
spatial objects is valid only if they have the same SRID that is based on the same unit <strong>of</strong> measurement<br />
and projection.<br />
4.4 <strong>Raster</strong> Data<br />
<strong>Raster</strong> data is a matrix <strong>of</strong> cells (or pixels) organized into rows and columns (or a grid) where each<br />
cell contains a value representing in<strong>for</strong>mation. Unlike vector <strong>for</strong>mat, data stored in raster <strong>for</strong>mat can<br />
be used to represent various real world phenomena like [16]:<br />
• Land use or soils data which is classified as discrete data.<br />
• Temperature, elevation or spectral data that comes from satellite images and aerial photographswhich<br />
are classified as continuous data.<br />
• Pictures such as scanned maps or photographs <strong>of</strong> drawings and buildings.<br />
4.4.1 Usage<br />
With a simple data structure, raster is exceptionally useful <strong>for</strong> a wide range <strong>of</strong> applications. In<br />
GIS, the uses <strong>of</strong> raster data falls under four main categories:<br />
• Base maps A common way to use raster is as a background <strong>for</strong> displaying other vector layers.<br />
Three main sources <strong>of</strong> raster based maps are orthophotos, satellite imagery and scanned maps.<br />
29
Figure 4.2: In<strong>for</strong>mation representation using raster data [16].<br />
An thophoto, thophotograph or thoimage is an aerial photograph geometrically corrected such<br />
that the scale is uni<strong>for</strong>m: the photo has the same lack <strong>of</strong> distortion as a map. Unlike an uncorrected<br />
aerial photograph, an orthophotograph can be used to measure true distances because<br />
it is an accurate representation <strong>of</strong> the Earth’s surface, being adjusted <strong>for</strong> topographic relief 1 ,<br />
lens distortion 2 and camera tilt 3 . When orthophotographs are displayed underneath other<br />
layers, they provide user with confidence that map layers are spatially aligned and represent real<br />
objects.<br />
Figure 4.3: Basemap raster <strong>for</strong> road data [16].<br />
• Continuous maps Due to the matrix <strong>of</strong> cells structure, rasters are well suited <strong>for</strong> representing<br />
and storing data that changes continuously across a surface. Elevation values measured from<br />
the Earth’s surface are the most common application <strong>of</strong> surface maps. For example, raster in<br />
Figure 4.4 displays elevation, where green cells show lower elevation and red, pink and white cells<br />
show higher elevation. Other values, such as rainfall, temperature, concentration and population<br />
density, can also be used in spatial analysis as cells representing surfaces are regularly spaced.<br />
• <strong>The</strong>matic maps <strong>Raster</strong>s representing thematic data can be derived from other data through<br />
analyzing operations. A common analysis application is classifying a satellite image by landcover<br />
categories. Basically, this activity groups the values <strong>of</strong> data into classes (such as vegetation<br />
type) and assigns a categorical value. Figure 4.5 is an example <strong>of</strong> a classified raster data that<br />
expresses the human use <strong>of</strong> land. <strong>The</strong>matic maps can also result from geoprocessing operations<br />
that combine data from various sources such as vector, raster and terrain data. For example,<br />
user can process data through a geoprocessing model to create raster data that maps suitability<br />
<strong>for</strong> a specific activity.<br />
• User-defined attributes Digital photography and scanner are output devices that capture real<br />
world phenomena into digital world <strong>for</strong> long-term storage. <strong>Raster</strong> data is means by which digital<br />
1 http://en.wikipedia.org/wiki/Topography.<br />
2 http://en.wikipedia.org/wiki/Barrel_distortion.<br />
3 http://en.wikipedia.org/wiki/Camera_tilt.<br />
30
Figure 4.4: Surface map raster [16].<br />
Figure 4.5: <strong>The</strong>matic map raster [16].<br />
photographs, scanned documents or scanned drawings are conserved. Via raster representation,<br />
these real phenomena can also be used as user-defined attributes <strong>of</strong> a geographic object. For<br />
example, a parcel layer may have scanned legal documents identifying the latest transaction <strong>for</strong><br />
that parcel. Or, a layer representing cave openings may have pictures <strong>of</strong> the actual cave openings<br />
associated with the point features. Concretely, a real tree represented by the digital picture in<br />
Figure 4.6 can be used as an attribute to a landscape layer that a city may maintain.<br />
4.4.2 Cell Representation<br />
Figure 4.6: Tree attribute [16].<br />
<strong>Raster</strong> data is made up <strong>of</strong> a matrix <strong>of</strong> cells (or pixels), where each cell contains a value. In other<br />
words, the cell values are used to represent phenomenon described by the raster data such as a category,<br />
magnitude, height or spectral value. <strong>The</strong> category can be a land-use class such as grassland, <strong>for</strong>est<br />
or road. A magnitude might represent gravity, noise pollution or percent rainfall. Height (distance)<br />
can represent surface elevation above mean sea level, which can be used to derive slope, aspect and<br />
watershed properties. Spectral values are used in satellite imagery and aerial photography to represent<br />
light reflectance and color.<br />
Cell values can be either positive or negative, integer or floating point. Integer values are best used<br />
31
<strong>for</strong> discrete data while floating-point values are suited <strong>for</strong> continuous data (such as surfaces). Cells<br />
can also have a noData value to indicate the absence <strong>of</strong> data.<br />
Depend on represented data, there are two ways to apply a value to a cell. Generally, when the cell<br />
value represents a measure as in the case <strong>of</strong> elevation, it is applied at the center <strong>of</strong> the cell. However,<br />
in most cases, the cell value is resulted from a sampling <strong>of</strong> a phenomenon, so it is applied <strong>for</strong> the whole<br />
cell square.<br />
Figure 4.7: On the left side: cell values applied at the center point. On the right side: cell values<br />
applied <strong>for</strong> the whole square.<br />
<strong>Raster</strong> data is stored as an ordered list <strong>of</strong> cell values. For example, such a raster in Figure 4.8 will<br />
be stored as a list <strong>of</strong> 80, 74, 62, 45, 45, 34 and so on.<br />
Figure 4.8: <strong>Raster</strong> cell values [16].<br />
<strong>The</strong> area represented by each cell consists <strong>of</strong> the same width and height and equals a portion <strong>of</strong><br />
the entire surface represented by the raster. For example, a raster representing elevation may cover<br />
an area <strong>of</strong> 100 square kilometers. If there were 100 cells in this raster, each cell would represent one<br />
square kilometer <strong>of</strong> 1 km in width and 1 km in height.<br />
<strong>The</strong> dimension <strong>of</strong> the cell can be as large or as small as needed to represent the surface conveyed<br />
by the raster and the objects within this surface. In other words, the cell size determines how coarse<br />
or fine the objects in the raster will appear. <strong>The</strong> smaller the cell size is, the smoother the raster will<br />
be. However, when decreasing the cell size to get better image, the number <strong>of</strong> cell will increase as the<br />
surface size is maintained. A large number <strong>of</strong> cells will take long time to process and demands more<br />
storage space. In contrast, if a cell size is too large, in<strong>for</strong>mation may be lost or subtle patterns may<br />
be obscured. For example, if the cell size is larger than the width <strong>of</strong> a road, the road may not exist<br />
within the raster dataset. In Figure 4.10, it shows how does the polygon look like as it is represented<br />
at various cell sizes.<br />
<strong>The</strong> location <strong>of</strong> each cell is defined by the row or column where it is located within the raster<br />
matrix. Essentially, the matrix is represented by a Cartesian coordinate system, in which the rows <strong>of</strong><br />
32
Figure 4.9: <strong>Raster</strong> cell [16].<br />
Figure 4.10: <strong>Raster</strong> resolution [16].<br />
33
the matrix are parallel to the x-axis and the columns to the y-axis <strong>of</strong> the Cartesian plane. Row and<br />
column values begin with 0.<br />
Figure 4.11: Pixel or cell location.<br />
<strong>The</strong> extent <strong>of</strong> a raster then is defined by the top, bottom, left and right coordinates <strong>of</strong> the rectangular<br />
covered by the raster, as shown in Figure 4.12 .<br />
4.4.3 Zones and Regions<br />
Zones<br />
Figure 4.12: <strong>Raster</strong> extent [16].<br />
Any two or more cells with the same value belong to the same zone. A zone consists <strong>of</strong> cells that are<br />
adjacent, disconnected or both. Zones whose cells are adjacent usually represent a single feature such<br />
as a building, lake, road or water body. Assemblages <strong>of</strong> entities, such as <strong>for</strong>est stands in a state, soil<br />
types in a county or single-family houses in a town, are features that will most likely be represented<br />
by zones made up <strong>of</strong> many disconnected groups <strong>of</strong> connected cells.<br />
Every cell in a raster belongs to a zone. Some raster data contains only a few zones while others<br />
contain many.<br />
Regions<br />
Each group <strong>of</strong> connected cells in a zone is considered a region. A zone that consists <strong>of</strong> a single<br />
group <strong>of</strong> connected cells has only one region. Zones can be composed <strong>of</strong> as many regions as necessary<br />
to represent a feature. In the example <strong>of</strong> Figure 4.13, zone 2 consists <strong>of</strong> two regions, zone 4 <strong>of</strong> three<br />
regions and zone 5 <strong>of</strong> one region.<br />
34
4.4.4 Representing Features<br />
Figure 4.13: <strong>Raster</strong> zones and regions [32].<br />
In raster data, the cell typically represents the predominant phenomenon <strong>of</strong> the area covered by<br />
a cell, whereas vector data can accurately identify individual features. This is due to the fact that<br />
when representing geographic features using raster data, features are nothing more than collections<br />
<strong>of</strong> cells with the same attribute values and thus lose their unique identities. <strong>Raster</strong> data is best used<br />
when the primary problem concerns with the locational relationships <strong>of</strong> the phenomena represented<br />
by geographic features and not the features themselves.<br />
Discrete Data<br />
Discrete data, which is sometimes called thematic, categorical or discontinuous data, is used to<br />
describe discrete objects and can be expressed in both vector and raster <strong>for</strong>mats. A discrete object has<br />
always precise boundaries. So it is easy to define where the object begins and where it ends as well as<br />
how to compose them from discrete features like points, lines and polygons. A lake is a discrete object<br />
surrounded by landscape. Other examples <strong>of</strong> discrete objects include buildings, roads and parcels.<br />
Points<br />
Figure 4.14: Discrete data represented in raster <strong>for</strong>mat [33].<br />
A point is represented by an explicit x,y coordinate in vector <strong>for</strong>mat. However, in raster <strong>for</strong>mat,<br />
it is a single cell, the smallest unit <strong>of</strong> a raster. By definition, a point has no area but will represent<br />
an area when it is converted to a cell. For example, a telephone pole or the location <strong>of</strong> an endangered<br />
plant will occupy the entire area covered by a cell. <strong>The</strong>re<strong>for</strong>e, the smaller the cell size, the smaller the<br />
area and thus the closer the representation <strong>of</strong> the point feature.<br />
As a raster point has the same size as the size <strong>of</strong> the cell. So the cell size has to be chosen small<br />
enough to capture sufficient input points <strong>for</strong> the desired analysis. In the case if two or more points<br />
fall within the same cell, the value <strong>of</strong> one <strong>of</strong> these points will be randomly selected when assigning a<br />
value to the cell.<br />
35
Lines<br />
Figure 4.15: <strong>Raster</strong> point representation [34].<br />
In vector <strong>for</strong>mat, a line is an ordered list <strong>of</strong> x,y coordinates whereas in raster <strong>for</strong>mat it is represented<br />
as a chain <strong>of</strong> connected cells with the same value. When there is a break between the chain <strong>of</strong> same<br />
valued cells, it corresponds a break in the line. A break can also be used to define two roads or two<br />
rivers that do not intersect.<br />
Figure 4.16: <strong>Raster</strong> line representation [34].<br />
Converting a vector line to raster data is similar to converting a vector point to raster data. For<br />
any line that passes over a cell, this cell will receive the attribute value <strong>of</strong> this line. If multiple lines<br />
pass through a single cell, one <strong>of</strong> the lines will be randomly selected to represent that cell.<br />
<strong>The</strong> same as vector point, the width <strong>of</strong> vector line will become the width <strong>of</strong> the cell. For example,<br />
if the line that is being converted represents a road and the cell size is one meter, then the road will<br />
be one meter wide in the output raster data.<br />
Polygons<br />
A vector polygon is an enclosed area defined by an ordered list <strong>of</strong> x,y coordinates in which the first<br />
and last coordinates are the same. In contrast, a raster polygon is a group <strong>of</strong> contiguous cells with<br />
the same value that most accurately describe the shape <strong>of</strong> the area. Examples <strong>of</strong> polygonal features<br />
include buildings, ponds, soils, <strong>for</strong>ests, swamps and fields.<br />
<strong>The</strong> accuracy <strong>of</strong> the raster representation depends on the scale <strong>of</strong> the data and the size <strong>of</strong> the cell.<br />
<strong>The</strong> finer the cell resolution and the greater the number <strong>of</strong> cells, the more accurate the representation.<br />
Continuous Data<br />
Continuous data is used to describe continuous surfaces. A continuous surface represents phenomena<br />
in which each location on the surface has a measure <strong>of</strong> the concentration level or a value describing its<br />
relationship with a fixed point in space or with an emitting source. Continuous data is also referred<br />
to as field, nondiscrete or surface data.<br />
One type <strong>of</strong> continuous surface, that is derived from those characteristics that define a surface, is<br />
a surface where each point in the surface is its measured from a fixed reference point. <strong>The</strong>se include<br />
elevation (the fixed reference point is a sea level and the measure at each point is its height above the<br />
36
Figure 4.17: <strong>Raster</strong> polygon representation [34].<br />
sea level). Another example is temperature where the measure at each point is temperature at a place<br />
on the Earth.<br />
Figure 4.18: <strong>Raster</strong> elevation data <strong>for</strong> a part <strong>of</strong> the province <strong>of</strong> Quebec [8].<br />
4.5 Spatial Resolution<br />
<strong>The</strong> detail level <strong>of</strong> phenomena represented by a raster is <strong>of</strong>ten dependent on the spatial resolution<br />
or cell size <strong>of</strong> the raster. <strong>The</strong> cell must be small enough to capture the required detaild but it has to<br />
be also large enough so that computer storage and analysis can be per<strong>for</strong>med efficiently. Smaller cell<br />
sizes result in larger raster data set and greater storage space to represent an entire surface, which<br />
<strong>of</strong>ten require longer processing time.<br />
Figure 4.19: Spatial resolution.<br />
37
Choosing an appropriate cell size is not always simple. For example, the spatial resolution needed<br />
<strong>for</strong> applications againsts with the requirements <strong>for</strong> quick displaying, processing time and storages. In<br />
GIS, the choice is made <strong>for</strong> the least accurate raster data. For example, <strong>for</strong> a raster data derived from<br />
30-meter resolution Landsat imagery, a digital elevation model (DEM) at a higher resolution, such as<br />
10 meters, may be unnecessary.<br />
Figure 4.20: <strong>Raster</strong> in different spatial resolutions [11].<br />
However in most <strong>of</strong> applications, determining an adequate cell size is not a static process and<br />
depends on what data expected to obtain. In the other hand, a raster can always be resampled to<br />
have a larger cell size but any greater detail can not be obtained by resampling the same raster at a<br />
smaller cell size. So, it is useful to store a copy <strong>of</strong> the raster at its smallest cell size, then it will be<br />
resampled to match the use in application to increase analysis processing speed.<br />
4.6 Spatial Resolution Versus Scale<br />
Spatial resolution refers to the dimension <strong>of</strong> the cell size that represents an area on the ground. If<br />
the area covered by a cell is 5 x 5 meters, the resolution is 5 meters. <strong>The</strong> higher the resolution <strong>of</strong> a<br />
raster, the smaller the cell size and thus the greater the detail. This is opposite to scale.<br />
A scale model represents a copy <strong>of</strong> an object that is larger or smaller than its actual size. To do<br />
this, a relative proportion (a scale factor) <strong>of</strong> the physical size <strong>of</strong> the original object is maintained <strong>for</strong><br />
the restitution. <strong>The</strong> smaller the scale, the less detail shown. So, an ortho photograph displayed at a<br />
scale <strong>of</strong> 1:2,000 (that means 1 unit on model is equal to 2,000 units on real object) shows more details<br />
than one displayed at a scale <strong>of</strong> 1:24,000. However, if the same orthophoto has a cell size <strong>of</strong> 5 meters,<br />
the resolution will remain the same no matter what scale it is displayed at, as the physical cell size<br />
does not change.<br />
Image shown in Figure 4.21 illustrates well these effect. On the left, the scale <strong>of</strong> the image (1:50,000)<br />
is smaller than the scale <strong>of</strong> the one on the right (1:2,500) but their spatial resolutions (cell size) are<br />
the same. Another way to display images is to change the spatial resolution and maintain the scale<br />
like the ones in Figure 4.22.<br />
4.7 Bands<br />
<strong>PostGIS</strong> <strong>Raster</strong> supports multiple bands. So besides the ordinates row and column, each raster can<br />
have the third ordinate band and is identified as a cell in the space <strong>of</strong> three dimensions (see Figure<br />
4.23). Band is numbered from 1 to n, where n is the highest band number. Each band has in<strong>for</strong>mation<br />
about itself such as band data, a pixel type and a nodata value (as described in Figure ??). <strong>The</strong> pixel<br />
type indicates the number <strong>of</strong> bits used to express the color <strong>of</strong> a single pixel as well as the nodata value.<br />
Band data is a two-dimensional matrix <strong>of</strong> cells. <strong>The</strong> storage used <strong>for</strong> band data is band sequential<br />
(BSQ).<br />
38
Figure 4.21: <strong>Raster</strong>s at different scales [11].<br />
Figure 4.22: Same scaled rasters at different spatial resolution [11].<br />
Figure 4.23: <strong>Raster</strong> bands.<br />
39
<strong>The</strong> multi-band conception is resulted from the fact that, in practice, a raster image can contain<br />
multiple bands. For example, electromagnetic wave data from remote sensing devices is grouped into<br />
a certain number <strong>of</strong> channels, where the number <strong>of</strong> possible channels depends on the capacities <strong>of</strong> the<br />
sensing device. Or, multispectral images contain multiple channels and hyperspectral images contain<br />
environ 50 or more channels. <strong>The</strong>n by using raster type to model such data in a geographic in<strong>for</strong>mation<br />
system, each channel is expressed by a band.<br />
Some rasters have a single band <strong>of</strong> data, while others have multiple bands. Basically, a band<br />
is represented by a single matrix <strong>of</strong> cell values and a raster with multiple bands contains multiple<br />
coincident matrices <strong>of</strong> cell values representing the same spatial area. An example <strong>of</strong> a single-band raster<br />
dataset is a digital elevation model (DEM). Each cell in a DEM contains only one value representing<br />
surface elevation. Most satellite imagery has multiple bands, typically containing values within a range<br />
or band <strong>of</strong> the electromagnetic spectrum.<br />
<strong>The</strong>re are three main ways to display single-band raster data:<br />
• Using two colors: In a binary image, each cell has a value <strong>of</strong> 0 or 1 and is <strong>of</strong>ten displayed using<br />
black and white. This type <strong>of</strong> display is <strong>of</strong>ten used <strong>for</strong> displaying scanned maps with simple line<br />
work such as parcel maps.<br />
• Grayscale: In a grayscale image, each cell has a value from 0 to 255 or 65535. <strong>The</strong>se are <strong>of</strong>ten<br />
used <strong>for</strong> black and white aerial photographs.<br />
• Color map: One way to represent colors on an image is using a color map. A set <strong>of</strong> values is<br />
coded to match a defined set <strong>of</strong> red, green and blue (RGB) values.<br />
Figure 4.24: Three main ways to display single-band raster [35].<br />
With multiple bands raster, every cell location has more than one value associated with it. Each<br />
band usually represents a segment <strong>of</strong> the electromagnetic spectrum collected by a sensor. Bands can<br />
represent any portion <strong>of</strong> the electromagnetic spectrum including ranges not visible to the eye such as<br />
the infrared or ultraviolet sections. <strong>The</strong> term band originated from the reference to the color band on<br />
the electromagnetic spectrum.<br />
Figure 4.25: Multi-band raster [35].<br />
When a map layer is created from a multi-band raster image, user can choose to display the image<br />
from a single band <strong>of</strong> data or from multiple bands. A combination <strong>of</strong> any three available bands<br />
40
in a multiband raster can be used to create RGB composites. When displaying image using RGB<br />
composites, obviously more in<strong>for</strong>mation is conveyed from the dataset than in the case <strong>of</strong> one band.<br />
Figure 4.26: RGB composite from a three-band raster [35].<br />
A satellite image, <strong>for</strong> example, commonly has multiple bands representing different wavelengths<br />
from the ultraviolet through the visible and infrared portions <strong>of</strong> the electromagnetic spectrum. Landsat<br />
imagery, <strong>for</strong> example, is data collected from seven different bands <strong>of</strong> the electromagnetic spectrum.<br />
Bands 1 to 7, including 6, represent data from the visible, near infrared and mid infrared regions.<br />
Band 6 collects data from the thermal infrared 4 region.<br />
4.8 Pixel Types<br />
Figure 4.27: Multi-band raster image [35].<br />
Besides band data, each band contains also in<strong>for</strong>mation about nodata value and pixel type, which<br />
is a string value. Below are different pixel types supported in <strong>PostGIS</strong> <strong>Raster</strong> [6]:<br />
"1BB" = 1-bit boolean<br />
"2BUI" = 2-bit unsigned integer<br />
"4BUI" = 4-bit unsigned integer<br />
"8BSI" = 8-bit signed integer<br />
"8BUI" = 8-bit unsigned integer<br />
"16BSI" = 16-bit signed integer<br />
"16BUI" = 16-bit unsigned integer<br />
"32BSI" = 32-bit signed integer<br />
4 http://en.wikipedia.org/wiki/Infrared.<br />
41
"32BUI" = 32-bit unsigned integer<br />
"32BF" = 32-bit float<br />
"64BF" = 64-bit float<br />
4.9 Nodata Values<br />
Cell values can be either positive or negative, integer or floating point. A noData value is used<br />
to represent cell values that are either unknown or meaningless. In the other words, a noData value<br />
represents the absence <strong>of</strong> data. Sometimes there are areas in a raster that user does not want to<br />
display. <strong>The</strong>se can include borders, backgrounds or other data considered to not have valid values. In<br />
some cases, these areas are expressed as noData values, although in the other cases, they may have<br />
real values.<br />
When per<strong>for</strong>ming operations on raster data, there are typically two ways that noData are treated<br />
<strong>for</strong> each cell: noData value is returned <strong>for</strong> the position <strong>of</strong> corresponding cell, noData is ignored and<br />
can not be computed. So when calculating the statistics <strong>for</strong> a raster, user can decide to ignore or not<br />
any cells with noData value.<br />
Any analysis functions in <strong>PostGIS</strong> <strong>Raster</strong> always takes the nodata value into account. This means<br />
that the areas with nodata value will be omitted from the operation. For example in intersection<br />
operation, if a vector completely overlaps a nodata value area <strong>of</strong> one tile, the operation will set false<br />
<strong>for</strong> this tile and vector intersection and returns an EMPTY GEOMETRY result [8]. If the vector partially<br />
overlaps a nodata value area and intersect other parts <strong>of</strong> the tile, the operation will set true <strong>for</strong> this<br />
intersection and returns only parts <strong>of</strong> the tile with significant values, omitting parts with nodata<br />
values.<br />
Each raster band has its own noData value whose range depends on the associated band pixel<br />
type. <strong>The</strong> noData value is specified in the band in<strong>for</strong>mation (see Figure ??).<br />
4.10 Blocks or Tiles<br />
When importing a raster image into <strong>PostGIS</strong> database, users can choose to split the raster into<br />
small regular blocks by adding the -k option to the raster2pgsql.py Python loader, otherwise the<br />
entire raster is loaded into a single block. <strong>The</strong> block size is a parameter that follows just after the<br />
option -k (such as 128x128). All blocks are registered in a regular blocked table.<br />
Each block is stored in a row <strong>of</strong> the table and contains all data about itself (such as attribute<br />
in<strong>for</strong>mation, georeference in<strong>for</strong>mation, band in<strong>for</strong>mation and band data) as the mother raster, except<br />
its size is equal the size <strong>of</strong> mother raster divided by block size. So each block by definition can be<br />
identified as a tile. This also means that in <strong>PostGIS</strong> <strong>Raster</strong>, there are no difference between rasters,<br />
tiles and blocks.<br />
Sometimes, the dimension size (row and column) <strong>of</strong> the mother raster may not be evenly divided<br />
by the block size. <strong>PostGIS</strong>T <strong>Raster</strong> adds padding to the boundary blocks that do not have enough<br />
original cells to be completely filled. <strong>The</strong> padding cells have the same cell type as other cells and have<br />
values equal to zero. Padding makes each block have the same block size.<br />
Figure 4.28: <strong>Raster</strong> tiles [23].<br />
42
<strong>The</strong>re<strong>for</strong>e, when the -k option is applied <strong>for</strong> a raster image, it implies that:<br />
• <strong>The</strong> multidimensional matrix <strong>of</strong> cells representing raster image is partitioned into small blocks<br />
(or tiles) <strong>for</strong> large-scale storage and optimal retrieval and processing.<br />
• All imported blocks have the same width and height.<br />
• All blocks do not overlap and their upper left corners follow a regular block grid.<br />
• <strong>The</strong> global extent <strong>of</strong> the raster layer is rectangular and not rotated.<br />
<strong>The</strong>re is, however, no mechanism to en<strong>for</strong>ce these criteria and adding, modifying or deleting a row<br />
from the table might break this regular blocking. So some blocks can be missing in a regular blocked<br />
table. Missing blocks are assumed to be filled with the proper nodata value <strong>of</strong> each band when they<br />
are displayed in a map.<br />
4.11 Pyramids or Overviews<br />
4.11.1 Concept<br />
<strong>The</strong> Pyramids concept is used to reduce resolution representations <strong>of</strong> a raster image to improve<br />
per<strong>for</strong>mance in a way that Pyramids can speed up the display <strong>of</strong> raster data by retrieving only the<br />
data at a specified resolution that is required <strong>for</strong> the display. For instance, the level resolution <strong>of</strong> image<br />
is related to the amount <strong>of</strong> time that an application needs to retrieve and display it, particularly over<br />
the Web. <strong>The</strong> lower the image resolution, the faster it can be displayed. For example, in the case<br />
where the image details are not important as user has "zoomed out" considerably, loading a lower<br />
resolution image is more adequate than loading entire image with a very high resolution.<br />
Figure 4.29: Pyramids (or Overviews) in <strong>PostGIS</strong> <strong>Raster</strong> [24].<br />
When users zoom in, levels with lower resolutions are required to draw successively smaller areas.<br />
However, by using pyramids, per<strong>for</strong>mance is maintained because the database server can choose the<br />
most appropriate pyramid level (or the most appropriate resolution) <strong>of</strong> the raster data to quickly<br />
display it on the screen. In <strong>PostGIS</strong> <strong>Raster</strong>, at each level resolution, a copy <strong>of</strong> image is created and<br />
maintained as a separate raster. So without pyramids, the entire raster must be read from disk and<br />
resampled to a smaller size each time. This is called display resampling process.<br />
Pyramid levels represent reduced resolution images that require less memory space. A pyramid<br />
level <strong>of</strong> 1 indicates the original raster data, there is no reduction in the image resolution and no<br />
change in the storage space required. Values greater than 1 indicates increasingly reduced levels <strong>of</strong><br />
image resolution and reduced storage space requirements. Each successive level <strong>of</strong> the pyramid is<br />
downsampled at a scale <strong>of</strong> 4:1 as in Figure 4.30. Pyramids only need to be built once per raster. After<br />
that, they are accessed each time the raster data is viewed. <strong>The</strong> larger the raster data, the longer it<br />
takes to create the set <strong>of</strong> pyramids. This also means that more time is saved in the long run.<br />
4.11.2 Creating Pyramids<br />
In <strong>PostGIS</strong> <strong>Raster</strong>, a pyramid can be created at the same time as loading a raster image:<br />
python raster2pgsql.py -r *.jpg -t raster_table -s 26986 -l 4 -k 100x100 -I<br />
-o raster_overview_4.sql<br />
43
Figure 4.30: Pyramids at different levels and scales [36].<br />
<strong>The</strong> above command generates an sql file that will load all jpegs in current folder into a new<br />
table called raster_table, where each raster record is a 100x100 pixels width/height. <strong>The</strong> -l will<br />
create an overview table <strong>for</strong> raster_table with pyramid level 4. <strong>The</strong> overview table will be called<br />
o_4_raster_table and contains less raster records than the table raster_table has. Each raster<br />
record in o_4_raster_table is a 100x100 pixels width/height but at a lower resolution.<br />
<strong>The</strong> following script will execute the sql file to load the data into postgisdb:<br />
psql -d postgisdb -f aerials_overview4.sql<br />
4.12 Masks<br />
A mask is a special single band raster where each pixel having either the value <strong>of</strong> 0 or 1. It is<br />
used to define an irregularly shaped region inside another image. <strong>The</strong> 1-bits define the interior <strong>of</strong> the<br />
region and the 0-bits define the exterior <strong>of</strong> the region.<br />
A mask can be <strong>for</strong>med from a non blank raster. Each band <strong>of</strong> a non blank raster can also have a<br />
separate bitmap mask associated with it. Thus, there can be at most n+1 bitmap masks associated<br />
with a non blank raster, where n is the total number <strong>of</strong> bands <strong>of</strong> the raster. A bitmap mask can also<br />
be edited or updated independently.<br />
A mask attached to a raster must have the same number <strong>of</strong> rows and columns as any raster bands<br />
and must precisely cover the same area. It uses the same SRS (the spatial reference system) as that<br />
<strong>of</strong> the raster itself. Logically, a bitmap mask is not an integral part <strong>of</strong> the raster image but rather an<br />
additional piece <strong>of</strong> in<strong>for</strong>mation. Like pyramid, It is stored as a separate raster and independent the<br />
original raster.<br />
Masks are generally used by applications in the following ways [4]:<br />
• A mask can be used to determine which part <strong>of</strong> the image is displayed because sometimes users<br />
might want to mask out a part <strong>of</strong> a raster. An example might be one where a raster layer<br />
describes elevations ranging from below sea level to mountain top. If only certain elevations<br />
above sea level are interested, a mask can be applied to the raster layer to visually simulate<br />
a rise in sea level. A such mask will be computed from the source raster. For example, <strong>for</strong><br />
every cell greater than or equal to 100, its value is set to 1, otherwise its value is set to 0. <strong>The</strong><br />
output is a new raster containing cells with either a 0 (black) or 1 (while) value. <strong>The</strong> black areas<br />
(respectively the white areas) represent everything below (above) the elevation <strong>of</strong> 100 meters.<br />
Combining this mask with a suitable background, the effect <strong>of</strong> raising sea level is effectively<br />
illustrated as show in Figure 4.31.<br />
• When a mask is used as a noData mask in GIS application, the pixel value corresponding to the<br />
exterior (0-bits) <strong>of</strong> the mask will be treated as noData value. For this purpose, this value can<br />
be registered as a noData value in the raster band in<strong>for</strong>mation.<br />
44
Figure 4.31: In the right side: <strong>The</strong> mask. In the left side: the mask with the transparency set to 70%<br />
overlays the digital elevation model raster [10].<br />
4.13 Arrangements <strong>of</strong> <strong>Raster</strong> Layers<br />
<strong>PostGIS</strong> <strong>Raster</strong> uses only one table <strong>for</strong> the raster data, the georeference and the metadata as<br />
everything is stored in a single raster attribute. Thus raster attributes composing a raster table<br />
are not related to each other to <strong>for</strong>m a significant coverage. This choice makes the <strong>PostGIS</strong> <strong>Raster</strong><br />
structure very similar to the existing <strong>PostGIS</strong> vector structure. This also means that raster attributes<br />
from the same table can be <strong>of</strong> different sizes, can snap to different grids and can overlap like polygons<br />
in a vector layer can overlap.<br />
Hence, how does a raster coverage (or a raster table) look like depends on the structure and the<br />
relationships between the rasters that it contains. <strong>The</strong> following list represents different possible raster<br />
table arrangements supported in <strong>PostGIS</strong> <strong>Raster</strong>:<br />
1. A raster table may be referred to as an image warehouse <strong>of</strong> untiled and eventually unrelated<br />
images. In this case, these images may or may not overlap since every image has its own<br />
georeference. <strong>The</strong>y may also have no georeference at all.<br />
Figure 4.32: Image warehouse <strong>of</strong> untiled and unrelated images (4 images) [6].<br />
This type <strong>of</strong> arrangement is intended <strong>for</strong> non-geographical users that employ raster data <strong>for</strong> web<br />
sites or any other usage. That is because in this case, georeference in<strong>for</strong>mation is not necessary<br />
to be used. Furthermore, this soupless opens the door to other raster processing functions that<br />
could be build from non-geographical users.<br />
Figure 4.33: Image warehouse <strong>of</strong> cars [22].<br />
2. A raster table may be an irregular tiled raster coverage. Its extent might not necessarily be<br />
45
ectangular because there might be some missing tiles and they might be different sizes. Tiles<br />
<strong>of</strong> the table are not the same size and do not overlap.<br />
Figure 4.34: Irregular tiled raster coverage (36 tiles))[6].<br />
3. A raster table may be a regular tiled raster coverage. However, its extent might not necessarily<br />
be rectangular when there are some missing tiles. Tiles should be the same size and do not<br />
overlap.<br />
Figure 4.35: Regular tiled raster coverage (36 tiles) [6].<br />
4. A raster table may be a rectangular regular tiled raster coverage. Its extent is necessarily<br />
rectangular and there are no missing tiles. <strong>The</strong>se tiles are all the same size and do not overlap.<br />
This is the traditional way <strong>of</strong> displaying a coverage.<br />
Figure 4.36: Rectangular regular tiled raster coverage (54 tiles) [6].<br />
5. A raster table is a tiled image (using the option -k when loading the image). Its extent is<br />
necessarily rectangular and there are no missing tiles. <strong>The</strong>se tiles are all the same size and do<br />
not overlap. This type is different from type 4. in that it does not represent a complete coverage.<br />
Other images <strong>for</strong>ming the rest <strong>of</strong> the coverage are stored as tiled images in other tables.<br />
<strong>PostGIS</strong> <strong>Raster</strong> provides the padding mechanism to support regular tiled raster images (or<br />
regular blocking raster images) because raster applications are <strong>of</strong>ten optimized to deal with<br />
arrangements 3., 4. and 5..<br />
46
Figure 4.37: Tiled images (2 tables <strong>of</strong> 54 tiles) [6].<br />
6. A raster table may be a raster coverage resulting from any analysis operations (such as ST_AsPolygon(),<br />
ST_Intersection()) that imply rasterization <strong>of</strong> a vector coverage. From the rasterization, each<br />
vector feature becomes a small raster with the same extent as the original vector feature. This<br />
type <strong>of</strong> coverage is not necessarily complete nor rectangular. Tiles should be <strong>of</strong> different sizes<br />
and might overlap. It all depends on the characteristics <strong>of</strong> the vector layer being rasterized. For<br />
example, a continuous layer <strong>of</strong> mutual exclusive geometries (without gaps or holes like a <strong>for</strong>est<br />
cover) would result in a raster coverage in which significant pixels (with data values) would not<br />
overlap, but non-significant pixels (nodata values) would. On the other end, a discontinuous<br />
layer <strong>of</strong> mutual exclusive geometries (like a lake or building layer) would result in a coverage <strong>of</strong><br />
mostly disjoint raster objects. In practice, this arrangement is identical to a vector layer in the<br />
sense that all pixels <strong>of</strong> each raster have the same value.<br />
Figure 4.38: <strong>Raster</strong> object coverage (9 raster objects corresponding 9 rows in a raster table) [6].<br />
All these arrangements are possible and <strong>PostGIS</strong> <strong>Raster</strong> does not impose one over the other even<br />
though types 3. and 4. and 6. are the most practical <strong>for</strong> a GIS analyst. This is due to the fact<br />
that users might add or delete rows (or tiles) <strong>of</strong> a raster table and <strong>PostGIS</strong> <strong>Raster</strong> must support<br />
variable-sized tiles <strong>for</strong> vector to raster conversion. So it is very difficult to en<strong>for</strong>ce a certain type<br />
<strong>of</strong> configuration.<br />
<strong>The</strong> raster arrangements play a fundamental role in implement meaningful vector to raster<br />
conversion (see Section 4.18), where all attributes <strong>of</strong> a vector are conserved in the resulting<br />
raster table. Example, 10 lake vector features with attributes like name, type, area and etc. are<br />
converted to 10 lake raster features with the same attributes. In this case, if the vector features<br />
and the data values, part <strong>of</strong> the resulting raster features do not necessarily overlap, the nodata<br />
values <strong>of</strong> the raster features will overlap (see Figure 4.39). <strong>The</strong>se characteristics enable an easy<br />
integration <strong>of</strong> raster with vector.<br />
In <strong>PostGIS</strong>, the conversion from raster to vector can be done using ST_DumpAsPolygons() function<br />
as shown in Figure 4.40. So it is not matter whether the layers are in raster or vector <strong>for</strong>mat<br />
47
Figure 4.39: Vector to raster conversion.<br />
when working with analysis functions like ST_Intersection(). For instance, the intersection<br />
operation can per<strong>for</strong>m on vector and vector and results in a vector layer, or on vector and raster<br />
with result as a vector/raster layer or on raster and raster with result as a raster layer.<br />
Figure 4.40: <strong>Raster</strong> to vector conversion.<br />
However, as each spatial object has a spatial reference identifier (SRID) and only spatial objects<br />
with the same SRID can be used when per<strong>for</strong>ming spatial operations. So users have to ensure<br />
that vectors or rasters should have the same SRID be<strong>for</strong>e executing some spatial operations on<br />
them.<br />
4.14 Data Formats<br />
<strong>PostGIS</strong> <strong>Raster</strong> allows different <strong>for</strong>ms to express raster data:<br />
• Well Known TexT Well Known TexT (WKT) refers to the human readable text <strong>for</strong>mat. In the<br />
context <strong>of</strong> <strong>PostGIS</strong> <strong>Raster</strong>, it is used when inserting and retrieving a raster from text <strong>for</strong>mat.<br />
Example, the following request creates a raster from a line string with three bands (see Figure<br />
4.41):<br />
SELECT ST_As<strong>Raster</strong>( ST_Buffer( ST_GeomFromText(’LINESTRING(50 50,150 150,150 50)’),<br />
10), 200,200,ARRAY[’8BUI’, ’8BUI’, ’8BUI’], ARRAY[118,154,118], ARRAY[0,0,0])<br />
Where ST_Buffer(geometry, radius) returns a new geometry that represents all points whose<br />
distance from the geometry is less than or equal to radius.<br />
Figure 4.41: Image <strong>for</strong>med by the raster [17].<br />
48
• Well Known Binary Well Known Binary (WKB) refers to the binary <strong>for</strong>m <strong>of</strong> the Well Known<br />
Text described above. It is used when inserting a raster using ST_<strong>Raster</strong>FromWKB() (not yet<br />
implemented) and retrieving a raster using ST_AsBinary().<br />
Example:<br />
SELECT ST_AsBinary(rast) As rastbin<br />
FROM dummy_rast WHERE rid=1;<br />
rastbin<br />
-------------------------------------------------------------------------------<br />
0010000000000000000000000000000000000000000000000000000100000000000000000003400<br />
0000000000000000034000000000000000000000000000000000000000000000000001200000000<br />
0012000024000<br />
• Hexadecimal WKB Hexadecimal WKB (HEXWKB) is a hexadecimal representation <strong>of</strong> the WKB<br />
<strong>for</strong>m. This <strong>for</strong>m is used by the Python loader raster2pgsql.py and when outputting the value<br />
<strong>of</strong> a raster field like SELECT rast FROM raster_table.<br />
Example:<br />
SELECT rast from dummy_rast WHERE rid = 2;<br />
---------------------------------------------------------------------------------<br />
01000003009A9999999999A93F9A9999999999A9BF000000E02B274A4100000000771956410000000<br />
0000000000000000000000000FFFFFFFF050005000400FDFEFDFEFEFDFEFEFDF9FAFEFEFCF9FBFDFE<br />
FEFDFCFAFEFEFE04004E627AADD16076B4F9FE6370A9F5FE59637AB0E54F58617087040046566487A<br />
1506CA2E3FA5A6CAFFBFE4D566DA4CB3E454C5665<br />
4.15 Physical Storage<br />
<strong>PostGIS</strong> <strong>Raster</strong> enables user to store raster images in the database (storing in-database raster)<br />
or merely register them as external files (registering out-database raster). When registering a raster,<br />
only the raster metadata (width, height, number <strong>of</strong> band, georeference and path to the actual raster<br />
file) are stored in the database and not the pixel values.<br />
4.15.1 Storing In-database <strong>Raster</strong> Versus Storing Out-database <strong>Raster</strong><br />
<strong>The</strong> choice made between out-database raster and in-database raster depends on user applications.<br />
When user applications are read-only applications, that means that they only retrieve data and do<br />
not prefer to modify data. Out-database raster storage facilitates these processes by providing:<br />
• Fast application access: storing out-database raster stores the path <strong>of</strong> the raster image file<br />
conserved in the filesystem. It can speed up the reading <strong>of</strong> rasters files (JPEG, GIF, PNG) <strong>for</strong><br />
web applications in the way that only the path is needed to read when retrieving raster data<br />
and there is no need to convert it from the <strong>PostGIS</strong> <strong>Raster</strong> type to an image file.<br />
• Fast loading database: in the first time <strong>of</strong> loading a raster coverage (a table that contains<br />
a colon <strong>of</strong> type out-database raster or in-database raster), it is executed faster than normally<br />
since only the raster metadata has to be loaded or copied from the database.<br />
• Applicable SQL operators and functions: all operators and functions, that are available <strong>for</strong><br />
in-database raster data (except those involving write operations to the raster data like setting<br />
pixel value), work also with out-database rasters.<br />
49
Figure 4.42: Web application with out-database raster [23].<br />
• Simplified backup: since raster images in the filesystem that is not expected to be edited<br />
and only its metadata is registered in the database, in this way, out-database storage can avoid<br />
useless database backup <strong>of</strong> large data.<br />
In contrast, the traditional in-database raster is related to editing and analysis applications because<br />
<strong>of</strong> the following advantages:<br />
• Fast analysis: analysis operations per<strong>for</strong>med on raster data (such as dum a raster as polygons<br />
using ST_AsPolygon(), find intersection between raster and vector/raster with ST_Intersections()<br />
and etc.) require working on pixel values. <strong>The</strong> structure <strong>of</strong> raster data is nothing else a grid<br />
<strong>of</strong> two dimensions <strong>of</strong> cells, where value <strong>of</strong> each cell represents value <strong>of</strong> the corresponding pixel.<br />
Obviously, execution time <strong>of</strong> these operations is faster on in-database rasters since there is no<br />
need to extract the pixel values from an image file <strong>of</strong> JPEG or TIFF <strong>for</strong>mat.<br />
• Single storage: no matter what if data belongs to raster or vector type, <strong>PostGIS</strong> <strong>Raster</strong> allows<br />
a single dataset storage. <strong>The</strong>re is no need to store the raster data separately from the vector<br />
data, they can be placed alternatively in the same dataset.<br />
• Multi-Users edition: multiple users can modify raster data at the same time as <strong>PostGIS</strong><br />
database handles concurrent editing on in-database rasters.<br />
4.15.2 Registering Out-database <strong>Raster</strong><br />
Registering out-database raster is done via the -R option when loading raster image file into<br />
database.<br />
Example:<br />
python raster2pgsql.py -r c:/imagesets/landsat/image.tif -t landsat -R<br />
Where the key option -r specifies the input raster image, the -t option specifies the name <strong>of</strong><br />
rater table that contains the corresponding raster and the -R option indicates that the raster image<br />
is registered as a filesystem.<br />
4.15.3 Storing In-database <strong>Raster</strong><br />
Like geometry type, raster type is a complex <strong>PostgreSQL</strong> type composed <strong>of</strong> many attributes. A<br />
raster attribute may be composed <strong>of</strong> many bands having a common size, pixel size and georeference.<br />
Besides this, additional in<strong>for</strong>mation is needed to interpret the image data, such as a pixel type and<br />
a nodata value. <strong>The</strong> storage used <strong>for</strong> raster bands is band sequential (BSQ), which is one <strong>of</strong> three<br />
primary methods <strong>for</strong> encoding image data <strong>for</strong> multiband raster images. BSQ is not itself an image<br />
<strong>for</strong>mat but is a method <strong>for</strong> encoding pixel values <strong>of</strong> an image, where each line <strong>of</strong> the data is followed<br />
immediately by the next line in the same band. <strong>The</strong> BSQ data organization is optimal <strong>for</strong> spatial<br />
50
access <strong>of</strong> any part <strong>of</strong> a single band. It can also handle any number <strong>of</strong> bands and accommodates black<br />
and white, grayscale, pseudocolor, true color and multi-spectral image data.<br />
Figure 4.43: Storing in-database raster.<br />
For example, the following SQL command will create a raster table containing two dummy rasters,<br />
each one is stored in a single row using BSQ:<br />
Create table dummy_rast(rid integer, rast raster);<br />
Insert into dummy_rast(rid, rast)<br />
Values (1,<br />
-- <strong>Raster</strong>: 0 band, Nodata = 0<br />
(’01’ -- little endian (uint8 ndr)<br />
||<br />
’0000’ -- version (uint16 0)<br />
||<br />
’0000’ -- nBands (uint16 0)<br />
||<br />
’0000000000000040’ -- scaleX (float64 2)<br />
||<br />
’0000000000000840’ -- scaleY (float64 3)<br />
||<br />
’000000000000E03F’ -- ipX (float64 0.5)<br />
||<br />
’000000000000E03F’ -- ipY (float64 0.5)<br />
||<br />
’0000000000000000’ -- skewX (float64 0)<br />
||<br />
’0000000000000000’ -- skewY (float64 0)<br />
||<br />
’00000000’ -- SRID (int32 0)<br />
||<br />
’0A00’ -- width (uint16 10)<br />
||<br />
’1400’ -- height (uint16 20)<br />
)::raster),<br />
-- <strong>Raster</strong>: 5 x 5 pixels, 3 bands, 8BUI pixel type, NoData = 0<br />
(2, (’01000003009A9999999999A93F9A9999999999A9BF000000E02B274A’ || ’410000000077195<br />
64100000000000000000000000000000000FFFFFFFF050005000400FDFEFDFEFEFDFEFEFDF9FAFEFEFC<br />
F9FBFDFEFEFDFCFAFEF’ || ’EFE04004E627AADD16076B4F9FE6370A9F5FE59637AB0E54F586170870<br />
40046566487A1506CA2E3FA5A6CAFFBFE4D566DA4CB3E454C5665’)::raster);<br />
51
In this example, the dummy_rast table has two rows. Each <strong>of</strong> them corresponds to a raster tile.<br />
When inserting raster data <strong>for</strong> the first row, the first byte 01 is used to define the order <strong>of</strong> bytes<br />
organized in memory, called endianness. If it is a little endian, a computer records 0xA0B70708<br />
in the order 08 07 B7 A0 with the byte lowest first. <strong>The</strong> rest specifies different components <strong>of</strong> raster<br />
attribute like version, number band, scale, pixel size, skew, SRID, with and height. Each <strong>of</strong> them is<br />
separated from each other by a double vertical bar ’||’. However, it is not always in this way, like the<br />
one in the second row. <strong>The</strong> ’||’ can be placed anywhere in the whole hexadecimal string. As the first<br />
raster tile has no band, there is no string <strong>for</strong> band data values.<br />
In contrast, more invisibly, raster data in the second row is composed <strong>of</strong> three long strings but they<br />
can be decomposed into small strings according to structure <strong>of</strong> a raster type. Such a decomposition<br />
splits the first byte <strong>for</strong> ’endianness’, the next two bytes <strong>for</strong> ’version’ and etc. Or, data in the second<br />
raster tile can be rewritten in the following way:<br />
01 -- little endian<br />
00 00 -- version (uint16 0)<br />
03 00 -- nBands (uint16 3)<br />
--Georeference in<strong>for</strong>mation<br />
9A 99 99 99 99 99 A9 3F -- scale X (float64 0.05)<br />
9A 99 99 99 99 99 A9 BF -- scale Y (float64 -0.05)<br />
00 00 00 E0 2B 27 4A 41 -- ipX (float64 3427927.75)<br />
00 00 00 00 77 19 56 41 -- ipY (float64 5793244)<br />
00 00 00 00 00 00 00 00 -- skewX (float64 0)<br />
00 00 00 00 00 00 00 00 -- skew Y (float64 0)<br />
FF FF FF FF -- SRID (int32 -1)<br />
05 00 -- width (uint16 5)<br />
05 00 -- height (uint16 5)<br />
--Band in<strong>for</strong>mation<br />
--Band 1<br />
0 -- is<strong>of</strong>fline, hasnodatavalue (no is<strong>of</strong>fline, no nodatavalue )<br />
4 -- pixeltype (4 bit 8_BUI)<br />
00 -- nodata value<br />
--Band data values 5x5 pixels<br />
FD FE FD FE FE<br />
FD FE FE FD F9<br />
FA FE FE FC F9<br />
FB FD FE FE FD<br />
FC FA FE FE FE<br />
--Band 2<br />
0400 --<br />
--Band data values 5x5 pixels<br />
4E 62 7A AD D1<br />
60 76 B4 F9 FE<br />
63 70 A9 F5 FE<br />
59 63 7A B0 E5<br />
4F 58 61 70 87<br />
--Band 3<br />
04 00<br />
--Band data values 5x5 pixels<br />
46 56 64 87 A1<br />
50 6C A2 E3 FA<br />
5A 6C AF FB FE<br />
4D 56 6D A4 CB<br />
3E 45 4C 56 65<br />
As shown in Figure 4.44, the raster data stored in the second row <strong>of</strong> dummy_rast table can be<br />
52
Figure 4.44: In-database raster.<br />
directly seen from Quantum GIS (an open source desktop geographic in<strong>for</strong>mation systems). For<br />
instance, the first pixel value <strong>for</strong> the first, the second and the third band are respectively FD, 4E, 46<br />
in hexadecimal. <strong>The</strong>se values correspond to 253, 78 and 70 in decimal.<br />
4.16 Indexing<br />
<strong>PostGIS</strong> <strong>Raster</strong> creates indexes over raster data itself. In this way, user can do really complex<br />
operations on raster data, like getting a set <strong>of</strong> geometry and geometry value from a given raster<br />
band (ST_DumpAsPolygons() function). Unlike Oracle GeoRASTER that creates indexes over spatial<br />
extent, it has more sense when <strong>PostGIS</strong> <strong>Raster</strong> creates indexes over raster data.<br />
In <strong>PostGIS</strong>, loading a new raster table and creating indexes over the raster column can be done<br />
by executing these two lines:<br />
python raster2pgsql.py -r path/*.tif -t raster_table -s 4326 -k 50x50 -I<br />
-o raster_sql.sql<br />
psql -d database -f raster_sql.sql<br />
<strong>The</strong> -s option georeferences the resulting rasters using SRID 4326.<br />
<strong>The</strong> -k option splits image files into tiles <strong>of</strong> 50x50 pixels (one per row). All these tiles do not<br />
overlap and their upper left corners follow a regular block grid. <strong>The</strong> global extent <strong>of</strong> the layer is<br />
rectangular and not rotated.<br />
<strong>The</strong> -I option in<strong>for</strong>ms the loader to create the spatial index on the raster table. This index<br />
is very important as it restricts <strong>PostGIS</strong> <strong>Raster</strong>’s computing ef<strong>for</strong>ts only to the tiles involved in<br />
spatial operations. For example, when finding the intersection <strong>of</strong> the raster_table and a set <strong>of</strong><br />
geometry points, this operation will be per<strong>for</strong>med only on the tiles that actually intersect with the<br />
geometry points. So it is much faster to search <strong>for</strong> those tiles if they are spatially rather than try<br />
them one after the other sequentially from the raster table. If the -I option was not specified when<br />
using raster2pgsql.py, the index can always be created afterward by executing the following SQL<br />
command:<br />
CREATE INDEX rast_gist_idx<br />
ON raster_table<br />
USING GIST (ST_ConvexHull(rast));<br />
<strong>The</strong> ST_ConvexHull() function returns the convex hull geometry <strong>of</strong> the raster including pixel<br />
values equal to BandNoDataValue(). Further, a spatial index can also be made on the geom_points<br />
table to make sure that the intersection operation will be done as quickly as possible:<br />
CREATE INDEX point_geom_idx<br />
ON geom_points<br />
USING GIST (the_geom);<br />
53
One approach to make this intersection operation without <strong>PostGIS</strong> <strong>Raster</strong> is to convert those<br />
raster images to shapefiles (a popular geospatial vector data <strong>for</strong>mat), import them in <strong>PostGIS</strong> and do<br />
a traditional intersection query between geometries only. <strong>The</strong> problem is that converting only one <strong>of</strong><br />
those Shuttle Radar Topography Mission (SRTM) files is very difficult. <strong>The</strong> vector version <strong>of</strong> only one<br />
<strong>of</strong> those files exceeds the limit <strong>of</strong> 2 GB imposed on shapefiles. Since it is mostly impossible to convert<br />
those rasters to vectors, the <strong>PostGIS</strong> <strong>Raster</strong> approach is to load them into <strong>PostGIS</strong> and will vectorize<br />
only ones that are needed to do the requested operation. This approach benefits greatly from the<br />
indexing <strong>of</strong> raster data in the database.<br />
4.17 Retrieving<br />
As each storing type is specified <strong>for</strong> a class <strong>of</strong> application, it results in a strong difference in the way<br />
they retrieve raster data.<br />
4.17.1 In-database <strong>Raster</strong> Retrieving<br />
<strong>The</strong>re exist two modes when retrieving in-database raster data from <strong>PostGIS</strong> database:<br />
1. ONE RASTER PER ROW<br />
2. ONE RASTER PER TABLE<br />
<strong>PostGIS</strong> uses the GDAL driver <strong>for</strong> exporting rasters via a connection string. <strong>The</strong> syntax <strong>of</strong> this<br />
connection string is as follows:<br />
PG":host=’’ port:’’ dbname=’’ user=’’ password=’’<br />
[schema=’’] [table=’’] [where=’’]<br />
[mode=’’]"<br />
Certain fields can be omitted like password in some case. <strong>The</strong> table option specifies name <strong>of</strong> a<br />
raster table to connect. <strong>The</strong> where option is used to filter results from the raster table. <strong>The</strong> mode<br />
option determines which connection mode is evoked:<br />
• Mode = 1 or ONE RASTER PER ROW mode (the default mode): in this mode, a raster table is<br />
considered as a set <strong>of</strong> different raster images. <strong>The</strong>n where parameter is used to select which<br />
raster images will be exported.<br />
• Mode = 2 or ONE RASTER PER TABLE mode: in this case, a raster table is considered as a unique<br />
raster image composed by a set <strong>of</strong> raster tiles (one raster tile per row). This mode is intended<br />
<strong>for</strong> reading tiled raster.<br />
When the connection is established, the GDAL driver uses gdal_translate command to create<br />
an image file from the connected raster table:<br />
gdal_translate -outsize 50% 50% "PG:host=’localhost’ dbname=’’<br />
user=’’ password=’’ table=’table_name’ mode=’2’"<br />
table_name.tif<br />
<strong>The</strong> additional option -outsize will create an image file like the original image but at a different<br />
size (a half size in the above example).<br />
4.17.2 Out-database <strong>Raster</strong> Retrieving<br />
<strong>PostGIS</strong> <strong>Raster</strong> enables user to simply register basic metadata <strong>of</strong> images stored in the filesystem<br />
without having to actually load their data values into the database. This is out-database storage as<br />
opposed to the more natural in-database storage. In this way, web or desktop applications:<br />
• do not have to retrieve images from the database but instead can access them directly from the<br />
file system (such as JPEG files).<br />
• can use almost <strong>PostGIS</strong> <strong>Raster</strong> operators and functions on those rasters using GDAL driver<br />
(out-database raster support is under development).<br />
54
4.18 Conversion<br />
In <strong>PostGIS</strong>, when using analysis functions, it is no matter whether the layers are raster or vector<br />
type as <strong>PostGIS</strong> <strong>Raster</strong> provides a set <strong>of</strong> functions to support conversion between raster and vector<br />
data.<br />
4.18.1 <strong>Raster</strong> to vector<br />
With ST_DumpAsPolygons() function, raster data is converted to vector <strong>for</strong>m, along with a set <strong>of</strong><br />
geometric objects.<br />
Example:<br />
SELECT ST_DumpAsPolygons(rast)).geom, ST_DumpAsPolygons(rast)).val<br />
FROM raster_table ;<br />
<strong>The</strong> result <strong>of</strong> this function is a set <strong>of</strong> geomval <strong>for</strong>med by a geometry and a pixel value, where each<br />
geometric object is the union <strong>of</strong> all pixels <strong>of</strong> the same band that have the same pixel value. So the<br />
ST_DumpAsPolygons() function is useful <strong>for</strong> polygonizing rasters in which a single raster will be split<br />
and trans<strong>for</strong>med into multiple polygons. For example, as the circle in Figure 4.45 is composed by two<br />
half-circles that have different values, when applying the ST_DumpAsPolygons() function, it results in<br />
two geometric half-circles by definition.<br />
4.18.2 Vector to raster<br />
Figure 4.45: Conversion from raster to vector [22].<br />
Inversely, a raster object can be build from a geometric object using ST_As<strong>Raster</strong>() function. <strong>The</strong><br />
vector to raster conversion can be per<strong>for</strong>med without loss <strong>of</strong> in<strong>for</strong>mation as <strong>PostGIS</strong> <strong>Raster</strong> introduces<br />
the concept <strong>of</strong> raster object. This concept postulates that geographic entities can be stored as raster<br />
tiles at variable sizes instead <strong>of</strong> polygons. In the following demonstration, the request will output a<br />
raster containing image <strong>of</strong> a black geometric circle taking up 150 x 150 pixels as the one in Figure<br />
4.46.<br />
Select ST_As<strong>Raster</strong>(ST_Buffer(ST_Point(1,5),10),150, 150, ’2BUI’);<br />
Figure 4.46: Conversion from vector to raster [22].<br />
55
4.19 Intersection<br />
<strong>The</strong> fact that <strong>PostGIS</strong> <strong>Raster</strong> achieves efficient conversion between raster and vector, is the base<br />
to implement certain operations over data, whether it is in raster or vector <strong>for</strong>mat. <strong>The</strong>se operations<br />
are essential in <strong>PostGIS</strong> because they contribute to the accomplishment <strong>of</strong> its second goal described<br />
in Chapter 3. This goal includes <strong>of</strong>fering a single set <strong>of</strong> overlay SQL function operating seamlessly<br />
on vector and raster data. Furthermore, in comparison to ORACLE Geo<strong>Raster</strong> (also in Chapter 3),<br />
they play an important role that makes <strong>PostGIS</strong> <strong>Raster</strong> more per<strong>for</strong>ming than ORACLE GEO<strong>Raster</strong><br />
and more adapted to various groups <strong>of</strong> users (experienced and inexperienced ones). Such operations<br />
include ST_Intersection() that makes intersection between raster and vector data. Several possible<br />
scenarios are available <strong>for</strong> this operation:<br />
1. A vector and vector intersection with a vector layer as a result.<br />
2. A vector and raster intersection with a raster layer as a result.<br />
3. A vector and raster intersection with a vector layer as a result.<br />
4. A raster and raster intersection with a raster layer as a result.<br />
<strong>The</strong> result can be a raster or a set <strong>of</strong> geometry-pixel value pairs (as in the case <strong>of</strong> ST_DumpAsPolygons())<br />
representing the shared portion <strong>of</strong> two geometries, two rasters or between a vectorization <strong>of</strong> a raster<br />
and a geometry. <strong>The</strong>se cases will be examined one by one in the following examples.<br />
Example 1.1: A vector and vector intersection with a vector layer as a result is illustrated in Figure<br />
4.47.<br />
Figure 4.47: Vector and vector intersection with a resulting vector layer [22].<br />
This example examines the first case <strong>of</strong> intersection between a geometric circle a with a geometric<br />
vegetation cover (type 1 in blue and type 2 in green). <strong>The</strong> result is a half circle in vector <strong>for</strong>mat with<br />
two attributes: a circle name and a cover type.<br />
Example 1.2: A vector and raster intersection with a raster layer as a result.<br />
In general, the intersection begins to select which raster tiles have to be loaded in order to construct<br />
an intersected raster extent (using ST_intersects()) containing all intersected raster tiles. In the<br />
first view, this paradigm makes the operation more efficient in the sense that the number <strong>of</strong> intersected<br />
raster tiles is <strong>of</strong>ten a small number in compare to whole number <strong>of</strong> existing raster tiles (see Figure<br />
4.48). In second view, the intersection operation works only with these intersected tiles. <strong>The</strong> raster<br />
extent construction is just the first phase because true intersection will take pixel values (raster <strong>for</strong>mat)<br />
or geometries (vector <strong>for</strong>mat) into account (using ST_intersection()).<br />
If the output is a raster, then the operation will attach pixel values in the final result as one in<br />
Figure 4.49. So the vegetation cover type represented by a raster is well known. In addition, the<br />
vector attribute is also conserved and become an attribute <strong>of</strong> the resulting raster.<br />
Example 1.3: A vector and raster intersection with a vector layer as a result.<br />
If the final result is expressed in vector <strong>for</strong>m, the intersecting raster tiles are first vectorized (using<br />
ST_DumpAsPolygon()) into a set <strong>of</strong> geometry-pixel value and this set is then intersected with the<br />
geometry using the ST_Intersection(vector, vector) function. At this stage, one more time, as<br />
vectorization is a complex task (it is related to each pixel value) and time consume, the paradigm<br />
56
Figure 4.48: <strong>Raster</strong> intersection paradigm [22].<br />
Figure 4.49: Vector and raster intersection with a resulting raster layer [22].<br />
sounds very useful because it helps <strong>PostGIS</strong> to vectorize only what is needed to do the requested<br />
operation. As the intersection(vector,vector) → vector operation, the final result is a set <strong>of</strong> geometrypixel<br />
value pairs representing the shared portion <strong>of</strong> the geometric and the vectorization <strong>of</strong> the raster<br />
(see Figure 4.50).<br />
Figure 4.50: Vector and raster intersection with a resulting vector layer [22].<br />
Example 1.4: A raster and raster intersection with a raster layer as a result.<br />
In the case <strong>of</strong> raster-raster intersection, the result is stored in a multiband raster. <strong>The</strong> extent <strong>of</strong><br />
the resulting raster corresponds to the geometrical intersection <strong>of</strong> the two raster extents. Nodata area<br />
presenting in any band will result in nodata area in every band <strong>of</strong> the result. In other words, any pixel<br />
intersecting with a nodata value pixel becomes a nodata value pixel in the result.<br />
To obtain a result similar to the Intersection(vector/vector) → vector operation, the resulting<br />
raster must be vectorized and moreover, this vectorization must take into account multiband.<br />
Different possible scenarios will be one more time examined in the following part but in the case<br />
<strong>of</strong> mutual exclusive polygons.<br />
Example 2.1: A vector and vector intersection with a vector layer as a result. Here, in Figure 4.52,<br />
the result is trivial.<br />
Example 2.2: A vector and raster intersection with a raster layer as a result.<br />
As in the previous case, the intersection operation results in different disjoint rasters, along with<br />
additional attributes that come from input vectors (Figure 4.53). To obtain a result similar to the<br />
intersection(vector,vector) → vector operation, the resulting rasters must be vectorized.<br />
Example 2.3: A vector and raster intersection with a vector layer as a result.<br />
57
Figure 4.51: <strong>Raster</strong> and raster intersection with a resulting vector layer [22].<br />
Figure 4.52: Mutual exclusive polygons intersection with a resulting vector layer [22].<br />
Figure 4.53: Mutual exclusive vector-raster intersection with a resulting raster layer [22].<br />
Figure 4.54: Mutual exclusive vector-raster intersection with a resulting vector layer [22].<br />
58
<strong>The</strong> final result is a set <strong>of</strong> geometry-pixel value pairs representing the shared portion <strong>of</strong> the geometric<br />
and the vectorization <strong>of</strong> the raster (Figure 4.54). This result is the same as the one obtained<br />
from the intersection(vector,vector) → vector operation.<br />
Example 2.4: A raster and raster intersection with a raster layer as a result.<br />
Figure 4.55: Mutual exclusive raster-raster intersection with a resulting raster layer [22].<br />
<strong>The</strong> same, the results are stored in multiband rasters as different disjoint objects as shown in Figure<br />
4.55. To obtain a result similar to the intersection(vector,vector) → vector operation, the resulting<br />
rasters must be vectorized.<br />
4.20 Temporal <strong>Raster</strong><br />
By definition, continuous fields are phenomena that are perceived as having a value at each point in<br />
space and time. Temporal raster, an extension <strong>of</strong> raster, is a new type designed to take into account<br />
the temporal aspect. In addition, a set <strong>of</strong> operations allowing interactions between this new type with<br />
date and time [2] are also implemented.<br />
<strong>PostgreSQL</strong> provides different languages to support new types defined by user, such as C, PL/pgSQL.<br />
PL/pgSQL is a procedural language that allows user to create new types, complex functions and etc.<br />
It is easy to learn and can do anything that can be done in C language. <strong>The</strong> rest <strong>of</strong> this section<br />
introduces the new temporal raster type and different functions built using PL/pgSQL.<br />
4.20.1 Structure<br />
Temporal raster is defined as a new composite data type based on raster type and timestamp type:<br />
st_rastertemp( rast raster, temp timestamp)<br />
4.20.2 Operations<br />
Operation ST_InTime is a constructor <strong>of</strong> temporal raster. It yields <strong>for</strong> each input raster, a<br />
corresponding temporal raster whose value is a pair <strong>of</strong> a timestamp instant and a raster value. A<br />
simple pseudocode <strong>for</strong> ST_InTime is shown below:<br />
Example:<br />
SELECT ST_InTime(raster, ’5/12/2011’)<br />
FROM rasterTable;<br />
Inversely, ST_Instant and ST_Value operations retrieve respectively the timestamp instant and<br />
the raster value <strong>of</strong> the input temporal raster.<br />
Example :<br />
SELECT ST_Instant(tempRast), ST_Value(tempRast)<br />
FROM temp<strong>Raster</strong>Table;<br />
59
ST_Present and ST_Passes predicates check whether a temporal raster is created respectively at<br />
an instant or a period <strong>of</strong> time.<br />
Example :<br />
SELECT ST_Present(tempRast, ’13/7/2001’::date)<br />
FROM temp<strong>Raster</strong>Table;<br />
SELECT ST_Passes(tempRast, ST_Range(’1/1/2008’, ’31/12/2011’))<br />
FROM temp<strong>Raster</strong>Table;<br />
Acting in the same way as ST_Present and ST_Passes but instead <strong>of</strong> returning a boolean,<br />
ST_AtInstant and ST_AtPeriods operations return the temporal raster values.<br />
Example :<br />
SELECT ST_AtInstant(tempRast, ’13/7/2001’::date)<br />
FROM temp<strong>Raster</strong>Table;<br />
SELECT ST_AtPeriods(tempRast,ST_Range(’1/1/2008’,’31/12/2011’))<br />
FROM temp<strong>Raster</strong>Table;<br />
In addition, there are also some aggregate functions [13] that execute on multiple temporal raster<br />
values. <strong>The</strong>se values are grouped together as input. <strong>The</strong> output is a single value computed based<br />
on certain criteria. An example <strong>of</strong> a simple aggregate function is ST_Sum that calculates the sum <strong>of</strong><br />
a sequence <strong>of</strong> temporal raster values. As each temporal raster is a matrix <strong>of</strong> values <strong>of</strong> each point in<br />
space at a time instant, the computation <strong>of</strong> the sum <strong>of</strong> this sequence goes back to the computation <strong>of</strong><br />
the sum <strong>of</strong> values <strong>of</strong> each corresponding point. <strong>The</strong> output is a summing raster.<br />
Pseudo code <strong>of</strong> ST_Sum:<br />
WHILE (band
Finally, ST_Min and ST_Max, as indicate their names, return the temporal rasters that have respectively<br />
a minimum or maximum timestamp instant. To find the temporal rasters that have the<br />
minimal timestamp instant, firstly this minimum timestamp instant is found from a loop. <strong>The</strong>n a<br />
second loop choose only those that match this timestamp as output.<br />
Pseudo code <strong>of</strong> ST_Min:<br />
WHILE r timestamp <strong>of</strong> temporal raster r<br />
minTime = timestamp <strong>of</strong> temporal raster r<br />
WHILE r
Chapter 5<br />
User Guide<br />
Sometimes storing data using raster is the only choice such as imagery is only available in raster<br />
<strong>for</strong>mat. Moreover, users can get many other advantages resulting from the nature <strong>of</strong> raster data,<br />
which is a matrix <strong>of</strong> cell values. For example, this simple data structure <strong>of</strong>fers the ability to represent<br />
continuous surfaces as a grid <strong>of</strong> cell values and so enables easy spatial and statistical surface analysis.<br />
<strong>The</strong> ability to uni<strong>for</strong>m storage as points, lines and polygons, which are all vector features, could also<br />
be stored using raster data.<br />
<strong>The</strong> following section introduces instructions about how to execute some basic operations such as<br />
importing, exporting raster data, conversion and intersection between raster and vector data, along<br />
with other abilities that <strong>PostGIS</strong> <strong>Raster</strong> could <strong>of</strong>fer to users.<br />
5.1 Store and Manage <strong>Raster</strong>s<br />
5.1.1 Import <strong>Raster</strong>s<br />
User can import rasters from existing raster images stored in file system using raster2pgsql<br />
Python loader:<br />
(1) raster2pgsql.py -r "c:/temp/mytiffolder/*.tif" -t mytable -s 4326 -o table_name.sql<br />
(2) psql -d postgisdb -f table_name.sql -U -W<br />
<strong>The</strong> first command (1) generates a sql file that loads file_name.tif with SRID 4326 into a<br />
new table called mytable. <strong>The</strong> second command (2) runs the SQL script <strong>for</strong> loading the data into<br />
postgisdb.<br />
Or users can create their own rasters from SQL command:<br />
CREATE TABLE dummy_rast(rid integer, rast raster);<br />
INSERT INTO dummy_rast(rid, rast)<br />
VALUES<br />
-- <strong>Raster</strong>: 5 x 5 pixels, 3 bands, PT_8BUI pixel type, NODATA = 0<br />
(1,(’01000003009A9999999999A93F9A9999999999A9BF000000E02B274A4<br />
1000000007719564100000000000000000000000000000000FFFFF<br />
FFF050005000400FDFEFDFEFEFDFEFEFDF9FAFEFEFCF9FBFDFEFEF<br />
DFCFAFEFEFE04004E627AADD16076B4F9FE6370A9F5FE59637AB0E<br />
54F58617087040046566487A1506CA2E3FA5A6CAFFBFE4D566DA4C<br />
B3E454C5665’)::raster);<br />
5.1.2 Get and Set <strong>The</strong> <strong>Raster</strong> Properties<br />
• Upper left corner coordinates and trans<strong>for</strong>mation parameters<br />
–Get the upper left corner coordinates <strong>of</strong> all rasters in the table:<br />
62
SELECt rid, ST_UpperLeftX(rast)<br />
FROM dummy_rast;<br />
--Set the upper left corner coordinates <strong>of</strong> the raster whose rid number is 1<br />
--from the table dummy_rast:<br />
SELECT ST_SetUpperLeft(rast,-71.01,42.37)<br />
FROM dummy_rast WHERE rid = 1;<br />
• SRID and number <strong>of</strong> bands<br />
–Get SRID <strong>of</strong> the raster whose rid is 1:<br />
SELECT ST_SRID(rast) As srid<br />
FROM dummy_rast WHERE rid=1;<br />
–Set SRID <strong>of</strong> the raster whose rid is 1:<br />
SELECT ST_SETSRID(rast) As newRast<br />
FROM dummy_rast WHERE rid=1;<br />
–Get number <strong>of</strong> bands <strong>of</strong> the raster whose rid is 1:<br />
SELECT rid, ST_NumBands(rast)<br />
FROM dummy_rast Where rid = 1;<br />
• Get and set band properties –Pixel type and nodata value Get pixel type <strong>of</strong> band number 1 <strong>of</strong><br />
the raster whose rid is 1:<br />
SELECT ST_BandPixelType(rast,1)<br />
FROM dummy_rast<br />
WHERE rid = 1;<br />
Get no data value <strong>of</strong> band number 2 <strong>of</strong> the raster whose rid is 1:<br />
SELECT ST_BandNoDataValue(rast,2)<br />
FROM dummy_rast<br />
WHERE rid = 1;<br />
Set no data value <strong>of</strong> band number 2 <strong>of</strong> the raster, whose rid is 1, to 254:<br />
UPDATE dummy_rast<br />
SET rast = ST_SetBandNoDataValue(rast,2, 254)<br />
WHERE rid = 1;<br />
• Reproject rasters This operation will reproject the geographic locations <strong>of</strong> rasters into any appropriate<br />
coordinate system <strong>for</strong> execution <strong>of</strong> some spatial operations. <strong>The</strong> reprojection is executed<br />
using ST\_Trans<strong>for</strong>m(raster, srid, algorithm). This function uses specified resampling<br />
algorithm such as NearestNeighbor, Bilinear, Cubic, CubicSpline or Lanczos. Default is NearestNeighbor.<br />
<strong>The</strong> following query trans<strong>for</strong>ms all rasters <strong>of</strong> the dummy_rast table into WGS 84<br />
(having the SRID number 4326) using Bilinear algorithm:<br />
SELECT ST_Trans<strong>for</strong>m(rast,4326,’Bilinear’)<br />
FROM dummy_rast ;<br />
• Resample a raste Resample a raster with new dimensions, an arbitrary grid corner and a set <strong>of</strong><br />
raster georeferencing attributes. This operation is per<strong>for</strong>med using ST_Resample(raster, width,<br />
height, algorithm). New pixel values are computed using the NearestNeighbor, Bilinear, Cubic,<br />
CubicSpline or Lanczos resampling algorithm. Default is NearestNeighbor.<br />
63
SELECT rast As origin, ST_Resample(rast,100,100) As reduce_100<br />
FROM dummy_rast;<br />
With this query, all rasters will be resampled into new dimension 100x100 using NearestNeighbor<br />
algorith by default.<br />
• Rescale rasters Rescaling a raster corresponds to resample a raster by adjusting its scale (or pixel<br />
size). New pixel values are computed using the NearestNeighbor, Bilinear, Cubic, CubicSpline<br />
or Lanczos resampling algorithm. Default is NearestNeighbor. <strong>The</strong> following example rescales<br />
rasters to a pixel size <strong>of</strong> 0.0015 using ST_Rescale(raster, scalexy, algorithm).<br />
SELECT ST_Rescale(rast,0.0015)<br />
FROM dummy_rast;<br />
• Snap rasters to different grid This operation corresponds to resample a raster by snapping it<br />
to a grid defined by an arbitrary pixel corner and optionally a pixel size. New pixel values<br />
are computed using the NearestNeighbor, Bilinear, Cubic, CubicSpline or Lanczos resampling<br />
algorithm. Default is NearestNeighbor. <strong>The</strong> simple example below uses ST_SnapToGrid(raster,<br />
cornerx, cornery, algorithm) function to snap a raster to a slightly different grid defined by the<br />
pixel corner (0.0002, 0.0002):<br />
SELECT ST_SnapToGrid(rast,0.0002, 0.0002)<br />
FROM dummy_rast;<br />
5.1.3 Vector to <strong>Raster</strong> Conversion<br />
<strong>The</strong> example below creates a raster containing a black circle using ST_As<strong>Raster</strong>(geometry, width,<br />
height, pixeltype) function. Its dimensions are 150x150 pixels and its pixel type is 2-bit unsigned<br />
integer (2BUI):<br />
SELECT ST_As<strong>Raster</strong>(ST_Buffer(ST_Point(1,5),10),150, 150, ’2BUI’);<br />
where ST_Buffer is used to return a geometry that represents all points whose distance from the<br />
point (1,5) is less than or equal to 10 pixels.<br />
5.1.4 <strong>Raster</strong> to Vector Conversion<br />
Figure 5.1: <strong>Raster</strong> circle [17].<br />
<strong>The</strong> conversion using ST_DumpAsPolygons(raster, band) returns a set <strong>of</strong> geomval (<strong>for</strong>med by a<br />
geometry and a pixel band value) rows from a given raster band. Default band number is 1. Each<br />
geometry is the union <strong>of</strong> all pixels that have the same pixel value.<br />
SELECT (ST_DumpAsPolygons(rast)).*<br />
FROM dummy_rast<br />
WHERE rid = 1;<br />
64
5.2 Exporting <strong>Raster</strong>s<br />
User can export existing rasters from <strong>PostGIS</strong> database as many small raster files named image1.tif,<br />
image2.tif et etc. Each file corresponds to one row <strong>of</strong> a raster table.<br />
gdal_translate "PG:host=’localhost’ dbname=’’ user=’’<br />
password=’’ table=’table_name’ mode=’1’" c:/temp/image\#.tif<br />
Or user can produce only one big raster file composed by available rasters <strong>of</strong> a raster table:<br />
gdal_translate "PG:host=’localhost’ dbname=’’ user=’’<br />
password=’’ table=’table_name’ mode=’2’" c:/temp/image.tif<br />
5.3 Get <strong>Raster</strong> Statistics<br />
• Get summary statistics <strong>The</strong> ST_SummaryStats(raster, band, exclude_nodata_value) function<br />
returns summary statistics consisting <strong>of</strong> count, sum, mean, stddev (standard deviation), min<br />
and max <strong>for</strong> a given raster band <strong>of</strong> a raster. Band 1 is assumed if no band is specified. By<br />
default, exclude_nodata_value parameter is true.<br />
SELECT rid, ST_SummaryStats(rast) As stats<br />
FROM dummy_rast;<br />
• Get pixel histogram <strong>The</strong> ST_Histogram(raster, band, categories, width[ ]) function returns a<br />
set <strong>of</strong> (min, max, count, percent) records summarizing raster data distribution <strong>for</strong> a number <strong>of</strong><br />
categories(the number <strong>of</strong> resulting records) <strong>of</strong> a given band. Number <strong>of</strong> categories are autocomputed<br />
if it is not specified. Band 1 is assumed if no band is specified. <strong>The</strong> width[] parameter<br />
is an array that indicates the width <strong>of</strong> each category. If the number <strong>of</strong> categories is greater than<br />
the number <strong>of</strong> widths, the widths are repeated.<br />
SELECT rid, band, ST_Histogram(rast) As stats<br />
FROM dummy_rast;<br />
• Computes quantiles <strong>The</strong> ST_Quantile(raster, quantiles[]) function computes quantiles <strong>for</strong> a<br />
raster in the context <strong>of</strong> the population. A pixel value could be examined to be at 25%, 50%,<br />
75% percentile <strong>of</strong> the raster data that contains all possible pixel values.<br />
SELECT ST_Quantile(rast, 0.75) As value<br />
FROM dummy_rast WHERE rid=1;<br />
• Get number <strong>of</strong> pixels <strong>The</strong> ST_ValueCount(raster, values[]) function returns a set <strong>of</strong> records<br />
containing a pixel band value and the number <strong>of</strong> pixels in a given band that have a given set<br />
<strong>of</strong> values. If no band is specified, band number 1 is used by default. By default nodata value<br />
pixels are not counted and pixel band values are rounded to the nearest integer.<br />
SELECT ST_ValueCount(rast) As value<br />
FROM dummy_rast WHERE rid=1;<br />
5.4 Display <strong>Raster</strong>s<br />
Normally any s<strong>of</strong>twares, that use GDAL to read raster and enable a database connection, are able<br />
to display raster directly from <strong>PostGIS</strong> database. Examples <strong>of</strong> such s<strong>of</strong>tware include:<br />
• QGIS plugin<br />
65
• gvSIG plugin<br />
• MapServer through GDAL<br />
Other s<strong>of</strong>twares that do not support direct raster displaying but instead they allow displaying a<br />
vectorization <strong>of</strong> the raster. This is the case <strong>of</strong> any s<strong>of</strong>twares that are used to display vector <strong>PostGIS</strong><br />
queries such as OpenJump or ArcGIS 10.<br />
– OpenJump<br />
SELECT ST_AsBinary((ST_DumpAsPolygons(rast)).geom), (ST_DumpAsPolygons(rast)).val<br />
FROM dummy_rast<br />
WHERE rid=1;<br />
– ArcGIS 10<br />
Same as OpenJump but without ST_AsBinary():<br />
SELECT (ST_DumpAsPolygons(rast)).geom, (ST_DumpAsPolygons(rast)).val<br />
FROM dummy_rast WHERE rid=1;<br />
5.5 Edit and Compute <strong>Raster</strong>s<br />
• Set pixel value <strong>The</strong> ST_SetValue(raster, band, geometricpoint, newvalue) function returns a<br />
new raster resulting from setting the value <strong>of</strong> a given band in a given column x and row y<br />
pixel or at a pixel that intersects a particular geometric point. Band number starts at 1 and is<br />
assumed to be 1 if not specified.<br />
UPDATE dummy_rast<br />
SET rast = ST_SetValue(rast,1, ST_Point(3427927.75, 5793243.95),100)<br />
WHERE rid = 1 ;<br />
• Reclass rasters <strong>The</strong> ST_Reclass(raster, band, reclassexpression, pixeltype, nodatavalue) function<br />
creates a new raster by applying a valid <strong>PostgreSQL</strong> algebraic operation that defines a class<br />
expression on the input raster band. <strong>The</strong> band number specifies the band to be changed. If it<br />
is not specified, it is assumed to be 1. All other bands are unchanged. <strong>The</strong> new raster will have<br />
the same georeference, width and height as the original raster. Use case: convert a 16 BUI band<br />
to a 8 BUI and so on <strong>for</strong> simpler rendering.<br />
ALTER TABLE dummy_rast ADD COLUMN reclass_rast raster;<br />
UPDATE dummy_rast<br />
SET reclass_rast = ST_Reclass(rast,2,’0-87:1-10, 88-100:11-15, 101-254:0-0’,<br />
’4BUI’,0)<br />
WHERE rid = 1;<br />
• Clip rasters <strong>The</strong> ST_Clip(raster, band, geometry) function returns a new raster that is clipped<br />
by an input geometry. If no band is specified all bands are returned.<br />
SELECT ST_Clip(rast, ST_Buffer(ST_Centroid(ST_Envelope(rast)), 20), false )<br />
FROM aerials.boston<br />
WHERE rid = 4;<br />
• Apply algebra operation <strong>The</strong> ST_MapAlgebraExpr(raster, band, pixeltype, expression) function<br />
creates a new one band raster by applying a valid <strong>PostgreSQL</strong> algebraic operation on the input<br />
raster band. Band 1 is assumed if no band is specified. <strong>The</strong> new raster will have the same<br />
georeference, width and height as the original raster but will only have one band. If pixeltype<br />
is given, then the new raster will have a band <strong>of</strong> that pixeltype. If pixeltype is passed NULL,<br />
then the new raster band will have the same pixeltype as the input rast band.<br />
66
Figure 5.2: Clipping raster effect [17].<br />
ALTER TABLE dummy_rast ADD COLUMN map_rast raster;<br />
UPDATE dummy_rast SET map_rast = ST_MapAlgebraExpr(rast,NULL,<br />
’CASE WHEN rast < 0 THEN rast+10 ELSE NULL END’)<br />
WHERE rid = 1;<br />
Figure 5.3: Algebra operation on rasters [23].<br />
5.6 Convert <strong>Raster</strong>s to GDAL Format<br />
5.6.1 <strong>Raster</strong> to TIFF File<br />
<strong>The</strong> ST_AsTIFF(raster, numberbands, compression) function returns the selected raster bands as a<br />
single TIFF image (byte array). If no band is specified, it will try to use all bands. Where:<br />
– numberbands: an array <strong>of</strong> bands used to export (max is 3 bands). <strong>The</strong> order <strong>of</strong> the bands is<br />
RGB. For example, ARRAY[3,2,1] maps band 3 to Red, band 2 to green and band 1 to blue.<br />
– compression: a compression type such as JPEG90 (or some other percent), LZW, JPEG or<br />
DEFLATE9.<br />
SELECT ST_AsTIFF(rast, ’JPEG90’) As rasttiff<br />
FROM dummy_rast<br />
WHERE rid=1;<br />
5.6.2 <strong>Raster</strong> to JPEG File<br />
<strong>The</strong> (ST_AsJPEG(raster, band/numberbands, quality) function returns the selected raster bands as<br />
a single JPEG image (byte array). Where:<br />
– band: a number that specifies a band <strong>for</strong> single band export.<br />
– numberbands: an array <strong>of</strong> bands used to export (max is 3 bands). <strong>The</strong> order <strong>of</strong> the bands is<br />
RGB. If more than 3 bands are specified, then only the first band is used. If only 3 bands are specified,<br />
then all 3 bands are mapped to RGB. For example, ARRAY[3,2,1] maps band 3 to Red, band 2 to<br />
green and band 1 to blue. If both band and numberbands are specified, band 1 is used by default.<br />
– quality: a number ranged from 0 to 100. Default is 75.<br />
67
SELECT ST_AsJPEG(rast) As rastjpg<br />
FROM dummy_rast<br />
WHERE rid=1;<br />
5.6.3 <strong>Raster</strong> to PNG File<br />
<strong>The</strong> ST_AsPNG(raster, band/numberbands, compression) function returns the selected raster bands<br />
as a single PNG image (byte array). Where:<br />
– band: a number that specifies a band <strong>for</strong> single band export.<br />
– numberbands: an array <strong>of</strong> bands used to export. Bands are mapped to RGB or RGBA space.<br />
For example, ARRAY[3,2,1] means map band 3 to Red, band 2 to green and band 1 to blue.<br />
If both band and numberbands are not specified, then all bands are used if the raster has 1, 3, or<br />
4 bands and. If it has 2 or more than 4 bands, then only band 1 is used.<br />
– compression is a number from 1 to 9.<br />
SELECT ST_AsPNG(rast) As rastpng<br />
FROM dummy_rast WHERE rid=2;<br />
5.7 Intersect <strong>Raster</strong>s with Vectors<br />
One approach to make this operation is to convert all raster tiles to a set <strong>of</strong> geometries and do a<br />
traditional intersection query between geometries only. <strong>The</strong> problem is that vectorizing all the tiles<br />
will be too long and it is impossible to load a huge number <strong>of</strong> geometry in GIS s<strong>of</strong>tware. Since it is<br />
mostly impossible to convert those tiles to vectors, the <strong>PostGIS</strong> <strong>Raster</strong> approach will vectorize only<br />
what is needed to do the requested operation.<br />
In the intersection, if a geometry completely overlaps a nodata value area <strong>of</strong> one tile, st_intersects(rast,<br />
geom) will return false <strong>for</strong> this tile/geometry couple and st_intersection(rast, geom)<br />
will return an EMPTY GEOMETRY without vectoring this tile. If the geometry partially overlaps a nodata<br />
value area and intersects other parts <strong>of</strong> the tile, st_intersects(rast, geom) will return true <strong>for</strong> this<br />
tile/geometry couple and st_intersection(rast, geom) will return only values <strong>of</strong> parts <strong>of</strong> the tile<br />
that intersects the geometry.<br />
5.7.1 Intersect <strong>Raster</strong>s with Points<br />
Practically, user can use intersection operation to extract ground elevation values <strong>for</strong> lidar (Light<br />
Detection And Ranging) 1 points.<br />
SELECT pointID, ST_Value(rast, geom) elevation<br />
FROM lidar, srtm WHERE ST_Intersects(geom, rast)<br />
Figure 5.4: Intersection <strong>of</strong> raster and geometric points [23].<br />
In the above request, the intersection(raster,vector) operation is not necessarily needed. This is<br />
due to the fact that each geometric point is represented by a pixel or a cell <strong>of</strong> a grid. So to extract<br />
1 http://en.wikipedia.org/wiki/LIDAR.<br />
68
elevation values at lidar points, only the ST_Value() function, that gives elevation values at particular<br />
geometric points, is needed.<br />
5.7.2 Intersect <strong>Raster</strong>s with Lines<br />
In the case <strong>of</strong> geometric lines, this operation is used to extract elevation values <strong>for</strong> each road<br />
segment in a road network.<br />
SELECT roadID,<br />
(ST_Intersection(geom, rast)).geom road,<br />
(ST_Intersection(geom, rast)).val elevation<br />
FROM roadNetwork, srtm<br />
WHERE ST_Intersects(geom, rast)<br />
User accesses the geometry and the value parts <strong>of</strong> the resulting set <strong>of</strong> geomval by surrounding<br />
them with parentheses and adding .geom or .val at the end <strong>of</strong> the expression.<br />
5.7.3 Intersect <strong>Raster</strong>s with Polygons<br />
Figure 5.5: Intersection <strong>of</strong> raster and roads [23].<br />
In the same way, user can extract temperature values <strong>for</strong> each polygon (circles in the following<br />
example).<br />
CREATE TABLE buff_temp AS<br />
SELECT id, (gv).geom buffer, (gv).val temp<br />
FROM (SELECT id, ST_Intersection(geom, rast) gv<br />
FROM buffers, temperature<br />
WHERE ST_Intersects(geom, rast))<br />
Figure 5.6: Intersection <strong>of</strong> raster polygons [23].<br />
<strong>The</strong>n, the result can also be used to compute the mean temperature <strong>for</strong> each polygon.<br />
CREATE TABLE result AS<br />
SELECT id,<br />
sum(ST_Area(the_geom) * val) / sum(ST_Area(the_geom)) AS meantemp<br />
69
FROM buff_temp<br />
GROUP BY id<br />
ORDER BY id;<br />
5.8 Aggregate Functions<br />
Figure 5.7: Different temperature values in a polygon [23].<br />
<strong>The</strong> ST_Union(rast, band, expression) function returns a single band raster from the union<br />
<strong>of</strong> a set <strong>of</strong> raster tiles. If no band is specified <strong>for</strong> the union, band number 1 is assumed. <strong>The</strong><br />
resulting raster’s extent is the extent <strong>of</strong> the whole set. <strong>The</strong> resulting raster pixel values are defined by<br />
expression parameter. User can define their own expressions or use predefined functions like FIRST,<br />
LAST, MIN, MAX, SUM, MEAN and COUNT. <strong>The</strong> default function is LAST when no expression<br />
is specified. <strong>The</strong> LAST (respectively FIRST) function merges all rasters together by unioning their<br />
extents and burning the last (first) raster without taking the other raster pixel values into account.<br />
SELECT (ST_Union(rast, ’last’)<br />
FROM dummy_rast;<br />
5.9 Create a High Resolution Analysis Grid<br />
Even though, to compute road and river length, mean temperature and etc, a vector <strong>for</strong>mat can<br />
be used to store each cell <strong>of</strong> a grid as a polygon. <strong>The</strong>n necessaire operations are applied to the set<br />
<strong>of</strong> polygons. It sounds like raisonnable but with a huge set <strong>of</strong> polygon (500 000 x 300 000 polygons)<br />
resulting from a large area, these polygons are unmanageable. In contrast, by using raster, users can<br />
choose to encapsulate them into small blocks as far as they want <strong>for</strong> easy analysis.<br />
For example, all <strong>of</strong> USA can be stored as a grid <strong>of</strong> 500 000 x 300 000 pixels or cells (each cell<br />
represents an area <strong>of</strong> 10 m). In raster <strong>for</strong>mat, these polygons are manageable in 15 000 000 tiles<br />
<strong>of</strong> 100x100 pixels. <strong>The</strong> rest is to intersect vector layers with the raster tiles and apply appropriate<br />
operations to the intersection result.<br />
5.10 Create a Specialised Web or Desktop GIS Application<br />
Complete SQL GIS<br />
With the raster API, <strong>PostGIS</strong> is now a very complete SQL GIS as:<br />
• It provides a single set <strong>of</strong> overlaid functions that work seamlessly on raster and vector files. So<br />
an easy SQL API to manipulate and analyse graphical data.<br />
• All geographic data (vector and raster) is spatially indexed. So there is no need to write complex<br />
C,C++, Python or JAVA code to manipulate complex data.<br />
70
Figure 5.8: Gird <strong>of</strong> cells <strong>of</strong> USA map [23].<br />
• <strong>PostGIS</strong> provides several storage solutions <strong>for</strong> applications whether they are read-only applications<br />
(storing out-database raster) or editing and analysis applications (storing in-database<br />
raster).<br />
With out-database raster, image files (JPEGs) can be stored as they are in any GDAL <strong>for</strong>mat.<br />
So it speeds up geoprocessing (a GIS operation used to manipulate spatial data) by providing<br />
direct access <strong>for</strong> web applications.<br />
<strong>The</strong> traditional in-database raster, that stores raster data as a grid <strong>of</strong> pixel values, is intended<br />
<strong>for</strong> analysis operations that require working on pixel values. Obviously, execution time <strong>of</strong> these<br />
operations are faster than ones executed on out-database rasters since there is no need to extract<br />
the pixel values from an image file (such as JPEG, TIFF and etc).<br />
Lightweight Multi-users<br />
As all geoprocessing is done in the database, these processes thus are kept close to the data where<br />
the data should be (in a database). Hence, desktop and web GIS applications become simple SQL<br />
query builders and data viewers.<br />
Figure 5.9: Web GIS application [23].<br />
71
Chapter 6<br />
Application<br />
Most <strong>of</strong> GIS applications <strong>of</strong>ten relate to the history <strong>of</strong> changes <strong>of</strong> phenomena like temperature,<br />
precipitation and etc. This section intends to introduce a novice application that shows the evolution<br />
in time <strong>of</strong> a set <strong>of</strong> temporal raster data, where each temporal raster is a matrix <strong>of</strong> values <strong>of</strong> points<br />
in space at a time instant. Each temporal raster can also be referred as a map, hence the evolution<br />
is considered as a sort <strong>of</strong> movie-map. <strong>The</strong> application is built on Quantum Geographic In<strong>for</strong>mation<br />
System (QGIS). So, the first part <strong>of</strong> this section will introduce QGIS and its application. <strong>The</strong> second<br />
part focuses on the time application.<br />
6.1 Quantum GIS<br />
Quantum GIS (QGIS) is a Geographic In<strong>for</strong>mation System application that provides geographical<br />
data viewing, editing and analysis capabilities using graphical interface.<br />
QGIS is cross plat<strong>for</strong>m and runs on Linux, Unix,Mac OS X and Windows. By using GDAL,<br />
GRASS GIS, <strong>PostGIS</strong> and <strong>PostgreSQL</strong> as extensions, QGIS provides access to various vector, raster<br />
<strong>for</strong>mats and works on multiple databases. QGIS is written in C++ and allows integration <strong>of</strong> user<br />
plugins developed using either C++ or Python.<br />
6.1.1 Advantages<br />
<strong>The</strong>re are several reasons that make QGIS become one <strong>of</strong> the tools used in most GIS and preferred<br />
than other GIS applications [20]:<br />
• Quantum GIS is open-source.<br />
• It <strong>of</strong>fers a similar interface as market s<strong>of</strong>tware like ArcGIS or SuperGIS.<br />
• It can view, edit and create a wide variety <strong>of</strong> vector <strong>for</strong>mats ( Shp, vectors Grass, <strong>PostgreSQL</strong><br />
/ <strong>PostGIS</strong> and etc.)<br />
• Its s<strong>of</strong>tware that evolves and improves continuously through custom plugins (Python or C++).<br />
• It allows interoperability with external databases (such as <strong>PostGIS</strong>,MapServer and etc.).<br />
• It is available in multi-language and has a large volunteer community.<br />
• Its capability to run with additional tools (Openstreetmap, Google Maps and etc.).<br />
• It connects with external sources <strong>of</strong> data (WFS and WMS servers).<br />
• <strong>The</strong> graphical interface <strong>of</strong> QGIS is much cleaner and faster than one <strong>of</strong> GRASS GIS.<br />
• Its possibility <strong>of</strong> using Quantum GIS as a graphical interface GRASS GIS through a plug-in.<br />
• Quantum GIS requires a small memory space.<br />
72
6.1.2 Utilisation<br />
QGIS is designed with a graphical user interface to enhance user interaction. It consists <strong>of</strong> a layout<br />
area, a layers panel, toolbars and a status bar (see Figure 6.1).<br />
<strong>The</strong> layout area is where the map is displayed.<br />
<strong>The</strong> layers panel contains a list <strong>of</strong> layers that are added to the project. In this area, user can make<br />
a layer visible (not visible) by checking (unchecking) the box related to its layer name. Only the top<br />
layer is displayed in layout area as this one masks bottom layers.<br />
Figure 6.1: QGIS interface.<br />
<strong>The</strong> status bar is located at the bottom right. It displays coordinates <strong>of</strong> the current position, the<br />
scale <strong>of</strong> the area, and the projection property <strong>of</strong> the layer.<br />
<strong>The</strong> toolbars describe the features found in the menu. <strong>The</strong>y comprise four main parts (as shown in<br />
Figure 6.2 from left to right): the file part <strong>for</strong> project management, the view part <strong>for</strong> repairing the area<br />
being worked on, the layer part <strong>for</strong> layer management and the extra part <strong>for</strong> extension functionalities<br />
(such as GRASS, WKT<strong>Raster</strong> and etc.).<br />
Figure 6.2: QGIS toolbars.<br />
In the layer management tool, user can import a vector or a raster layer from filesystem. Furthermore,<br />
a remarkable feature, that makes QGIS become the first choice in comparison with GRASS, is<br />
its ability to connect with <strong>PostGIS</strong> database. <strong>The</strong>n user can load a vector or a raster layer directly<br />
from <strong>PostGIS</strong> into QGIS.<br />
However, just only QGIS with version from 1.7 supports raster. This feature is integrated through<br />
WKT<strong>Raster</strong> plugin.<br />
73
6.2 Tools<br />
Figure 6.3: <strong>PostGIS</strong> connection.<br />
This part focuses on a new approach to represent geographic data such as temporal raster data.<br />
This approach consists <strong>of</strong> exploiting the temporal features <strong>of</strong> raster to show the evolution in time <strong>of</strong><br />
real world phenomena, so called time travel. In addition, an extra tool that allows user to create a<br />
specific color legend <strong>for</strong> a set <strong>of</strong> temporal raster data is also represented. <strong>The</strong> extra tool thus enhances<br />
the time travel application.<br />
6.2.1 Interface<br />
At the beginning, the application starts with listing all <strong>of</strong> the tables that have a column <strong>of</strong> type<br />
temporal raster in the Temporal raster table(s) window. <strong>The</strong>se tables are retrieved directly from<br />
<strong>PostGIS</strong> database as QGIS is capable <strong>of</strong> establishing a connection to <strong>PostGIS</strong>. Users will choose one<br />
table <strong>for</strong> visualizing the evolution in time <strong>of</strong> temporal rasters existed in this table.<br />
Figure 6.4: Temporal raster window.<br />
74
Time Travel<br />
<strong>The</strong> time travel feature is available through a separate window. This window is divided into three<br />
main areas: time , media and band areas. <strong>The</strong> time and media areas gather all <strong>of</strong> the necessary<br />
options <strong>for</strong> controlling the evolution in time <strong>of</strong> temporal raster data. <strong>The</strong> band area relates to the<br />
band properties.<br />
Time Area<br />
Figure 6.5: Time travel interface.<br />
As shown in the time region, the first slider bar represents the evolution in time <strong>of</strong> a set <strong>of</strong> loaded<br />
temporal rasters. <strong>The</strong> interval between two ticks represents the minimum time interval between two<br />
any temporal rasters. It is expressed in day unit and its value can be changed from the spin box<br />
Time interval. Just behind these ticks, on the left side is the minimum time instant and on the<br />
right side is the maximum time instant that exists in the temporal raster set. <strong>The</strong> current time field<br />
indicates the current time instant <strong>of</strong> the evolution as the slider moves.<br />
<strong>The</strong> Begin time and End time fields express the evolution time interval in which all the temporal<br />
rasters that have a time instant included in this interval will be counted in the evolution. For example,<br />
user may choose to view the evolution beginning at some particular time instant (2001-07-13 08:17:34<br />
in the figure) by entering this time instant in the Begin time field. Otherwise, it can be taken from<br />
the calendar button, located just next to the Begin time field. <strong>The</strong> same <strong>for</strong> the End time field.<br />
Media Area<br />
<strong>The</strong> media area <strong>of</strong>fers different ways to control the evolution : move <strong>for</strong>ward to next temporal<br />
raster (or map), move backward to previous map, move to begin map, move to final map, play and<br />
stop temporal raster evolution (or movie). Furthermore, the second slider bar help user change the<br />
speed <strong>of</strong> the movie. This speed varies from minimum 0.05s to maximum 2s.<br />
Band Area<br />
It depends on the number band that each raster possesses, the application proposes appropriate<br />
options. In the one band case, the raster is a gray image because each pixel point is expressed by a<br />
single value. Hence, the application provides user the possibility to load a color palette from a palette<br />
file (Load a style field). <strong>The</strong> palette file is created from the color legend button (this feature is<br />
described later). When rasters have multiple bands (color images), users have possibilities to view<br />
overlapping multiple bands (Multi Band Color radio button) or each band individually ( Single Band<br />
Color radio button). If the Single Band Color radio button is marked, a compose box with a list <strong>of</strong><br />
band numbers will appear to help user choose to visualize a desired band.<br />
<strong>The</strong> Single Band radio button (respectively Multi Band radio button) is not an option <strong>for</strong> users.<br />
It is used to in<strong>for</strong>m users if rasters are single band (respectively multi band). Both <strong>of</strong> them are<br />
75
Figure 6.6: Band area.<br />
controlled by the application and choices made by users on these options have no effect either on<br />
Multi Band or Single Band£ button.<br />
6.2.2 Color Legend<br />
<strong>The</strong> color legend is used to indicate the significance <strong>of</strong> color by numbers. It consists <strong>of</strong> a title, a<br />
color bar and a common unit <strong>for</strong> numbers and tick notations. In the example below, the red color<br />
area expresses high temperature and the blue color area expresses low temperature.<br />
Figure 6.7: <strong>The</strong> temperature color legend.<br />
As each temporal raster is a matrix <strong>of</strong> values <strong>of</strong> points in space, hence it is referred to as a map.<br />
Each map possesses normally a minimum value and a maximum value. If Time travel is an application<br />
that shows the evolution <strong>of</strong> a set <strong>of</strong> maps, then the color legend representing all these maps needs to<br />
be computed from this set. It does not make sense when the color legend <strong>of</strong> a specific map is used<br />
<strong>for</strong> a set <strong>of</strong> maps. This also means that the minimum value (respectively maximum) at the bottom<br />
(respectively top) <strong>of</strong> the color legend is the minimum value <strong>of</strong> a set <strong>of</strong> maps.<br />
<strong>The</strong> color legend is available through another window than Time travel window. <strong>The</strong> Output color -<br />
palette file field let user enter the desired name <strong>for</strong> the created color palette file. In the Color palette<br />
region, the left compose box contains all <strong>of</strong> the available color palettes that help users to freely choose<br />
a satisfied one. Behind this box, the chosen color palette is shown.<br />
<strong>The</strong> Apply button aims to apply the chosen palette to the current map <strong>for</strong> users to visualize, along<br />
with creating a corresponding color palette file with the name given by the Output color palette file<br />
field. Users can repeat this step as many times as the number <strong>of</strong> existing palettes. Once a color palette<br />
file is created, its name is registered in the Created color palette(s) compose box. On the one<br />
hand, these color palette files serve as style files <strong>for</strong> maps and are used to create corresponding color<br />
legends on the other hand. Finally, the Create button creates the color legend <strong>of</strong> the current color<br />
palette file. <strong>The</strong> result <strong>of</strong> the color legend is simply a PNG image file.<br />
6.3 Implementation<br />
<strong>The</strong> application is developed as a plugin [12] in QGIS using PyQt, the bridge between Python and<br />
Qt4 graphics library.<br />
76
Figure 6.8: <strong>The</strong> color legend interface.<br />
QGIS retrieves the temporal raster table from <strong>PostgreSQL</strong> using a connection string and a SQL<br />
command. <strong>The</strong> connection string is used to establish a connection to <strong>PostgreSQL</strong>. Its structure is<br />
’PG: dbname=%s host=%s user=%s password=%s port=%s’. <strong>PostgreSQL</strong> then executes the SQL<br />
command and outputs temporal raster table list as a result.<br />
6.3.1 Time Travel<br />
Loading Data<br />
To show the revolution in time <strong>of</strong> a set <strong>of</strong> temporal rasters, first <strong>of</strong> all, data need to be loaded<br />
from <strong>PostgreSQL</strong> into QGIS. <strong>The</strong>re exist two approaches <strong>for</strong> loading temporal raster (or map). <strong>The</strong><br />
first one attempts to load each map, one after another from <strong>PostgreSQL</strong> database into QGIS. When<br />
loading a map, there is a change from QGIS cursor to <strong>PostgreSQL</strong> cursor. That is because when QGIS<br />
establishes a connection to <strong>PostgreSQL</strong>, <strong>PostgreSQL</strong> will execute a request to retrieve a temporal raster<br />
row. When the map is loaded, necessary PyQt instructions like updating current time, progress slider<br />
bar etc. are need to be executed to show the evolution. In turn, a cursor change from <strong>PostgreSQL</strong> to<br />
QGIS occurs again be<strong>for</strong>e these instructions take place, as PyQt instructions are managed by QGIS<br />
cursor. <strong>The</strong>se steps are exactly what will happen to the next loaded map and so on until the final<br />
loaded map. This approach sounds cumbersome and involves a lot <strong>of</strong> execution time due to cursor<br />
changes.<br />
Figure 6.9: <strong>The</strong> loading map sequential approach.<br />
In the second approach, all maps are loaded into QGIS memory once and <strong>for</strong> all. Hence, only two<br />
cursor changes are needed (one from QGIS to <strong>PostgreSQL</strong> and another from <strong>PostgreSQL</strong> to QGIS).<br />
<strong>The</strong>n, the visibility <strong>of</strong> each map is simply handled by turning on or <strong>of</strong>f the check box corresponding to<br />
this map from the layers panel as described in the previous section. This approach reduces enormously<br />
execution time. Another advantage results from this is that all maps can be organized in an order<br />
(descending or ascending) by modifying the SQL command. <strong>The</strong> ordering can not happen in the first<br />
approach as each map is individually loaded.<br />
Pseudo code <strong>of</strong> function iniLayers that loads all layers into QGIS using the second approach:<br />
def iniLayers(self):<br />
Retrieve a list <strong>of</strong> temporal raster IDs to rids<br />
Change QGIS cursor to <strong>PostgreSQL</strong> cursor<br />
77
Figure 6.10: <strong>The</strong> loading map parallel approach.<br />
For each rid in rids:<br />
Retrieve a layer from <strong>PostgreSQL</strong> using a connection string<br />
Try to add layer to qgis<br />
Come back to QGIS cursor<br />
Figure 6.11: Maps representing world climate [7] are loaded once time. <strong>The</strong>ir visibility is handled by<br />
turning on/<strong>of</strong>f the check boxes list.<br />
Media Control<br />
Each loaded map is identified by an ID. All map IDs are saved in a list layerIds. Only maps that have<br />
a time instant included in interval from Begin time to End time will be shown in the evolution. When<br />
the play media button is triggered, the first map that satisfies the time condition will be displayed.<br />
Subsequently, value in the Current time field is updated by time instant <strong>of</strong> the first map and the slider<br />
in the Time region moves by a step. Each step is at least equals the tick interval (by definition <strong>of</strong><br />
tick interval in the previous section). <strong>The</strong>n a QTimer ctimer is necessary to increase the time interval<br />
between two displayed maps instances. Otherwise, all maps that satisfy the time range condition will<br />
be displayed nearly at the same time and human eyes can not recognize the succession <strong>of</strong> the maps.<br />
Users can drag and drop the speed slider to change this time interval from 0.05s to 2s. After the<br />
ctimer is time out, it triggers the displaying function displayLayer to display the second map and so<br />
on until the final map is reach.<br />
Pseudo code <strong>of</strong> function playMedia:<br />
If a map satisfies the time condition<br />
Display the map<br />
Update current time field<br />
Move slider<br />
Trigger ctimer<br />
Pseudo code <strong>of</strong> function displayLayer:<br />
Retrieve a map from a map id<br />
Turn on the visibility <strong>of</strong> this map<br />
78
Band Properties<br />
Figure 6.12: Media area.<br />
Depend on the number <strong>of</strong> bands that a map possesses, the Single band radio button (respectively<br />
the Multi band radio button) will be marked if the map has only one band (multi band).<br />
Figure 6.13: Single band rasters.<br />
In the case <strong>of</strong> one band, each map is coded in gray color (a pixel color is coded either in RGB or<br />
CMYK color models that require at least three band). However, user can load a color palette from a<br />
style file created from color legend option. A style file describes each pixel value by a RGB triple in<br />
each row. Example <strong>of</strong> rows in a style file is as follows:<br />
"17.00592,139,0,116,255,<br />
17.56223,137,0,118,255,<br />
..."<br />
<strong>The</strong> first number is a pixel value. <strong>The</strong> next three numbers are a RGB triple. <strong>The</strong> final number<br />
is alpha value that indicates the transparency level between an image and a background. In this<br />
example, 255 will create a full transparency.<br />
To set up a color palette <strong>for</strong> a map from a style file, firstly QGIS uses the file to create Color Ramp<br />
Entries array object and then set this object <strong>for</strong> the maps.<br />
Pseudo code to set up a color palette:<br />
Create Color Ramp Entries array object<br />
For each loaded map<br />
Tell the map to use a QgsColorRampShader function<br />
Get a pointer to the raster shader function<br />
Set parameters <strong>for</strong> the QgsColorRampShader function using Color Ramp Entries array<br />
Refresh the map<br />
In multi band case, as maps are already coded in either RGB or CMYK color models, then there<br />
is no option to create a color table. Instead, it <strong>of</strong>fers the possibility <strong>for</strong> user to choose a specific single<br />
band <strong>for</strong> visualization or switch to multi band mode. By default, color maps are displayed in multi<br />
band color mode. When single band color mode is activated and a band number is chosen, the function<br />
mulSinBandCol is used to turn on only the chosen band and turn <strong>of</strong>f the others band <strong>for</strong> all maps.<br />
Pseudocode <strong>for</strong> mulMulBandCol:<br />
For each loaded map<br />
Turn the map on MultiBandColor mode.<br />
For single band color, pseudocode <strong>of</strong> mulSinBandCol is:<br />
79
Figure 6.14: Maps representing world climate are loaded as single band rasters. <strong>The</strong>y are turned into<br />
color maps by loading a created color palette "worldclim.txt".<br />
Figure 6.15: Map is loaded as multi band raster.<br />
80
For each loaded map<br />
Turn the map on MultiBandSingleBandPseudoColor mode<br />
Set the chosen band as the band to be displayed<br />
Set PseudoColorShader as color shading algorithm <strong>for</strong> the map<br />
6.3.2 Color Legend<br />
Figure 6.16: Visualisation <strong>of</strong> band number 2 <strong>of</strong> a multi band map.<br />
<strong>The</strong> most important function in color legend construction is compute<strong>Raster</strong>Stats. It computes the<br />
minimum and the maximum pixel values from a set <strong>of</strong> temporal rasters (or maps). In fact, these values<br />
are resulted from <strong>PostgreSQL</strong> through a connection. For instance, the minimum pixel value is computed<br />
from the request SELECT min((ST_SummaryStats((rtt).rast)).min) FROM temporal<strong>Raster</strong>Table<br />
(the temporal raster table is described in the interface Section). <strong>The</strong> (ST_SummaryStats((rtt).rast)).min)<br />
part gives, <strong>for</strong> each temporal raster in the temporal<strong>Raster</strong>Table, a corresponding minimum pixel value.<br />
Hence, the min((ST_SummaryStats((rtt).rast)).min) gives the minimum value <strong>of</strong> a set <strong>of</strong> minimum<br />
values according to the definition <strong>of</strong> the minimum pixel value <strong>of</strong> a set <strong>of</strong> temporal rasters.<br />
Each color palette is provided from an external tbl file. <strong>The</strong> tbl file describes a RGB triple <strong>of</strong><br />
color in each row. Hence the number <strong>of</strong> possible colors <strong>of</strong> a color palette is the number <strong>of</strong> lines used<br />
to code colors. Example <strong>of</strong> a tbl file is something like:<br />
"{ r g b }<br />
102 47 0<br />
153 96 53<br />
..."<br />
Each time, when users choose a color palette from Color legend window, the in<strong>for</strong>mation related<br />
to this palette, such as the number <strong>of</strong> colors, the RGB values array and the real data values, is saved<br />
respectively into three variables nColo, arColo and arColV. <strong>The</strong> creation <strong>of</strong> a color legend file (a PNG<br />
file) implies the use <strong>of</strong> these variables, along with the minimum and maximum pixel values <strong>of</strong> a set <strong>of</strong><br />
temporal rasters. For instance, the number <strong>of</strong> colors decides the color legend length, where each RGB<br />
color is painted as a color ligne. <strong>The</strong> tick notations are given by variable arColV. <strong>The</strong> number <strong>of</strong> tick<br />
notations depends on the number <strong>of</strong> colors that a palette has. If it has less than 10, the number <strong>of</strong> tick<br />
notations is equal to the number <strong>of</strong> available colors. Otherwise, it will be a fixed number and equal<br />
to 10. In this case, the number <strong>of</strong> colors between two tick notations is the division <strong>of</strong> the number <strong>of</strong><br />
colors by 10.<br />
81
Figure 6.17: Maps with a color legend.<br />
82
Chapter 7<br />
Conclusion<br />
Geography that evolves spatial organization and material character <strong>of</strong> the Earth’s surface is a<br />
relevant source to decision makers in business and government. For example, underlying all <strong>of</strong> the<br />
recommendations results that the demand <strong>for</strong> contributions from geography and the supply capacity <strong>of</strong><br />
current resources, are far out <strong>of</strong> line. Otherwise, faulty actions are taken and taken quickly, geography’s<br />
contributions will be severely constrained or may decline in quality.<br />
Even in the areas where geography is not contributing in a significant way, it could be seen as a<br />
provider giving resources and in<strong>for</strong>mation <strong>for</strong> decision makers. Geography provides a valuable way<br />
<strong>of</strong> thinking about human and environmental issues. Geography integrates phenomena and processes<br />
in particular places, in connection with the search, to contributes to science as an creative ef<strong>for</strong>t to<br />
advance the frontiers <strong>of</strong> knowledge. For example, the relationship between population, society and<br />
environmental resource has been a central issue <strong>for</strong> science. In this way, geography focuses on the<br />
nature <strong>of</strong> that relationship and analysis processes to identify relations between changes in population,<br />
environment and society.<br />
In many ways, geography sees the world as a continuous surface <strong>of</strong> landscapes, movements and<br />
interactions. Research on interdependencies between places can help to explain and predict spatial<br />
interactions. For example, decisions to relocate are the important decisions made by households that<br />
have, as a consequence, significant implications <strong>for</strong> the links between places. Recent work on the<br />
nature <strong>of</strong> the migration and mobility process shows that decisions to move are related to age, family<br />
composition and economic circumstances. Studies <strong>of</strong> interdependencies between places contribute also<br />
to the understanding <strong>of</strong> several critical issues <strong>for</strong> society. For example, one <strong>of</strong> the best illustrations <strong>of</strong><br />
spatial interdependence addresses the spread <strong>of</strong> infectious diseases. <strong>The</strong> spread <strong>of</strong> such diseases can<br />
be understood and predicted by using spatial modeling techniques related to location, synthesis and<br />
scale [19].<br />
So a GIS with only vector data type relates to geometric elements (such as roads, houses, trees,<br />
etc.) is not enough. <strong>The</strong> raster data type made <strong>of</strong> a matrix <strong>of</strong> points, suitable to describe continuous<br />
fields, phenomena that are perceived as having a value at each point in space and time, is not only<br />
a necessary complement type <strong>of</strong> vector but also a powerful feature that makes GIS become a perfect<br />
graphical tool. Current trends in GIS techniques suggest a future in which researchers, students,<br />
business people and public policy makers will explore a world <strong>of</strong> shared spatial data. <strong>The</strong>y will<br />
request analyses from a rich menu <strong>of</strong> options, select preferred geographic area and spatial scale <strong>for</strong><br />
analysis and export results in multimedia <strong>for</strong>mats. So, in developing GIS tools, developers need to<br />
think more not only about context <strong>of</strong> problems, but also about knowledge and skill levels <strong>of</strong> users as<br />
the users <strong>of</strong> tomorrow will be more numerous than at present.<br />
Furthermore, more development is needed to turn GIS applications into robust, efficient and fully<br />
functional tools. For example, advanced features like a query editor tool providing facilities <strong>for</strong> <strong>for</strong>mulating<br />
a query, a query viewer that displays result <strong>of</strong> geographic queries with various additional<br />
features such as an intelligent zoom, different possible visualizations <strong>of</strong> the same data by navigating<br />
in time and in different perceptions [1].<br />
More importantly, with the demonstrated important role <strong>of</strong> geographers in decision making, institutions<br />
and leaders in government, business, education and the communications media need to raise<br />
83
their levels <strong>of</strong> awareness <strong>of</strong> geography’s value to science and society and find more effective ways to<br />
publicize and utilize geography’s perspectives, skills and knowledge.<br />
A multimodal interface is defined as an interface that uses two or more means <strong>of</strong> modalities to<br />
interact with a computer. <strong>The</strong> usability <strong>of</strong> current GIS in the future will be improved using multimodal<br />
interfaces as these interfaces can give users more expressiveness and flexibility as well as better tools<br />
<strong>for</strong> controlling sophisticated visualization and multimedia output. For example, in planning and<br />
management, current GIS require extensive time and training <strong>for</strong> proper operation. So crisis managers<br />
may not have the time or training needed to use them effectively. In this case, multimodal interfaces<br />
can be more intuitive than conventional interfaces.<br />
By coupling the visually expressive nature <strong>of</strong> maps with multimodal interfaces, it will expand the<br />
range <strong>of</strong> possible users to include non-GIS specialists as inexperienced users can mostly interact with a<br />
map and express commands multimodally when describing spatial in<strong>for</strong>mation about location, number,<br />
size and orientation or shape <strong>of</strong> an object. What remains to be determined is which combination <strong>of</strong><br />
modes that will create more intuitive interfaces to maps and GIS.<br />
In Human-Computer Interaction (HCI), speech and gesture are the most natural means <strong>of</strong> humanhuman<br />
interaction. <strong>The</strong> Geo-Collaboration Crisis Management (GCCM) project is presently developing<br />
a Dialogue Assisted Visual Environment <strong>for</strong> Geo in<strong>for</strong>mation (DAVE_G) [21] that uses a combination<br />
<strong>of</strong> speech and gesture as inputs. <strong>The</strong> key functionality <strong>of</strong> DAVE_G is its ability to coordinate<br />
a collaborative dialogue between itself and users. For example, a user can say "DAVE", zoom to this<br />
area ? and makes a circular gesture around a desired area. DAVE_G gives the answer back with<br />
text, speech response and image display. In the future, it is being extended to become a tool <strong>for</strong> use<br />
in emergency response centers.<br />
84
Bibliography<br />
[1] Christine Parent, Stefano Spaccapietra, Esteban Zimányi. <strong>The</strong> MurMur project: Modeling and<br />
querying multi-representation spatio-temporal databases. Science direct, 2006.<br />
[2] Alejandro Vaisman, Esteban Zimányi. A multidimensional model representing continuous fields in<br />
spatial data warehouses. Databases and <strong>The</strong>oretical Computer Science. ACM Press, 2009.<br />
[3] Qingyun (Jeffrey) Xie and Jayant Sharma, Jean Ihm. Oracle Database 11g Geo<strong>Raster</strong>: An Oracle<br />
Technical White Paper, June 2007.<br />
[4] Qingyun (Jeffrey) Chuck Murray, Qingyun (Jeffrey) Xie, Weisheng (Terry) Xu, Sophia Yuditskaya,<br />
Zhihai Zhang, Hongwei Zhu. Oracle Spatial Geo<strong>Raster</strong> Developer?s Guide, 11g Release 1 (11.1):<br />
Geo<strong>Raster</strong> Overview and Concepts. August 2008.<br />
[5] Sandro Bimonte. Intégration de l’in<strong>for</strong>mation géographique dans les entrepôts de données et<br />
l’analyse en ligne : de la modélisation à la visualisation. University thesis. In<strong>for</strong>matique et In<strong>for</strong>mation<br />
pour la Société - L?Institut National des Sciences Appliquées de Lyon. 207 pages, 18<br />
Decembre 2007.<br />
[6] Pierre Racine , Bborie Park, Sandro Santilli, Mateusz Loskot, Jorge Arevalo, Regina Obe,<br />
David Zwarg. <strong>PostGIS</strong> <strong>Raster</strong> Beta Documentation. http://trac.osgeo.org/postgis/wiki/<br />
WKT<strong>Raster</strong>/Documentation01. Last updated: 2012-03-10.<br />
[7] Robert J. Hijmans, Susan Cameron, Juan Parra, Peter Jones, Andrew Jarvis, Karen Richardson.<br />
WorldClim: Global Climate Data, 2005. http://www.worldclim.org/<strong>for</strong>mats.<br />
[8] Pierre Racine. <strong>PostGIS</strong> WKT <strong>Raster</strong> Tutorial 1: Intersecting vector polygons with large<br />
raster coverage using <strong>PostGIS</strong> WKT <strong>Raster</strong>. 2005. http://trac.osgeo.org/postgis/wiki/<br />
WKT<strong>Raster</strong>Tutorial01. Last updated: 2011-06-20.<br />
[9] Jay Busselle. Computer Technology: <strong>Raster</strong> Images versus Vector Images. http://www.<br />
signindustry.com/computers/articles/2004-11-30-DASvector_v_raster.php3<br />
[10] Gary Sherman. Spatial Galaxy: Exploring the depths <strong>of</strong> open source GIS and more. Using<br />
the QGIS <strong>Raster</strong> Calculator, 25 January 2012. http://spatialgalaxy.net/2012/01/25/<br />
using-the-qgis-raster-calculator/.<br />
[11] Environmental Systems Research Institute. ArcGIS Desktop Help 9.3: Cell size <strong>of</strong> raster<br />
data. http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Cell_size_<strong>of</strong>_<br />
raster_data. Last undated: 2009-11-12.<br />
[12] Martin Dobias. PyQGIS Developer Cookbook: Developing Python Plugins. http://qgis.org/<br />
pyqgis-cookbook/plugins.html. Last undated: 2012-07-03.<br />
[13] <strong>The</strong> <strong>PostgreSQL</strong> Global Development Group. <strong>PostgreSQL</strong> 8.1.11 Documentation: Create aggregate,<br />
pages: 787-789.<br />
[14] Jorge Arevalo. <strong>PostGIS</strong> <strong>Raster</strong> Tutorial Series. Comparing Oracle Geo<strong>Raster</strong> with <strong>PostGIS</strong><br />
WKT <strong>Raster</strong> (I). http://gis4free.wordpress.com/2010/07/19/oracle-georaster-part-i/.<br />
Last undated: 2010-08-08.<br />
85
[15] Jorge Arevalo. <strong>PostGIS</strong> <strong>Raster</strong> Tutorial Series. Comparing Oracle Geo<strong>Raster</strong> with <strong>PostGIS</strong> WKT<br />
<strong>Raster</strong> (II). http://gis4free.wordpress.com/2010/09/01/oracle-georaster-part-ii/. Last<br />
undated: 2010-09-01.<br />
[16] Environmental Systems Research Institute. ArcGIS Desktop Help 9.3: What is raster data<br />
?. http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=What_is_raster_<br />
data?. Last undated: 2009-11-12.<br />
[17] Project Steering Committee, Refractions Research. <strong>PostGIS</strong> 2.1.0 SVN Manual: <strong>Raster</strong> Reference,<br />
pages 359-467, 22 june 2012.<br />
[18] Wikipedia Foundation. Crime mapping. http://en.wikipedia.org/wiki/Crime_mapping. Last<br />
undated: 2012-06-27 21:58.<br />
[19] Rediscovering Geography Committee Board on Earth Sciences and Resources Commission on<br />
Geosciences, Environment and Resources National Research Council. Rediscovering Geography:<br />
New Relevance <strong>for</strong> Science and Society. Geography’s Contributions to Decision Making. National<br />
Academies Press Washington, D.C.,ISBN: 0-309-57762-4, 248 pages, 1997.<br />
[20] CartoExpert.com. Cartographie Analyse Spatiale Géomatique SIG. Pourquoi utiliser QGIS ?.<br />
http://www.cartoexpert.com/index.php/fr/<strong>for</strong>mations/90-pourquoi-quantum-gis.html.<br />
[21] Adrian Cox. Undergraduate Texts in Geography. Multimodal GIS Interfaces in Crisis Management<br />
- Usability Study. <strong>The</strong> Pennsylvania State University, March 2005.<br />
[22] Pierre Racine. <strong>PostGIS</strong> WKT <strong>Raster</strong>: Seamless operations between vector and raster layers. BAM<br />
project, University Laval, July 2008.<br />
[23] Pierre Racine, Steve Cumming. Store, manipulate and analyze raster data within the <strong>PostgreSQL</strong>/<strong>PostGIS</strong><br />
spatial database. FOSS4G 2011 Conference, Denver, Colorado, USA, 12-16<br />
September 2011.<br />
[24] Regina Obe, Leo Hsu. <strong>PostGIS</strong> 2.0 3D and <strong>Raster</strong> support enhancements. North Carolina GIS<br />
Conference, 2011 (NCGIS 2011).<br />
[25] Doxygen v1.7.1. GDAL Utilities. http://www.gdal.org/gdal_utilities.html. Last updated:<br />
2012-01-07 12:57:28Z.<br />
[26] Environmental Systems Research Institute. ArcGIS Desktop Help 9.3: Georeferencing: Assigning<br />
map coordinates and spatial location. http://webhelp.esri.com/arcgisdesktop/9.3/index.<br />
cfm?TopicName=Georeferencing_and_coordinate_systems. Last updated: 2009-01-20.<br />
[27] Environmental Systems Research Institute. ArcGIS Desktop Help 9.3: Elements <strong>of</strong> geographic in<strong>for</strong>mation.<br />
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Elements_<br />
<strong>of</strong>_geographic_in<strong>for</strong>mation. Last undated: 2009-01-20.<br />
[28] Wikipedia Foundation. <strong>Raster</strong> graphics. http://en.wikipedia.org/wiki/<strong>Raster</strong>_graphics.<br />
Last undated: 2012-07-15 04:26.<br />
[29] Wikipedia Foundation. Vector graphics. http://en.wikipedia.org/wiki/Vector_image. Last<br />
undated: 2012-07-18 04:07.<br />
[30] Environmental Systems Research Institute. ArcGIS Desktop Help 9.3: How GIS represents<br />
and organizes geographic in<strong>for</strong>mation. http://webhelp.esri.com/arcgisdesktop/9.3/<br />
index.cfm?TopicName=How_GIS_represents_and_organizes_geographic_in<strong>for</strong>mation. Last<br />
undated: 2009-01-20.<br />
[31] Wikipedia Foundation. GIS and hydrology. http://en.wikipedia.org/wiki/GIS_and_<br />
Hydrology. Last undated: 2012-06-20 01:27.<br />
86
[32] Environmental Systems Research Institute. ArcGIS Desktop Help 9.3: <strong>Raster</strong> dataset zones<br />
and regions. http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=<strong>Raster</strong>_<br />
dataset_zones_and_regions. Last undated: 2009-11-12.<br />
[33] Environmental Systems Research Institute. ArcGIS Desktop Help 9.3: Discrete and continuous<br />
data. http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Discrete_<br />
and_continuous_data. Last undated: 2009-11-12.<br />
[34] Environmental Systems Research Institute. ArcGIS Desktop Help 9.3: Representing<br />
features in a raster dataset. http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?<br />
TopicName=Representing_features_in_a_raster_dataset. Last undated: 2009-11-12.<br />
[35] Environmental Systems Research Institute. ArcGIS Desktop Help 9.3: <strong>Raster</strong> bands. http://<br />
webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=<strong>Raster</strong>_bands. Last undated:<br />
2009-11-12.<br />
[36] Environmental Systems Research Institute. ArcGIS Desktop Help 9.3: <strong>Raster</strong> pyramids.<br />
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=<strong>Raster</strong>_pyramids.<br />
Last undated: 2009-11-12.<br />
[37] Wikipedia Foundation. Remote sensing. http://en.wikipedia.org/wiki/Remote_sensing.<br />
Last updated: 2012-07-20 11:16.<br />
[38] Wikipedia Foundation. Cartography. http://en.wikipedia.org/wiki/Cartography. Last updated:<br />
2012-07-12 19:45.<br />
[39] Wikipedia Foundation. Geology. http://en.wikipedia.org/wiki/Geology. Last updated:<br />
2012-07-26 06:42.<br />
[40] Wikipedia Foundation. Geophysics. http://en.wikipedia.org/wiki/Geophysics. Last updated:<br />
2012-06-15 14:38.<br />
87
Appendix A<br />
<strong>PostGIS</strong> <strong>Raster</strong> Utilisation<br />
A.1 Dependencies Installation<br />
– PostgeSQL version 7.2 or higher.<br />
– <strong>PostGIS</strong> version 1.3.5 or higher.<br />
Other necessary component is GDAL as <strong>PostGIS</strong> <strong>Raster</strong> uses GDAL to driver <strong>for</strong> images conversion,<br />
trans<strong>for</strong>mation, reprojection and connecting to raster files and Python loader:<br />
– Python version 2.5 or higher.<br />
– GDAL <strong>for</strong> Python version 1.6 or higher.<br />
– GDAL <strong>PostGIS</strong> <strong>Raster</strong> Driver.<br />
A.2 Installing and Configuring<br />
A.2.1 Linux<br />
<strong>PostGIS</strong> <strong>Raster</strong> is an extension <strong>of</strong> <strong>PostGIS</strong> and need to be installed separately. <strong>The</strong> last version <strong>of</strong><br />
<strong>PostGIS</strong> <strong>Raster</strong> can be downloaded here.<br />
<strong>The</strong> next step is to configure <strong>PostGIS</strong> <strong>Raster</strong> by the following commands:<br />
./configure --with-raster<br />
make<br />
sudo make install<br />
A.2.2 Windows<br />
Instructions can be found on this Web site. <strong>The</strong> option ’–with-raster’ should be added when<br />
invoking configure scripts.<br />
<strong>The</strong> full instructions about how to install and configure <strong>PostGIS</strong> <strong>Raster</strong> on Windows is available<br />
here.<br />
A.3 Creating Database<br />
<strong>The</strong> following code will create a new <strong>PostGIS</strong> <strong>Raster</strong> database in <strong>PostgreSQL</strong>:<br />
createdb <br />
createlang plpgsql <br />
psql -U -f postgis/postgis.sql -d <br />
psql -U -f spatial_ref\_sys.sql -d <br />
psql -U -f raster/rt_pg/rtpostgis.sql -d <br />
88
Appendix B<br />
Python Plugin in QGIS<br />
B.1 Necessary Files<br />
<strong>The</strong> directory structure <strong>of</strong> a plugin is as follows:<br />
PYTHON_PLUGINS_PATH/<br />
testplug/<br />
__init__.py<br />
plugin.py<br />
metadata.txt<br />
resources.qrc<br />
resources.py<br />
<strong>for</strong>m.ui<br />
<strong>for</strong>m.py<br />
Where:<br />
__init__.py: contains some basic in<strong>for</strong>mation about the plugin such as its name, version and<br />
main class.<br />
plugin.py: plugin body that contains main code <strong>for</strong> all the actions describing the plugin.<br />
metadata.txt: Required <strong>for</strong> QGIS >= 1.8.0. Contains general in<strong>for</strong>mation, version, name and<br />
some other metadata used by plugins website and plugin infrastructure. Metadata in metadata.txt is<br />
preferred to the methods in __init__.py. From QGIS 2.0 the metadata from __init__.py will not<br />
be accepted and the metadata.txt file will be required.<br />
resources.qrc: a .xml document containing relative paths to resources <strong>of</strong> the <strong>for</strong>ms.<br />
resources.py: <strong>The</strong> translation <strong>of</strong> the resources.qrc file to Python.<br />
<strong>for</strong>m.ui: a <strong>for</strong>m in QT-Designer with its resources.qrc.<br />
<strong>for</strong>m.py: <strong>The</strong> translation <strong>of</strong> the <strong>for</strong>m.ui file to Python.<br />
<strong>The</strong>re are also two automated ways <strong>of</strong> creating the basic files (or skeleton) <strong>of</strong> a typical QGIS Python<br />
plugin: the first one using a QGIS Plugin Builder and the second one come from a web application.<br />
B.2 Python Code<br />
B.2.1 __init__.py<br />
def name():<br />
return "My testing plugin"<br />
def description():<br />
return "This plugin has no real use."<br />
def version():<br />
89
eturn "Version 0.1"<br />
def qgisMinimumVersion():<br />
return "1.0"<br />
def authorName():<br />
return "Developer"<br />
def classFactory(iface):<br />
# Load TestPlugin class from file testplugin.py<br />
from testplugin import TestPlugin<br />
return TestPlugin(iface)<br />
<strong>The</strong> classFactory() function is called when the plugin is loaded into QGIS. It receives reference<br />
to instance <strong>of</strong> QgisInterface and return instance <strong>of</strong> TestPlugin plugin (the TestPlugin class will be<br />
described later in plugin.py file).<br />
def category():<br />
return "<strong>Raster</strong>"<br />
Normally, user-created plugins are placed into Plugins menu but from QGIS 1.9.90, they can also<br />
be placed into Vector, <strong>Raster</strong>, Database or Web menus using category entry. For example, the above<br />
plugin will be available from <strong>Raster</strong> menus.<br />
B.2.2 Plugin.py<br />
from PyQt4.QtCore import *<br />
from PyQt4.QtGui import *<br />
from qgis.core import *<br />
# initialize Qt resources from file resouces.py<br />
import resources<br />
class TestPlugin:<br />
def __init__(self, iface):<br />
# Save reference to the QGIS interface<br />
self.iface = iface<br />
def initGui(self):<br />
# Create action that triggers plugin<br />
self.action = QAction(QIcon(":/plugins/testplug/icon.png"), "Test plugin", self.iface.ma<br />
# Code in function run will be executed<br />
QObject.connect(self.action, SIGNAL("triggered()"), self.run)<br />
# Check if <strong>Raster</strong> menu available<br />
if hasattr(self.iface, "addPluginTo<strong>Raster</strong>Menu"):<br />
# <strong>Raster</strong> menu and toolbar available<br />
# Add action to toolbar and menu item<br />
self.iface.add<strong>Raster</strong>ToolBarIcon(self.action)<br />
self.iface.addPluginTo<strong>Raster</strong>Menu("\&Test plugins", self.action)<br />
else:<br />
# <strong>The</strong>re is no <strong>Raster</strong> menu, place plugin under Plugins menu as usual<br />
self.iface.addToolBarIcon(self.action)<br />
self.iface.addPluginToMenu("\&Test plugins", self.action)<br />
def unload(self):<br />
# Check if <strong>Raster</strong> menu available<br />
90
if hasattr(self.iface, "addPluginTo<strong>Raster</strong>Menu"):<br />
# Remove action from <strong>Raster</strong> toolbar and menu<br />
self.iface.removePlugin<strong>Raster</strong>Menu("\&Test plugins",self.action)<br />
self.iface.remove<strong>Raster</strong>ToolBarIcon(self.action)<br />
else:<br />
# Remove the Plugin menu and toolbar<br />
self.iface.removePluginMenu("\&Test plugins",self.action)<br />
self.iface.removeToolBarIcon(self.action)\\<br />
def run(self):<br />
# Main code <strong>for</strong> all the actions describing the plugin<br />
print "TestPlugin: run called!"<br />
<strong>The</strong> functions that must exist are initGui() and unload(). <strong>The</strong>se functions are called when the<br />
plugin is loaded and unloaded.<br />
B.2.3 Resources.qrc<br />
In initGui(), an icon icon.png from resource file resources.qrc is used. <strong>The</strong> structure <strong>of</strong> this<br />
file is as follows:<br />
<br />
<br />
icon.png<br />
<br />
<br />
<strong>The</strong> pyrcc4 command will generate a Python file that will contain the resources:<br />
pyrcc4 -o resources.py resources.qrc<br />
91
Appendix C<br />
Code Implementation<br />
C.1 Temporal <strong>Raster</strong> Functions<br />
<strong>PostgreSQL</strong> allows also abilities <strong>for</strong> users to define new types and their own functions. <strong>The</strong>n<br />
CREATE AGGREGATE can be used to provide the desired features that are not provided by <strong>PostgreSQL</strong>.<br />
An aggregate function is identified by its name and input data type. An aggregate function is made<br />
from one or two ordinary functions: a state transition function sfunc and an optional final calculation<br />
function ffunc.<br />
An temporary variable <strong>of</strong> type stype is used to hold the current value <strong>of</strong> the state transition<br />
function. At each input data item, the state transition function is invoked to calculate a new state<br />
value. After all the data has been processed, the final function is invoked once to calculate the<br />
aggregate result. If there is no final function then the aggregate returns the current state value as<br />
final result. sum is an example <strong>of</strong> this kind <strong>of</strong> aggregate, where <strong>for</strong> each input, sum adds its value to<br />
current state value and returns the sum <strong>of</strong> all input value as final result.<br />
A final function is specified in the case where the final result is different from the input data type.<br />
Average aggregate function is an example <strong>of</strong> this case and will be examined thereafter. If the final<br />
function is declared "strict", then it will not be called when the current state value is null. Instead a<br />
null result will be returned automatically.<br />
Example <strong>of</strong> creating the aggregate function ST_Avg:<br />
CREATE AGGREGATE ST_Avg(st_rastertemp) (<br />
SFUNC=array_append,<br />
STYPE=st_rastertemp[],<br />
FINALFUNC=ST_AvgTemp<strong>Raster</strong><br />
);<br />
CREATE OR REPLACE FUNCTION ST_AvgTemp<strong>Raster</strong>(arrayRastTemp st_rastertemp[])<br />
RETURNS raster AS<br />
$$<br />
DECLARE<br />
newraster raster;<br />
oldRast1 raster;<br />
oldRast2 raster;<br />
width int;<br />
height int;<br />
cx int;<br />
cy int;<br />
size int;<br />
s int;<br />
value double precision = 0;<br />
intType boolean = true;<br />
92
BEGIN<br />
newraster := arrayRastTemp[1].rast;<br />
width := ST_Width(newraster);<br />
height := ST_Height(newraster);<br />
size := array_upper(arrayRastTemp,1);<br />
-- Determine pixel type <strong>of</strong> temporal rasters<br />
IF ST_BandPixelType(newraster) = ’32BF’ OR ST_BandPixelType(newraster) = ’64BF’<br />
THEN intType = false;<br />
END IF;<br />
-- Check if all temporal rasters have same dimensions<br />
IF ST_Width(oldRast1) != ST_Width(oldRast2) OR ST_Width(oldRast1) != ST_Width(oldRast2)<br />
THEN<br />
-- If not then the function raises error<br />
RAISE EXCEPTION ’ST_Sum<strong>Raster</strong>: Attempting to sum a band with different width or height<br />
END IF;<br />
FOR cx IN 1..width LOOP<br />
FOR cy IN 1..height LOOP<br />
FOR s IN 1.. size LOOP<br />
value := value + ST_Value(arrayRastTemp[s].rast,cx,cy);<br />
END LOOP;<br />
value = value/size;<br />
-- Cast the result to an appropriate type<br />
IF intType = true<br />
THEN newraster := ST_SetValue(newraster,cx,cy,value::int);<br />
ELSE newraster := ST_SetValue(newraster,cx,cy,value);<br />
END IF;<br />
value := 0;<br />
END LOOP;<br />
END LOOP;<br />
RETURN newraster;<br />
END;<br />
$$<br />
LANGUAGE ’plpgsql’ IMMUTABLE STRICT;<br />
C.2 Temporal <strong>Raster</strong> Application<br />
Python code <strong>for</strong> loading layers into QGIS:<br />
def iniLayers(self):<br />
# Retrieve a connection string<br />
connstring=str(conn.getConnString(self,self.connection))<br />
# Retrieve a list <strong>of</strong> layer IDs<br />
rids=conn.listRIDs(self, connstring, str(self.table))<br />
# Change QGIS cursor to <strong>PostgreSQL</strong> cursor<br />
QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))\\<br />
<strong>for</strong> rid in rids:<br />
# Split table name from schema<br />
connstring = str(conn.getConnString(self,self.connection))<br />
table=str(self.table).split(".")<br />
93
name=""<br />
# Setting table name and mode<br />
if len(table)>1:<br />
# Checking if there is schema in the table name<br />
name+=str(table[0])<br />
connstring+=" schema="+str(table[0])<br />
connstring+=’ table=’+str(table[-1])<br />
name+="."+str(table[-1])<br />
# Query <strong>for</strong> row mode<br />
connstring+=’ mode=1 where=\’rid=’ + str(rid) + ’\’’<br />
# Object rlayer will contain loaded layer<br />
rlayer=None<br />
# Retrieve a layer from <strong>PostgreSQL</strong> using the connection string<br />
rlayer = Qgs<strong>Raster</strong>Layer(connstring, name)<br />
# Try to add layer to qgis.<br />
if rlayer:<br />
if rlayer.isValid():<br />
status = QgsMapLayerRegistry.instance().addMapLayer(rlayer)<br />
self.legend.setLayerVisible(rlayer,False)<br />
# Each layer is identified by an unique layer id<br />
self.layerIds.append(rlayer.id())<br />
else:<br />
QtGui.QMessageBox.warning(self,"Error", "Could not load "+connstring)<br />
# Come back to QGIS cursor<br />
QtGui.QApplication.restoreOverrideCursor()<br />
94
Appendix D<br />
<strong>Raster</strong> Sources<br />
<strong>Raster</strong> data is collected and used by a variety <strong>of</strong> geographic in<strong>for</strong>mation technologies, including<br />
remote sensing, airborne photogrammetry, cartography, and global positioning systems. <strong>The</strong> collected<br />
data is then analyzed by digital image processing systems, computer graphics applications, and computer<br />
vision technologies. <strong>The</strong>se technologies use several data <strong>for</strong>mats and create a variety <strong>of</strong> products.<br />
This section briefly describes some <strong>of</strong> the main raster data sources and their applications.<br />
D.1 Remote Sensing<br />
D.1.1 Introduction<br />
Remote sensing obtains in<strong>for</strong>mation about an area or object through a device that is not physically<br />
connected to the area or object. For example, the sensor might be in a satellite, balloon, airplane,<br />
boat, or ground station.<br />
<strong>The</strong>re are two main types <strong>of</strong> remote sensing: passive remote sensing and active remote sensing.<br />
Passive sensors detect natural radiation that is emitted or reflected by the object or surrounding areas.<br />
Reflected sunlight is the most common source <strong>of</strong> radiation measured by passive sensors. Examples<br />
<strong>of</strong> passive remote sensors include film photography, infrared,charge-coupled devices, and radiometers.<br />
Active collection, on the other hand, emits energy in order to scan objects and areas whereupon a<br />
sensor then detects and measures the radiation that is reflected or backscattered from the target.<br />
RADAR and LiDAR are examples <strong>of</strong> active remote sensing where the time delay between emission<br />
and return is measured, establishing the location, height, speed and direction <strong>of</strong> an object.<br />
D.1.2 Applications<br />
Remote sensing applications include environmental assessment and monitoring, global change<br />
detection and monitoring, and natural resource surveying.<br />
Remote sensing makes it possible to collect data on dangerous or inaccessible areas. Remote sensing<br />
applications include monitoring de<strong>for</strong>estation in areas such as the Amazon Basin, glacial features in<br />
Arctic and Antarctic regions, and depth sounding <strong>of</strong> coastal and ocean depths. Military collection<br />
during the Cold War made use <strong>of</strong> stand<strong>of</strong>f collection <strong>of</strong> data about dangerous border areas. Remote<br />
sensing also replaces costly and slow data collection on the ground, ensuring in the process that areas<br />
or objects are not disturbed.<br />
Orbital plat<strong>for</strong>ms collect and transmit data from different parts <strong>of</strong> the electromagnetic spectrum,<br />
which in conjunction with larger scale aerial or ground-based sensing and analysis, provides researchers<br />
with enough in<strong>for</strong>mation to monitor trends such as El Niño and other natural long and short term<br />
phenomena. Other uses include different areas <strong>of</strong> the earth sciences such as natural resource management,<br />
agricultural fields such as land usage and conservation, and national security and overhead,<br />
ground-based and stand-<strong>of</strong>f collection on border areas.<br />
By satellite, aircraft, spacecraft, buoy, ship, and helicopter images, data is created to analyze and<br />
compare things like vegetation rates, erosion, pollution, <strong>for</strong>estry, weather, and land use. <strong>The</strong>se things<br />
95
Figure D.1: Synthetic aperture radar image <strong>of</strong> Death Valley [37].<br />
can be mapped, imaged, tracked and observed. <strong>The</strong> process <strong>of</strong> remote sensing is also helpful <strong>for</strong> city<br />
planning, archaeological investigations, military observation and geomorphological surveying.<br />
<strong>The</strong> data collected by remote sensing is <strong>of</strong>ten called geo imagery. <strong>The</strong> wavelength, number <strong>of</strong><br />
bands, and other factors determine the radiometric characteristics <strong>of</strong> the geo images. <strong>The</strong> geo images<br />
can be single-band, multiband, or hyperspectral, all <strong>of</strong> which can be managed by <strong>PostGIS</strong> <strong>Raster</strong>.<br />
<strong>The</strong>se geo images can cover any area <strong>of</strong> the Earth (especially <strong>for</strong> images sensed by satellite).<br />
Generally, remote sensing works on the principle <strong>of</strong> the inverse problem. While the object or<br />
phenomenon <strong>of</strong> interest (the state) may not be directly measured, there exists some other variable<br />
that can be detected and measured (the observation), which may be related to the object <strong>of</strong> interest<br />
through the use <strong>of</strong> a data-derived computer model. <strong>The</strong> common analogy given to describe this<br />
is trying to determine the type <strong>of</strong> animal from its footprints. For example, while it is impossible to<br />
directly measure temperatures in the upper atmosphere, it is possible to measure the spectral emissions<br />
from a known chemical species (such as carbon dioxide) in that region. <strong>The</strong> frequency <strong>of</strong> the emission<br />
may then be related to the temperature in that region via various thermodynamic relations.<br />
<strong>The</strong> quality <strong>of</strong> remote sensing data consists <strong>of</strong> its spatial, spectral, radiometric and temporal<br />
resolutions. <strong>The</strong> temporal resolution can be high, such as with meteorological satellites, making<br />
it easier to detect changes. For remote sensing applications, various types <strong>of</strong> resolution (temporal,<br />
spatial, spectral, and radiometric) are <strong>of</strong>ten important.<br />
D.2 Photogrammetry<br />
D.2.1 Introduction<br />
Photogrammetry is used to determine the geometric properties <strong>of</strong> objects from measurements<br />
made on photographic images. In the simplest example, the distance between two points that lie on<br />
a plane parallel to the photographic image plane can be determined by measuring their distance on<br />
the image, if the scale (s) <strong>of</strong> the image is known. This is done by multiplying the measured distance<br />
by 1/s. Most photogrammetry applications use airborne photos or high-resolution images collected by<br />
satellite remote sensing. In traditional photogrammetry, the main data includes images such as black<br />
and white photographs, color photographs, and stereo photograph pairs.<br />
Photogrammetry rigorously establishes the geometric relationship between the image and the object<br />
as it existed at the time <strong>of</strong> the imaging event, and enables you to derive in<strong>for</strong>mation about the<br />
object from its imagery. <strong>The</strong> relationship between image and object can be established by several<br />
96
means, which can be grouped in two categories: analog (using optical, mechanical, and electronic<br />
components) or analytical (where the modeling is mathematical and the processing is digital). Analog<br />
solutions are increasingly being replaced by analytical/digital solutions, which are also referred to as<br />
s<strong>of</strong>tcopy photogrammetry.<br />
<strong>The</strong> main product from a s<strong>of</strong>tcopy photogrammetry system may include digital elevation models<br />
(DEMs) and orthoimagery. Geo<strong>Raster</strong> can manage all this raster data, together with its georeferencing<br />
in<strong>for</strong>mation.<br />
D.2.2 Application<br />
Photogrammetry is used in different fields, such as topographic mapping, architecture, engineering,<br />
manufacturing, quality control, policeinvestigation, and geology, as well as by archaeologists to quickly<br />
produce plans <strong>of</strong> large or complex sites and by meteorologists as a way to determine the actual wind<br />
speed <strong>of</strong> a tornado where objective weather data cannot be obtained. It is also used to combine live<br />
action with computer-generated imagery in movie post-production; <strong>The</strong> Matrix is a good example <strong>of</strong><br />
the use <strong>of</strong> photogrammetry in film (details are given in the DVD extras).<br />
This method is commonly employed in collision engineering, especially with automobiles. When<br />
litigation <strong>for</strong> accidents occurs and engineers need to determine the exact de<strong>for</strong>mation present in the<br />
vehicle, it is common <strong>for</strong> several years to have passed and the only evidence that remains is crime<br />
scene photographs taken by the police. Photogrammetry is used to determine how much the car in<br />
question was de<strong>for</strong>med, which relates to the amount <strong>of</strong> energy required to produce that de<strong>for</strong>mation.<br />
<strong>The</strong> energy can then be used to determine important in<strong>for</strong>mation about the crash (such as the velocity<br />
at time <strong>of</strong> impact)<br />
D.3 Cartography<br />
Cartography is the science <strong>of</strong> creating maps, which are two-dimensional representations <strong>of</strong> the<br />
three-dimensional Earth (or <strong>of</strong> a non-Earth space using a local coordinate system).<br />
Advances in electronic technology in the 20th century ushered in another revolution in cartography.<br />
Ready availability <strong>of</strong> computers and peripherals such as monitors, plotters, printers, scanners (remote<br />
and document) and analytic stereo plotters, along with computer programs <strong>for</strong> visualization, image<br />
processing, spatial analysis, and database management, have democratized and greatly expanded the<br />
making <strong>of</strong> maps. <strong>The</strong> ability to superimpose spatially located variables onto existing maps created<br />
new uses <strong>for</strong> maps and new industries to explore and exploit these potentials. See also: digital raster<br />
graphic.<br />
<strong>The</strong>se days most commercial-quality maps are made using s<strong>of</strong>tware that falls into one <strong>of</strong> three<br />
main types: CAD, GIS and specialized illustration s<strong>of</strong>tware. Spatial in<strong>for</strong>mation can be stored in<br />
a database, from which it can be extracted on demand. <strong>The</strong>se tools lead to increasingly dynamic,<br />
interactive maps that can be manipulated digitally.<br />
With the field rugged computers, GPS and laser rangefinders, it is possible to per<strong>for</strong>m mapping<br />
directly in the terrain. Construction <strong>of</strong> a map in real time, <strong>for</strong> example by using Field-Map technology,<br />
improves productivity and quality <strong>of</strong> the result.<br />
Today, maps are digitized or scanned into digital <strong>for</strong>ms, and map production is largely automated.<br />
Maps stored on a computer can be queried, analyzed, and updated quickly.<br />
<strong>The</strong>re are many types <strong>of</strong> maps, corresponding to a variety <strong>of</strong> uses or purposes. Examples <strong>of</strong> map<br />
types include base (background), thematic, relief (three-dimensional), aspect, cadastral (land use),<br />
and inset. Maps usually contain several annotation elements to help explain the map, such as scale<br />
bars, legends, symbols (such as the north arrow), and labels (names <strong>of</strong> cities, rivers, and so on). Maps<br />
can be stored in raster <strong>for</strong>mat (and thus can be managed by GIS), in vector <strong>for</strong>mat or in a hybrid<br />
<strong>for</strong>mat.<br />
97
D.4 Digital Image Processing<br />
D.4.1 Introduction<br />
Figure D.2: Relief map Sierra Nevada (Spain) [38].<br />
Digital image processing is used to process raster data in standard image <strong>for</strong>mats, such as TIFF,<br />
GIF, JFIF (JPEG), and Sun <strong>Raster</strong>, as well as in many geo image <strong>for</strong>mats, such as NITF, GeoTIFF,<br />
ERDAS IMG, and PCI PIX. Image processing techniques are widely used in remote sensing and<br />
photogrammetry applications. <strong>The</strong>se techniques are used as needed to enhance, correct, and restore<br />
images to facilitate interpretation; to correct <strong>for</strong> any blurring, distortion, or other degradation that may<br />
have occurred; and to classify geo-objects automatically and identify targets. <strong>The</strong> source, intermediate,<br />
and result imagery can be loaded and managed by Geo<strong>Raster</strong>.<br />
Digital image processing is the use <strong>of</strong> computer algorithms to per<strong>for</strong>m image processing on digital<br />
images. As a subcategory or field <strong>of</strong> digital signal processing, digital image processing has many<br />
advantages over analog image processing. It allows a much wider range <strong>of</strong> algorithms to be applied<br />
to the input data and can avoid problems such as the buildup <strong>of</strong> noise and signal distortion during<br />
processing. Since images are defined over two dimensions (perhaps more) digital image processing<br />
may be modeled in the <strong>for</strong>m <strong>of</strong> multidimensional systems. A digital image processing allows the use<br />
<strong>of</strong> much more complex algorithms <strong>for</strong> image processing, and hence, can <strong>of</strong>fer both more sophisticated<br />
per<strong>for</strong>mance at simple tasks, and the implementation <strong>of</strong> methods which would be impossible by analog<br />
means. application.<br />
D.4.2 Digital Camera Images<br />
Digital cameras generally include dedicated digital image processing chips to convert the raw data<br />
from the image sensor into a colour-corrected image in a standard image file <strong>for</strong>mat. Images from<br />
digital cameras <strong>of</strong>ten receive further processing to improve their quality, a distinct advantage that<br />
digital cameras have over film cameras. <strong>The</strong> digital image processing typically is executed by special<br />
s<strong>of</strong>tware programs that can manipulate the images in many ways. Many digital cameras also enable<br />
viewing <strong>of</strong> histograms <strong>of</strong> images, as an aid <strong>for</strong> the photographer to understand the rendered brightness<br />
range <strong>of</strong> each shot more readily.<br />
D.5 Geology, Geophysics and Geochemistry<br />
Geology, geophysics, and geochemistry all use digital data and produce some digital raster maps<br />
that can be managed by Geo<strong>Raster</strong>.<br />
• In geology, the data includes regional geological maps, stratum maps, and rock slide pictures. In<br />
98
geological exploration and petroleum geology, computerized geo stratum simulation, synthetic<br />
mineral prediction, and 3-D oil field characterization, all <strong>of</strong> which involve raster data, are widely<br />
used.<br />
Geologists use a number <strong>of</strong> field, laboratory, and numerical modeling methods to decipher Earth<br />
history and understand the processes that occur on and in the Earth. In typical geological<br />
investigations, geologists use primary in<strong>for</strong>mation related to petrology (the study <strong>of</strong> rocks),<br />
stratigraphy (the study <strong>of</strong> sedimentary layers), and structural geology (the study <strong>of</strong> positions<br />
<strong>of</strong> rock units and their de<strong>for</strong>mation). In many cases, geologists also study modern soils, rivers,<br />
landscapes, and glaciers; investigate past and current life and biogeochemical pathways, and use<br />
geophysical methods to investigate the subsurface.<br />
In modern times, geology is commercially important <strong>for</strong> mineral and hydrocarbon exploration<br />
and <strong>for</strong> evaluating water resources; is publicly important <strong>for</strong> the prediction and understanding<br />
<strong>of</strong> natural hazards, the remediation <strong>of</strong> environmental problems, and <strong>for</strong> providing insights into<br />
past climate change; plays a role in geotechnical engineering; and is a major academic discipline.<br />
Figure D.3: William Smith’s geologic map <strong>of</strong> England,Wales, and southern Scotland. Completed in<br />
1815, it was the first national-scale geologic map and by far the most accurate <strong>of</strong> its time [39].<br />
• In geophysics, data about gravity, heat flow, seismic wave transportation or vibrations, the<br />
magnetic field, and other subjects is saved, along with georeferencing in<strong>for</strong>mation.<br />
Geophysics is applied to societal needs, such as mineral resources, mitigation <strong>of</strong> natural hazards<br />
and environmental protection.Geophysical survey data are used to analyze potential petroleum<br />
reservoirs and mineral deposits, locate groundwater, find archaeological relics, determine the<br />
thickness <strong>of</strong> glaciers and soils, and assess sites <strong>for</strong> environmental remediation.<br />
• In geochemistry, the contents <strong>of</strong> multiple chemical elements can be analyzed and measured. <strong>The</strong><br />
triangulated irregular network (TIN) technique is <strong>of</strong>ten used to produce raster maps <strong>for</strong> further<br />
analysis, and image processing is widely used.<br />
Geochemistry is the science that uses the tools and principles <strong>of</strong> chemistry to explain the mechanisms<br />
behind major geological systems such as the Earth’s crust and its oceans. <strong>The</strong> realm<br />
<strong>of</strong> geochemistry extends beyond the Earth, encompassing the entire solar system and has made<br />
important contributions to the understanding <strong>of</strong> a number <strong>of</strong> processes including mantle convection,<br />
the <strong>for</strong>mation <strong>of</strong> planets and the origins <strong>of</strong> granite and basalt. is the slow creeping<br />
motion <strong>of</strong> Earth’s rocky mantle caused by convectioncurrents carrying heat from the interior <strong>of</strong><br />
the Earth to the surface.<br />
99
Figure D.4: Age <strong>of</strong> the sea floor. Much <strong>of</strong> the dating in<strong>for</strong>mation comes from magnetic anomalies [40].<br />
100
Appendix E<br />
<strong>Raster</strong> Resolution<br />
When working with raster data, there are four types <strong>of</strong> resolution <strong>of</strong>ten encountered: spatial<br />
resolution, spectral resolution, temporal resolution and radiometric resolution.<br />
Spatial resolution refers to the size <strong>of</strong> the smallest object that can be resolved on the ground. In a<br />
digital image, the resolution is limited by the pixel size, i.e. the smallest resolvable object cannot be<br />
smaller than the pixel size.<br />
<strong>The</strong> spatial resolution <strong>of</strong> raster data refers to the cell size. A higher spatial resolution implies that<br />
there are more pixels per unit area. <strong>The</strong>re<strong>for</strong>e, the graphic on the left represents a higher spatial<br />
resolution than the graphic on the right.<br />
Figure E.1: <strong>Raster</strong> data represented at different resolution or cell sizes [11].<br />
Spectral resolution describes the ability <strong>of</strong> a sensor to distinguish different wavelength intervals in<br />
the electromagnetic spectrum. <strong>The</strong> higher the spectral resolution, the narrower the wavelength range<br />
<strong>for</strong> a particular band. For example, a grayscale image (a single band) records wavelength data over<br />
the visible portion <strong>of</strong> the electromagnetic spectrum. However, it has a low spectral resolution. A color<br />
image (with three bands) collects wavelength data from three smaller parts <strong>of</strong> the visible portion <strong>of</strong><br />
the electromagnetic spectrum: the red, green, and blue parts. <strong>The</strong>re<strong>for</strong>e, each band in the color image<br />
has a higher spectral resolution than the single band in the grayscale image. Advanced multispectral<br />
and hyperspectral sensors collect data from up to hundreds <strong>of</strong> spectral bands, resulting a very high<br />
spectral resolution data.<br />
Temporal resolution refers to the frequency with which images can be captured over the same<br />
place on the earth’s surface. It is also known as the revisit period, which is a term most <strong>of</strong>ten used<br />
<strong>for</strong> satellite sensors. <strong>The</strong>re<strong>for</strong>e, a sensor that captures data once every week has a higher temporal<br />
resolution than one that captures data once a month.<br />
Radiometric resolution describes the ability <strong>of</strong> a sensor to distinguish objects viewed in the same<br />
part <strong>of</strong> the electromagnetic spectrum. This is synonymous with the number <strong>of</strong> possible data values<br />
in each band. For example, a Landsat band is typically 8-bit data and an IKONOS band is typically<br />
11-bit data. <strong>The</strong>re<strong>for</strong>e, the IKONOS data has a higher radiometric resolution.<br />
101
Appendix F<br />
Continuous Surfaces<br />
One type <strong>of</strong> continuous surface, that is derived from those characteristics that define a surface, is<br />
a surface where each point in the surface is its measured from a fixed reference point. <strong>The</strong>se include<br />
elevation (the fixed reference point is a sea level and the measure at each point is its height above the<br />
sea level) and aspect (the fixed reference point is one <strong>of</strong> four directions: north, east, south and west<br />
and the measure at each point is the direction <strong>of</strong> a normal at that point).<br />
Figure F.1: Elevation represented in raster <strong>for</strong>mat [33].<br />
Another type <strong>of</strong> continuous surface includes phenomena that progressively vary across a surface<br />
from a source. Examples <strong>of</strong> such phenomena include fluid and air movement. <strong>The</strong>se surfaces are<br />
characterized by the way in which the phenomenon moves. <strong>The</strong> first type <strong>of</strong> movement is through<br />
diffusion in which the phenomenon moves from areas with high concentration to those with less<br />
concentration until the concentration level evens out. Surface characteristics <strong>of</strong> this movement type<br />
include salt concentration moving through the ground or water, contamination moving away from a<br />
hazardous spill or a nuclear reactor and heat from a <strong>for</strong>est fire. In this type <strong>of</strong> continuous surface,<br />
there has to be a source, so-called source-concentration surface. <strong>The</strong> concentration is always greater<br />
near the source and decreases following a function <strong>of</strong> distance and the intermediate substance.<br />
In the source-concentration surface above, the concentration at any position is a function <strong>of</strong> the<br />
capability <strong>of</strong> the phenomenon to move through the environment. Another type <strong>of</strong> concentration surface<br />
is governed by the inherent characteristics <strong>of</strong> the moving phenomenon. For example, the movement <strong>of</strong><br />
the noise from a bomb blast is governed by the inherent characteristics <strong>of</strong> noise and the environment<br />
that it moves through. Mode <strong>of</strong> movement can also limit and directly affect the surface concentration<br />
<strong>of</strong> a feature, as is the case with seed dispersal from a plant. <strong>The</strong> means <strong>of</strong> movement, whether it be<br />
bees, man, wind, or water, all affect the surface concentration <strong>of</strong> seed dispersal <strong>for</strong> the plant. Other<br />
concentration surfaces include dispersal <strong>of</strong> animal populations, potential customers <strong>of</strong> a store (cars<br />
being the means <strong>of</strong> locomotion and time being the limiting factor) and the spreading <strong>of</strong> a disease.<br />
102
Figure F.2: Source-concentration surface represented in raster <strong>for</strong>mat [33].<br />
103