Artifact [87ac30c36b]
Not logged in

Artifact 87ac30c36b3e0f9bf9413356f089bbc6bdb28080:

Wiki page [ETOPO1] by sandro 2014-04-06 22:42:56.
D 2014-04-06T22:42:56.261
L ETOPO1
P 6a5493ef7650c843cea8b78ad233507363996956
U sandro
W 15130
Back to <a href="https://www.gaia-gis.it/fossil/librasterlite2/wiki?name=tutorials">RasterLite2 Tutorials index</a><hr><br>
<h1>Tutorial: adding a styled DEM to the Planet Earth sample</h1>
In this tutorial we'll use the following input Open Data datasource: please download it right now.
<ul>
<li><a href="http://www.ngdc.noaa.gov/mgg/global/relief/ETOPO1/data/ice_surface/cell_registered/georeferenced_tiff/ETOPO1_Ice_c_geotiff.zip">ETOPO1</a>: a raw Global Relief Model released from NOAA.</li>
</ul>
If you remember, you've already used an ETOPO1 datasource in the previous <b><i>Planet Earth</i></b> tutorial; but it was a pre-rendered, full color version.<br>
Now you'll use exactly the same identical dataset, but this time you'll learn how to directly access a <i>raw</i> <a href="http://en.wikipedia.org/wiki/Digital_elevation_model">DEM</a>, and how to apply your own custom styles to it.<br>
You'll possibly use yet again the same <b>earth.sqlite</b> DB-file used in the previous <b><i>Planet Earth</i></b> tutorial, and this will allow you to immediately perceive any relevant difference between these two different approaches.
<h3>Step 1) retrieve all basic informations about the ETOPO1 DEM</h3>
<verbatim>
$ tiffinfo ETOPO1_Ice_c_geotiff.tif
TIFF Directory at offset 0x8 (8)
  Image Width: 21600 Image Length: 10800
  Bits/Sample: 16
  Sample Format: signed integer
  Compression Scheme: None
  Photometric Interpretation: min-is-black
  Samples/Pixel: 1
  Rows/Strip: 1
  Planar Configuration: single image plane
  Tag 33550: 0.016667,0.016667,0.000000
  Tag 33922: 0.000000,0.000000,0.000000,-180.000000,90.000000,0.000000
  Tag 42112: <GDALMetadata>
  <Item name="NC_GLOBAL#Conventions">COARDS/CF-1.0</Item>
  <Item name="NC_GLOBAL#title">ETOPO1_Ice_c_gmt4.grd</Item>
  <Item name="NC_GLOBAL#history">grdsample -V ETOPO1_Ice_g_gmt4.grd -GETOPO1_Ice
_c_gmt4.grd=ni -T</Item>
  <Item name="NC_GLOBAL#GMT_version">4.4.0</Item>
  <Item name="NC_GLOBAL#node_offset">1</Item>
  <Item name="z#long_name">z</Item>
  <Item name="z#_FillValue">-2147483648</Item>
  <Item name="z#actual_range">-10803, 8333</Item>
  <Item name="x#long_name">Longitude</Item>
  <Item name="x#actual_range">-180, 180</Item>
  <Item name="x#units">degrees</Item>
  <Item name="y#long_name">Latitude</Item>
  <Item name="y#actual_range">-90, 90</Item>
  <Item name="y#units">degrees</Item>
  <Item name="NETCDF_VARNAME" sample="0">z</Item>
</GDALMetadata>

  Tag 42113: -2147483648
$
</verbatim>
As reported by the <b><i>tiffinfo</i></b> tool, this TIFF file contains a <b>21,600</b> x <b>10,800</b> raster; the suggested photometric interpretation is <b>Grayscale</b> (<b><i>min-is-black</i></b>), and pixel values are of the <b>INT16</b> type (<b><i>Sample Format: signed integer</b></i> and <b><i>Bits/Sample: 16</i></b>).<br>
<u>Please note</u>: since now you've constantly encountered <b><i>unsigned integer</i></b> samples; but ETOPO1 is a Global <b>DEM</b> covering both Continent surfaces and Ocean floors, and each pixel value corresponds to an <u><i>elevation measure</i></u>. So in this specific case using <b><i>signed integers</i></b> is a perfectly reasonable solution, because we'll have <u><i>positive</i></u> elevations above sea level and <u><i>negative</i></u> elevations below sea level. 
<verbatim>
$ listgeo ETOPO1_Ice_c_geotiff.tif
Geotiff_Information:
   Version: 1
   Key_Revision: 1.0
   Tagged_Information:
      ModelTiepointTag (2,3):
         0                 0                 0
         -180              90                0
      ModelPixelScaleTag (1,3):
         0.0166666666666667 0.0166666666666667 0
      End_Of_Tags.
   Keyed_Information:
      End_Of_Keys.
   End_Of_Geotiff.
