<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE page SYSTEM "gen/gandraxa.dtd">
<?xml-stylesheet type="text/xsl" href="gen/gandraxa.xsl"?>
<!--
	To see this page properly, install a browser capable of
	interpreting XML/XSL, for example a recent version of:
	- Mozilla Firefox, see http://www.mozilla.com/
	- Google Chrome, see www.google.com/
	- Internet Explorer, see http://www.microsoft.com/
-->
<page>
	<head>
		<title>Digital Elevation Models</title>
		<url>http://herbert.gandraxa.com/digital_elevation_models.xml</url>
		<menuimg>
			<img>
				<url>img/dem_menu.jpg</url>
				<alt>Digital elevation model</alt>
			</img>
		</menuimg>
		
		<context>
			<path>
				<home>
					<link loc="int">
						<url>home.xml</url>
						<text>Home</text>
					</link>
				</home>
				<dir>
					<link loc="int">
						<url>articles.xml</url>
						<text>Articles</text>
					</link>
				</dir>
				<dir>
					<link loc="int">
						<url>digital_terrain_analysis.xml</url>
						<text>Digital Terrain Analysis</text>
					</link>
				</dir>
				<doc>Digital Elevation Models</doc>
			</path>

			<chain>
				<next>
					<link loc="right">
						<url>isometric_projection.xml</url>
						<text>Isometric Projection</text>
					</link>
				</next>
			</chain>
		</context>
		
		<author>
			<mail>
				<recipient>hg</recipient>
				<server>gandraxa.com</server>
				<name>Herbert Glarner</name>
			</mail>
		</author>
		
		<publ>
			<event>
				<eventdate><y>2007</y><m>Feb</m><d>24</d></eventdate>
				<eventtext>First published</eventtext>
			</event>
			<event>
				<eventdate><y>2011</y><m>Jan</m><d>23</d></eventdate>
				<eventtext>
					Recoded in XLM
				</eventtext>
			</event>
		</publ>
		
		<furtherreading>
			<readitem>
				<link loc="wiki">
					<url>http://en.wikipedia.org/wiki/Digital_Elevation_Model</url>
					<text>Digital Elevation Models</text>
				</link> 
				on Wikipedia
			</readitem>
			<readitem>
				NASA Jet Propulsion Laboratory, Homepage of the
				<link loc="ext">
					<url>http://www2.jpl.nasa.gov/srtm/</url>
					<text>Shuttle Radar Topography Mission</text>
				</link> 
			</readitem>
			<!-- Seems to be broken
				<readitem>
					National Geospatial-Intelligence Agency (NGA),
					<link loc="ext">
						<url>http://www.nga.mil/portal/site/nga01/</url>
						<text>homepage</text>
					</link>
				</readitem>
			-->
			<readitem>
				U.S. Geological Survey (USGS),
				<link loc="ext">
					<url>http://www.usgs.gov/</url>
					<text>homepage</text>
				</link>
			</readitem>
		</furtherreading>
		
		<books>
			<book>
				<img>
					<url>img/dem_book.jpg</url>
					<alt>Digital Terrain Modeling: Principles and Methodology</alt>
				</img>
				<booktitle>Digital Terrain Modeling: Principles and Methodology</booktitle>
				<booklinks>
					<booklink-us>http://www.amazon.com/gp/product/0415324629/ref=as_li_qf_sp_asin_tl?ie=UTF8&amp;tag=gandraxa0d-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0415324629</booklink-us>
					<booklink-ca>http://www.amazon.ca/gp/product/0415324629/ref=as_li_qf_sp_asin_tl?ie=UTF8&amp;tag=gandraxa02-20&amp;linkCode=as2&amp;camp=15121&amp;creative=330641&amp;creativeASIN=0415324629</booklink-ca>
					<booklink-uk>http://www.amazon.co.uk/gp/product/0415324629/ref=as_li_qf_sp_asin_tl?ie=UTF8&amp;tag=gandraxa-21&amp;linkCode=as2&amp;camp=1634&amp;creative=6738&amp;creativeASIN=0415324629</booklink-uk>
					<booklink-de>http://www.amazon.de/gp/product/0415324629/ref=as_li_qf_sp_asin_tl?ie=UTF8&amp;tag=gandraxa0a-21&amp;linkCode=as2&amp;camp=1638&amp;creative=6742&amp;creativeASIN=0415324629</booklink-de>
					<booklink-fr>http://www.amazon.fr/gp/product/0415324629/ref=as_li_qf_sp_asin_tl?ie=UTF8&amp;tag=gandraxa00-21&amp;linkCode=as2&amp;camp=1642&amp;creative=6746&amp;creativeASIN=0415324629</booklink-fr>
					<booklink-it>http://www.amazon.it/gp/product/0415324629/ref=as_li_qf_sp_asin_tl?ie=UTF8&amp;tag=gandraxa0fa-21&amp;linkCode=as2&amp;camp=3370&amp;creative=23322&amp;creativeASIN=0415324629</booklink-it>
				</booklinks>
			</book>
		</books>
	</head>

	<toc>
		<toc1 ref="A">Basics</toc1>
			<toc2 ref="A1">Terminology</toc2>
			<toc2 ref="A2">Data Sources</toc2>
		<toc1 ref="B">Quantities</toc1>
			<toc2 ref="B1">Data Volumes</toc2>
			<toc2 ref="B2">Evaluating a Download</toc2>
		<toc1 ref="C">Obtaining Elevation Data</toc1>
			<toc2 ref="C1">USGS Interface</toc2>
			<toc2 ref="C2">Examining your Download</toc2>
		<toc1 ref="D">Verification</toc1>
	</toc>

	<abstract>
		<p><ptitle>Abstract</ptitle>
			This page explains the process of obtaining elevation data 
			from the U.S. Geological Survey (USGS), and shows how to verify the obtained data.</p>
	</abstract>



	<part>
		<heading id="A">Basics</heading>
		<chapter>
			<heading id="A1">Terminology</heading>
			<body>
				<p>Digital Elevation Models are collections of data to represent 
					the different elevations of surface area. In their most intuitive 
					form they come as a two-dimensional matrix, where the rows represent 
					latitudes and the columns longitudes. The individual cells are then 
					filled with the elevation for the given latitude/longitude combination. 
					The elevation most often is given in meters above (or below) sea level.</p>
			</body>
		</chapter>
		<chapter>
			<heading id="A2">Data Sources</heading>
			<body>
				<p>There are many sources on the Internet which provide elevation data 
					for many regions. However, many of them either lack accuracy, or don't 
					provide the desired resolution, or are restricted to very small areas, 
					or all of these.</p>
				<p>Fortunately, since the advent of the Shuttle Radar Topography Mission (SRTM) 
					things have changed. The aim of that project was set high: 
					it comprised measuring the elevation of a vast part of the Earth 
					(more accurately the area between 56° Southern latitude and 
					60° Northern latitude), at a resolution of one arc second 
					(corresponding to approx. 30 meters horizontally and vertically). 
					The project was carried out by the Space Shuttle Endeavour
					during its mission in February of 2000, in which all measurements 
					occured with the help of two radar antennas placed 60 meters apart, 
					employing a technique called interferometric Synthetic Aperture Radar.</p>
				<p>For us non-US-government people, it is absolutely a highlight that 
					the National Geospatial-Intelligence Agency (NGA) and the 
					National Aeronautics and Space Administration (NASA), the leaders of 
					this international project, decided that this material shall be 
					available for free, for everyone having access to the Internet 
					<note ref="1">
						<p>Note, that the availability of the data is somewhat restricted: 
						the resolution of one arc second is available for 
						US territories only; for all other areas the data 
						made available to the public has a resolution of 3 arc seconds, 
						corresponding to approx. 90 meters between two measurement points.</p>
					</note>.</p>
				<p>It comes ever better, though: much of the US territory data was 
					improved to an accuracy of 1/3 arc seconds, meaning that the resolution 
					was brought to approx. 10 meters between two measurement points. 
					The data was made available in a very comfortable manner by the 
					U.S. Geological Survey (USGS). The section after the next one is 
					dealing with their web interface.</p>
			</body>
		</chapter>
	</part>

	<part>
		<heading id="B">Quantities</heading>
		<chapter>
			<heading id="B1">Data Volumes</heading>
			<body>
				<p>Before retrieval of actual data, let's consider for a moment 
					about what data volumes we are talking.</p>
				<p>Let's assume, that we have available data for the whole planet, 
					at a resolution of 10 meters. The Earth has a surface of 
					approx. 510 million km<sup>2</sup>, 
					of which approx. 149 million km<sup>2</sup> (29.2%) is land. 
					At an accuracy of 10 meters, the data would amount to 
					100 x 100 = 10,000 elevation measurements per square kilometer, 
					and thus (if we restrict ourselves to the land areas) to 
					a total of 1.49 trillion data points (short scale terminology, 
					i.e. 1 trillion = 1 million millions).</p>
				<p>Depending on the desired resolution, storing a single data point 
					requires more than just a byte, though: 
					a byte at 8 bits can only hold 2<sup>8</sup>=256 distinct values. 
					If we aim for an elevation expressed in meters above sea level, 
					then we need at least 14 bits (for values between 0 and 16,383 meters) 
					to accommodate such heights as the Mount Everest's peak at 8,848 meters. 
					And if we also want to express negative values, another bit is needed 
					to act as a sign bit. 
					Since 15 bits are quite unhandy to deal with in modern computer systems, 
					two bytes with a total of 16 bits will be used instead 
					(and this is in fact one of the data formats which is provided 
					by the USGS).</p>
				<p>From above it becomes obvious, that the total storage requirements 
					amounts to approx. 3 Terabytes, or at the time of writing this article 
					about thrice the size of the largest hard disk drives available for 
					PCs 
					<note ref="2"><p>At the time of writing this article the largest 
						hard disk drive available was the 
						<em>Hitachi Deskstar 7K1000</em>.</p></note>.</p>
			</body>
		</chapter>
		<chapter>
			<heading id="B2">Evaluating a Download</heading>
			<body>
				<p>For the reasons given above, we are forcing ourselves to some modesty: 
					what we are looking for is high-resolution data 
					(1/3 arc second, or 10 meters) 
					not exceeding hard disk space of about 100 MB. 
					Given a comparably modern PC, this quantity has 
					the following advantages:</p>
				<list>
				 	<li>the download via a DSL or cable connection should be feasible 
				 		(a few minutes at max.);</li>
					<li>it should be possible to store it onto your hard disk drive; and</li>
					<li>it should be possible to process it within your local RAM.</li>
				 </list>
				<p>100 MB imply, that we are looking for approx. 50 million data points 
					(because each elevation point requires 16 bits = 2 bytes to be encoded). 
					These 50 million points cover a rectangular area of whatever dimensions. 
					To get an estimation of what we are looking for, 
					let's assume the area is approximately square. 
					The square root of 50 million will tell us the length of 
					the square's edges then (in data points): 
					the result is approx. 7,000 data points, 
					and since we are after a resolution of 10 meters, 
					we can go for a square with an edge length of 
					approx. 70,000 meters = 70 km, 
					covering an area of approx. 5,000 km<sup>2</sup>.</p>
				<img float="right" width="304">
					<url>/img/dem_fig1.jpg</url>
					<alt>Google Maps showing Maui and Kaho'olawe</alt>
					<caption>Fig. 1: Finding a suitable area, in this case Maui 
						and Kaho'olawe. © Google, Imagery © TerraMetrics, NASA,
						Map data © NAVTEQ&#8482;</caption>
				</img>
				<p>Because a goal of this article is the verification of once downloaded data, 
					it would be ideal if we could tell quite instantly if we got it right. 
					For this reason, it would be an advantage if we could find 
					an island of roughly the area outlined above: 
					assuming that the sea level is given as 0 (meters above sea level), 
					we would be able to immediately identify the isolated landmass 
					within a body of water, simply by distinguishing 0 and non-0 values 
					and coloring the two entities differently.</p>
				<p>Bearing in mind, that such high-resolution data was made available 
					only for US territories, prospective area candidates were searched 
					within the islands forming the US state of Hawaii. 
					The "big island" 
					<link loc="wiki">
						<url>http://en.wikipedia.org/wiki/Hawaii_%28island%29</url>
						<text>Hawai'i</text>
					</link> is too big for our purpose 
					(its landmass alone is larger than 10,000 km<sup>2</sup>), 
					but the second-largest island 
					<link loc="wiki">
						<url>http://en.wikipedia.org/wiki/Maui</url>
						<text>Maui</text>
					</link>, having a landmass of less than 2,000 km<sup>2</sup>, 
					with the inclusion of it's small Southwestern neighbor 
					<link loc="wiki">
						<url>http://en.wikipedia.org/wiki/Kahoolawe</url>
						<text>Kaho'olawe</text>
					</link> (approx. 116 km<sup>2</sup>) would suit us well: 
					about half of the area consists of water surrounding the islands 
					and the other half of land.</p>
				<p>A quick check on 
					<link loc="ext">
						<url>http://maps.google.com/</url>
						<text>Google Maps</text>
					</link> (Fig. 1) reveals, 
					that the rectangle surrounding the two islands would have 
					a dimension of roughly 80 km horizontally and 60 km vertically: 
					pretty much exactly what we want.</p>
			</body>
		</chapter>
	</part>

	<part>
		<heading id="C">Obtaining Elevation Data</heading>
		<chapter>
			<heading id="C1">USGS Interface</heading>
			<body>
				<p>Now that we know what we want, it's about the time 
					to deal with the USGS web interface. 
					It can be reached via 
					<link loc="ext">
						<url>http://seamless.usgs.gov/website/seamless/viewer.php</url>
						<text>http://seamless.usgs.gov/website/seamless/viewer.php</text>
					</link>. Note that it might take a while until the map within 
					the page has been loaded.</p>
				<img>
					<url>/img/dem_fig2.jpg</url>
					<alt>Starting the USGS web interface</alt>
					<caption>Fig. 2: Starting the USGS web interface</caption></img>
				<p>In the elevation menu to the right deselect the default mark 
					and select "NED shaded relief (1/3 arc second)" instead (Fig. 3). 
					You will notice that the map's appearance changes on deselection 
					and selection to reflect the availability within the chosen resolution.</p>
				<img>
					<url>/img/dem_fig3.jpg</url>
					<alt>Selecting the resolution</alt>
					<caption>Fig. 3: Selecting the resolution</caption></img>
				<p>Since we by default already are in the "Zoom" menu, we can zoom 
					into the appropriate area simply by dragging the mouse 
					while its left button is pressed: 
					a red rectangle will give you feedback about 
					the currently selected area (Fig. 4).</p>
				<img>
					<url>/img/dem_fig4.jpg</url>
					<alt>Zooming into the desired area</alt>
					<caption>Fig. 4: Zooming into the desired area</caption></img>
				<p>Upon releasing the mouse button, a zoomed-in map as per your rectangle 
					will be loaded. Notice that the areas for which data is available 
					appear highlighted. Repeat this process of zooming in closer and closer 
					until you have selected the desired area, 
					in the case of our example the islands of Maui and Kaho'olawe. 
					If the resolution is high enough, the names of places 
					are blended in to facilitate orientation.</p>
				<p>Now select the "Downloads" menu group by clicking 
					on the icon "Define Download Area". 
					After this, the mouse essentially will react as before, 
					i.e. one can click and drag to define a rectangular area 
					within the currently displayed map. 
					Being in the "Downloads" menu gives you an additional feedback 
					(as explained in the notes below the map): 
					if the color of the rectangle's borders is red, 
					then the resulting file would be too large to be made 
					available for download. 
					This will be the case for data volumes exceeding 250 MB. 
					You then either need to proceed in smaller steps 
					and assemble the download files programmatically, 
					or you need to order the the file on media 
					if you indeed want the data as one single file. 
					As long as the color of the rectangle is green, though, 
					all is fine and you can continue. 
					Try to not to be too generous with the surrounding water area: 
					every pixel you include in your selection results in 
					a larger download file (Fig. 5).</p>
				<img>
					<url>/img/dem_fig5.jpg</url>
					<alt>Selecting the download area</alt>
					<caption>Fig. 5: Selecting the download area</caption></img>
				<p>Now another window opens with the details of your selection. 
					Do <em>not</em> just accept the data presented there. 
					Instead, use the option "Modify Data Request". 
					You will notice, that all of the products listed here 
					should be deselected, with the exception of 
					"National Elevation Dataset (NED) 1 Arc Second" 
					near the end of the list. 
					This is <em>not</em> what we want: 
					deselect it and choose 
					"National Elevation Dataset (NED) <em>1/3 Arc Second</em>" 
					instead (Fig. 6). 
					Notice, that this data is not the original SRTM project data: 
					the 1 arc second and 3 arc seconds data are in the 
					two bottommost options.</p>
				<p>Just after your selection three scrolldown lists appear. 
					If you follow this example, you must select "BIL" as the data format 
					to be delivered, not "ArcGrid" as is suggested by default. 
					"BIL" will return 16 bit data per elevation point, 
					which is the easiest format to deal with. 
					Also, select "TXT" as the data format, 
					we don't want fancy markups, just the data. 
					Depending on your computing environment, 
					select the compression format ("ZIP" or "TGZ"). 
					When done, click on the button labeled 
					"Save changes and return to summary".</p>
				<img>
					<url>/img/dem_fig6.jpg</url>
					<alt>Settings of your request</alt>
					<caption>Fig. 6: Settings of your request</caption></img>
				<p>Once back to the summary, make sure you do indeed have the space 
					on your machine to hold the requested data. 
					Recall, that you will be delivered a compressed file, 
					which you eventually must decompress to make use of it.</p>
				<p>You schedule your download by clicking on the according button. 
					Notice, that depending on the workload of the USGS server 
					it might take a while until your requested data is ready, 
					and also the download itself will need its time. 
					Time to get yourself a coffee while this happens.</p>
			</body>
		</chapter>
		<chapter>
			<heading id="C2">Examining your Download</heading>
			<body>
				<p>Once the file is on your machine, decompress it into a folder of your choice. 
					The file with the extension ".bil" contains your raw data. 
					That file is quite large (in my case it has exactly 96,001,532 bytes).</p>
				<p>If you open it in a text editor capable of dealing with hex files 
					(e.g. 
					<link loc="ext">
						<url>http://www.ultraedit.com/</url>
						<text>UltraEdit</text>
					</link>), you will notice a lot of <code>00</code> bytes at the start 
					(at least if you were following this example). 
					More accurately we should not speak about single bytes here, though, 
 					because the BIL format delivers 16 bits = 2 bytes per data point 
					(hence you should notice a lot of <code>00 00</code> sequences). 
					This is because the left upper corner of the selection rectangle 
					was located in the ocean, and since this is at sea level, 
					its elevation is 0 meters.</p>
				<p>Scroll somewhat down and you will notice different data (Fig. 7). 
					I marked two elevation points in it, 
					one is the hexadecimal sequence <code>2B 07</code>, 
					and the other <code>2A 07</code>. 
					These sequences are in 
					<link loc="wiki">
						<url>http://en.wikipedia.org/wiki/Endianness</url>
						<text>Little Endian</text>
					</link> order, which means, that the bytes must be interpreted 
					from right to left, i.e. <code>07 2B</code> and <code>07 2A</code>. 
					The hexadecimal values of 072B and 072A stand 
					for decimal 1835 and 1834, resp., which is the elevation 
					in meters above sea level. 
					These two particular values are not unreasonable,
					as the Wikipedia article about the island Maui tells us, 
					that the island's highest point is 3,055 meters (the Haleakala volcano).</p>
				<img>
					<url>/img/dem_fig7.jpg</url>
					<alt>Examining the BIL file</alt>
					<caption>Fig. 7: Examining the BIL file</caption></img>
				<p>You might have observed, that there is no delimiter 
					structuring the obtained data. So how do we know how the data 
					is structured then? As per explanations on the USGS site, 
					the raw data is delivered row after row, starting at the 
					Northwestern corner of your selection rectangle. 
					Within a row there are several cells occupying 2 bytes each. 
					But how do we know, how many cells make up a row? 
					This is encoded in a headers file with the extension ".hdr", 
					which you will find in your zip delivery as well. 
					In my case there are the following entries in there:</p>
				<table>
					<row><col>BYTEORDER</col><col>I</col></row>
					<row><col>LAYOUT</col><col>BIL</col></row>
					<row>
						<col highlight="yellow">NROWS</col>
						<col highlight="yellow">5951</col></row>
					<row>
						<col highlight="yellow">NCOLS</col>
						<col highlight="yellow">8066</col></row>
					<row><col>NBANDS</col><col>1</col></row>
					<row><col>NBITS</col><col>16</col></row>
					<row><col>BANDROWBYTES</col><col>16132</col></row>
					<row><col>TOTALROWBYTES</col><col>16132</col></row>
					<row><col>BANDGAPBYTES</col><col>0</col></row></table>
				<p>As you might have suspected already, 
					the entries labeled <code>NROWS</code> and <code>NCOLS</code> 
					provide the required numbers. 
					In my case, there are 5,951 rows each having 8,066 cells, 
					for a total of 5,951 × 8,066 = 48,000,766 cells. 
					Multiply this by 2 bytes per cell and you get 96,001,532 bytes &#8211; 
					exactly the length of my BIL file.</p>
			</body>
		</chapter>
	</part>

	<part>
		<heading id="D">Verification</heading>
		<body>
			<p>So far we are quite confident that we are able to interpret the received data. 
				What's missing is some actual programming. 
				How you do this and in what programming language is up to you. 
				However, the pseudo code is quite trivial:</p>
