Book Image

Python Geospatial Analysis Cookbook

Book Image

Python Geospatial Analysis Cookbook

Overview of this book

Table of Contents (20 chapters)
Python Geospatial Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Other Geospatial Python Libraries
Mapping Icon Libraries
Index

Converting an ESRI ASCII DEM to an image height map


To end this chapter with a bang, here is the most complicated conversion we have seen so far and the most fun as well. Input is an elevation dataset that's stored in ASCII format, more specifically, Arc/Info ASCII Grid, for short with the AAIGrid with the (.asc) file ending. Our output is a heightmap image (http://en.wikipedia.org/wiki/Heightmap). A heightmap image is an image that stores height elevation as a pixel value. A heightmap is also simply known as a digital elevation model (DEM). The benefit of using an image to store elevation data is that it is web compatible and we can use this in a 3D visualization with threejs, for example, as shown in Chapter 10, Visualizing Your Analysis.

We need to be careful with regard to the output image format because simply storing an 8-bit image limits us to only storing 0 to 255 height values, which is typically not enough. The output image should store a minimum of 16-bits, giving us a range from...