$
</verbatim>
The <b><i>listgeo</i></b> tool confirms that this actually is GeoTIFF: unhappily it's a bogus GeoTIFF, missing to declare many relevant informations (e.g. the intended Reference System). So it's practically useless.
<verbatim>
0.0166666666666667
0.00000
0.00000
-0.0166666666666667
-180.00000
90.00000
</verbatim>
Anyway this isn't a blocking issue: you could easily add by yourself a WorldFile supporting the TIFF (as exemplified in the above snippet); or you could eventually just download it from <a href="https://www.gaia-gis.it/gaia-sins/rasterlite2-resources/ETOPO1_Ice_c_geotiff.tfw">here</a>. 
<h3>Step 2) creating the Etopo1_DEM Coverage</h3>
<verbatim>
$ rl2tool CREATE -db earth.sqlite -cov Etopo1_DEM -smp INT16 \
-pxl DATAGRID -cpr LZMA -srid 4326 -res 0.0166666666666667 -nd -9999

rl2_tool: request is CREATE
===========================================================
              DB path: earth.sqlite
             Coverage: Etopo1_DEM
          Sample Type: INT16
           Pixel Type: DATAGRID
      Number of Bands: 1
        NO-DATA pixel: -9999
          Compression: LZMA (7-zip, lossless)
   Tile size (pixels): 512 x 512
                 Srid: 4326
Pixel base resolution: X=0.0166666666666667 Y=0.0166666666666667
===========================================================

     SQLite version: 3.8.4.2
 SpatiaLite version: 4.2.0-devel
RasterLite2 version: 0.8

Raster Coverage "Etopo1_DEM" successfully created

Operation CREATE successfully completed
$
</verbatim>
<ul>
<li>Exactly as you already did in any previous <b><i>tutorial</i></b> you'll invoke <b><i>rl2tool</i></b> from the command shell.</li>
<li>the most relevant arguments will be explained one by one:
<ul>
<li><b>-smp INT16</b> this specifies the Coverage's Sample Type.</li>
<li><b>-pxl DATAGRID</b> this specifies the Coverage's Pixel Type.<br>
<li><b>-cpr LZMA</b> this specifies that all Tiles in this Coverage must be  compressed using the <u><i>lossless</i></u> <b>LZMA</b> algorithm.<br>
<u>Please note</u>: in this case using the common <b>JPEG</b> compression is completely out of discussion, because JPEG doesn't support 16 bit pixels.</li>
</ul></li>
</ul>
<h3>Step 3) populating the Etopo1_DEM Coverage</h3>
<verbatim>
$ rl2tool IMPORT -db earth.sqlite -cov Etopo1_DEM -srid 4326 -wf \
-src ETOPO1_Ice_c_geotiff.tif -pyr

rl2_tool; request is IMPORT
===========================================================
              DB path: earth.sqlite
    Input Source path: ETOPO1_Ice_c_geotiff.tif
             Coverage: Etopo1_DEM
              Section: from file name
Using the WorldFile
          Forced SRID: 4326
Immediately building Pyramid Levels
===========================================================

     SQLite version: 3.8.4.2
 SpatiaLite version: 4.2.0-devel
RasterLite2 version: 0.8

Importing: ETOPO1_Ice_c_geotiff.tif
------------------
    Image Size (pixels): 21600 x 10800
                   SRID: 4326
       LowerLeft Corner: X=-180.00 Y=-90.00
      UpperRight Corner: X=180.00 Y=90.00
       Pixel resolution: X=0.0166666666666667 Y=0.0166666666666667
  ----------
    Pyramid levels successfully built for: ETOPO1_Ice_c_geotiff

