Creating elevation contours

Now, let's look at another way to visualize the elevation better using contours. A contour is an isoline along the same elevation in a dataset. Contours are usually stepped at intervals to create an intuitive way to represent elevation data, both visually and numerically, using a resource-efficient vector dataset.

The input to generate contours is our DEM and the output is a shapefile. The algorithm to generate contours is fairly complex and very difficult to implement using NumPy's linear algebra. So, our solution in this case is to fall back on the GDAL library, which has a contouring method available through the Python API. In fact, the majority of this script is just setting up the OGR library code that is needed ...

Get Learning Geospatial Analysis with Python - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.