<pre>Open File
	FilePos := 0
	For Row = 1 To 5951
		For Col = 1 To 8066
			Elevation := Get 2 Bytes at FilePos
			Do Something with Elevation
			FilePos := FilePos + 2
		Next Col
		Switch to next Row
	Next Row
Close File</pre>
			<p>The task described with "Do Something with Elevation" was to find 
				the minimum and maximum elevations, so that I could quickly tell 
				if the data I received was reliable. 
				Remember that the 16 bits are signed, though 
				(which makes sense, as it is very well possible to have elevations
				 below sea level). In my case I received a minimum of -4 meters 
				 (<code>0xFFFC</code>), 
				 and a maximum of 3,053 meters 
				 (<code>0x0BED</code>). This is what we expected, 
				 since Maui's highest point is given as 3,055 meters.</p>
			<p>The second task was more fun, as it was about creating 
				a miniaturized false-color image. 
				My current screen resolution is 1,280×1,024 pixels, 
				so to accommodate the obtained data on my screen I needed 
				to omit 7 out of 8 points, both horizontally and vertically, 
				resulting in an image of 1,008×743 pixels.</p>
			<p>I arbitrarily decided to output all points with an elevation 
				of 0 and less meters as a blue pixel, 
				and introduced height levels 512 meters apart, 
				such subdividing the islands' heights into 7 layers 
				(0 to 512 meters, 512 to 1024 meters, ..., 3072 to 3584 meters). 
				Each layer was given a distinct plain color 
				(yellow, light green, ..., white). 
				To make steep slopes better visible, individual heights 
				were interpolated between two neighboring colors, 
				in a resolution of 1/256 per color component. 
				The scaled-down result can be seen in Fig. 8.</p>
			<img>
				<url>/img/dem_fig8.jpg</url>
				<alt>False-color image of data sample</alt>
				<caption>Fig. 8: False-color image of data sample</caption></img>
			<p>The islands' shapes don't differ from what we expected 
				(compare with the map from Google Maps, Fig. 1), 
				also smaller features like Maui's Kealia Pond 
				(near the Southern coast of the isthmus) are represented accurately. 
				To show this was the goal of this first article within 
				the series Digital Terrain Analysis.</p>
		</body>
	</part>
</page>