Operation IMPORT successfully completed
$
</verbatim>
Exactly as you already did in any other previous tutorial.
<h3>Step 4) creating and loading your own custom Raster Styles</h3>
<h4>4.1) downloading the ETOPO1 styles</h4>
Just download the appropriate resource-pack from <a href="https://www.gaia-gis.it/gaia-gis/rasterlite2-resources/etopo1_styles.zip">here</a>; it contains any SLD/SE RasterSymbolizer required by this tutorial.
<h4>4.2) exploring the SLD/SE RasterSymbolizer anatomy</h4>
<verbatim>
<?xml version="1.0" encoding="UTF-8"?>
<RasterSymbolizer version="1.1.0" 
		xsi:schemaLocation="http://www.opengis.net/se http://schemas.opengis.net/se/1.1.0/Symbolizer.xsd" 
		xmlns="http://www.opengis.net/se" 
		xmlns:ogc="http://www.opengis.net/ogc" 
		xmlns:xlink="http://www.w3.org/1999/xlink" 
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<Name>etopo</Name>
	<Description>
		<Title>ETOPO1 Color Map</Title>
		<Abstract>derived from the original "etopo2" color rule (GRASS GIS)</Abstract>
	</Description>
	<Opacity>1.0</Opacity>
	<ColorMap>
		<Interpolate fallbackValue="#ffffff">
			<LookupValue>Rasterdata</LookupValue>
			<InterpolationPoint>
				<Data>-11000.00000000</Data>
				<Value>#000000</Value>
			</InterpolationPoint>
			<InterpolationPoint>
				<Data>-5000.00000000</Data>
				<Value>#000064</Value>
			</InterpolationPoint>
			<InterpolationPoint>
				<Data>-1000.00000000</Data>
				<Value>#3232c8</Value>
			</InterpolationPoint>
			<InterpolationPoint>
				<Data>-1.00000000</Data>
				<Value>#9696ff</Value>
			</InterpolationPoint>
			<InterpolationPoint>
				<Data>0.00000000</Data>
				<Value>#009600</Value>
			</InterpolationPoint>
			<InterpolationPoint>
				<Data>270.00000000</Data>
				<Value>#5aa55a</Value>
			</InterpolationPoint>
			<InterpolationPoint>
				<Data>300.00000000</Data>
				<Value>#5aaf5a</Value>
			</InterpolationPoint>
			<InterpolationPoint>
				<Data>500.00000000</Data>
				<Value>#32b432</Value>
			</InterpolationPoint>
			<InterpolationPoint>
				<Data>500.00000000</Data>
				<Value>#46aa46</Value>
			</InterpolationPoint>
			<InterpolationPoint>
				<Data>1000.00000000</Data>
				<Value>#46914b</Value>
			</InterpolationPoint>
			<InterpolationPoint>
				<Data>1000.00000000</Data>
				<Value>#469b4b</Value>
			</InterpolationPoint>
			<InterpolationPoint>
				<Data>2000.00000000</Data>
				<Value>#969c64</Value>
			</InterpolationPoint>
			<InterpolationPoint>
				<Data>3000.00000000</Data>
				<Value>#dcdcdc</Value>
			</InterpolationPoint>
			<InterpolationPoint>
				<Data>4000.00000000</Data>
				<Value>#f5f5f5</Value>
			</InterpolationPoint>
			<InterpolationPoint>
				<Data>8850.00000000</Data>
				<Value>#ffffff</Value>
			</InterpolationPoint>
		</Interpolate>
	</ColorMap>
</RasterSymbolizer>
</verbatim>
You've already got few basic notions about <b><i>RasterSymbolizer</i></b> during the previous <b>Trieste</b> and <b>Orbetello</b> tutorials: now we'll examine a different Symbolizer, i.e. <b><i>ColorMap</i></b>:
<ul>
<li>a Color Map simply represents a <a href="http://en.wikipedia.org/wiki/Lookup_table">lookup table</a>. You can freely define one (or possibly more than one) <a href="http://en.wikipedia.org/wiki/Interval_%28mathematics%29">intervals</a>, and in the output image each pixel will then receive the appropriate color matching the corresponding interval.</li>
<li><u>Recall</u>: the <b><i>ETOPO1</i></b> sample is a Digital Elevation Model and each pixel value corresponds to an <u><i>elevation measure</i></u>. So you can now define as much elevation intervals as you wish, and each interval will correspond to some color of your choice.</li>
<li><b><i>ColorMap</i></b> supports two different flavors:
<ul>
<li><b><i>Interpolate</i></b> intends that each interval has a <u><i>start</i></u> and a <u><i>stop color</i></u>: the actual pixel color will then be the one precisely matching the corresponding <a href="http://en.wikipedia.org/wiki/Color_gradient">color gradient</a>.</li>
<li><b><i>Categorize</i></b> on the other hand intends that any pixels value matching an interval will always be represented by the same identical color.</li>
</ul></li>
</ul>
<h4>4.3) importing all RasterSymbolizers into the DB-file</h4>
<verbatim>
$ sqlite3 earth.sqlite
SQLite version 3.8.4.2 2014-03-26 18:51:19
Enter ".help" for usage hints.
sqlite> .null NULL
sqlite> SELECT load_extension('mod_spatialite');
NULL
sqlite> SELECT CreateStylingTables();
1
sqlite> SELECT RegisterRasterStyledLayer('etopo1_dem',
   ...> XB_Create(XB_LoadXML('./etopo1_styles/etopo.xml'), 1, 1));
1
sqlite> SELECT RegisterRasterStyledLayer('etopo1_dem',
   ...> XB_Create(XB_LoadXML('./etopo1_styles/etopo_categorize.xml'), 1, 1));
1
sqlite> SELECT RegisterRasterStyledLayer('etopo1_dem',
   ...> XB_Create(XB_LoadXML('./etopo1_styles/terrain.xml'), 1, 1));
1
sqlite> SELECT RegisterRasterStyledLayer('etopo1_dem',
   ...> XB_Create(XB_LoadXML('./etopo1_styles/srtm_plus.xml'), 1, 1));
1
sqlite> .quit
$
</verbatim>
This step exactly corresponds to the task already explained in the <b><i>Trieste</i></b> and <b><i>Orbetello</i></b> tutorials.
<h3>Step 5) testing the ETOPO1_DEM sample (and playing with Styles)</h3>
As you've already done in any previous <b><i>tutorial</i></b> you can now directly test the ETOPO1_DEM Coverage by publishing a standard WMS service.<br>
You simply have to start the <b><i>wmslite</i></b> light-weight server, then connecting some WMS viewer (e.g. <b><i>LibreWMS</i></b>) to the service being published on <b><i>localhost</i></b> aka IP address <b><i>127.0.0.1</i></b>, port <b><i>8080</i></b>.<br><br>
<img src="https://www.gaia-gis.it/gaia-sins/rasterlite2-pic/etopo1-default.png" alt="ETOPO1 default"><br>
This first example corresponds to the <u>default</u> Style (no RasterSymbolizer at all): in this case just a basic Grayscale rendering is applied. Not a really interesting option.<br><br>
<img src="https://www.gaia-gis.it/gaia-sins/rasterlite2-pic/etopo1-etopo-categorize.png" alt="ETOPO1 categorize"><br>
This second example corresponds to the <b>etopo_categorize</b> style.<br>
You can now fully appreciate what a <b>ColorMap</b> of the <b>Categorize</b> type really means; all elevations falling within the same class interval have  the same identical color, and the final result is an unpleasant ugly map.<br><br> 
<img src="https://www.gaia-gis.it/gaia-sins/rasterlite2-pic/etopo1-etopo.png" alt="ETOPO1 etopo style"><br>
This third example corresponds to the <b>etopo</b> style; now the <b>ColorMap</b> is of the <b>Interpolate</b> type, and the final result is much more brilliant then before.<br>
<u>Please note well</u>: both the <b>etopo_categorize</b> and the <b>etopo</b> style share exactly the same identical <b>ColorMap</b>; but the <b>etopo</b> style supports the <b>Interpolate</b> rendering, thus producing a wide range of different color shades, and the overall effect surely is a pleasant one.<br><br>
<img src="https://www.gaia-gis.it/gaia-sins/rasterlite2-pic/etopo1-terrain.png" alt="ETOPO1 terrain"><br>
This fourth example corresponds to the <b>terrain</b> style; it's very similar to <b>etopo</b>, but in this case deep waters are simply represented as black areas, so to focus the attention on Lands and nearby shallow waters.<br><br>
<img src="https://www.gaia-gis.it/gaia-sins/rasterlite2-pic/etopo1-srtm-plus.png" alt="ETOPO1 srtm_plus"><br>
This final example corresponds to the <b>srtm_plus</b> style. As you can easily notice, it's not at all difficult creating completely different maps starting from the same identical DEM Coverage; you are simply required to define few alternative Styles and that's all.<br>
And using the standard capabilities supported by the WMS protocol switching from a Style to the other can be performed in the most simple and dynamic way.
<br><br>
<hr><br>
Back to <a href="https://www.gaia-gis.it/fossil/librasterlite2/wiki?name=tutorials">RasterLite2 Tutorials index</a>
Z 3d014fcbb8fa84d72a8eda3674469b73