mapchete.commons.hillshade module

Calculate hillshade and slopeshade.

Original code is from: https://github.com/migurski/DEM-Tools/blob/master/Hillup/data/__init__.py#L288-L318

License

Copyright (c) 2011, Michal Migurski, Nelson Minar

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the followg conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the followg disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the followg disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

mapchete.commons.hillshade.calculate_slope_aspect(elevation, xres, yres, z=1.0, scale=1.0)

Calculate slope and aspect map.

Return a pair of arrays 2 pixels smaller than the input elevation array.

Slope is returned in radians, from 0 for sheer face to pi/2 for flat ground. Aspect is returned in radians, counterclockwise from -pi at north around to pi.

Logic here is borrowed from hillshade.cpp: http://www.perrygeo.net/wordpress/?p=7

Parameters
elevationarray

input elevation data

xresfloat

column width

yresfloat

row height

zfloat

vertical exaggeration factor

scalefloat

scale factor of pixel size units versus height units (insert 112000 when having elevation values in meters in a geodetic projection)

Returns
slope shadearray
mapchete.commons.hillshade.hillshade(elevation, tile, azimuth=315.0, altitude=45.0, z=1.0, scale=1.0)

Return hillshaded numpy array.

Parameters
elevationarray

Input elevation data.

tileTile

Tile covering the array.

azimuthfloat

Light source direction in degrees. (default: 315, top left)

altitudefloat

Light source altitude angle in degrees. (default: 45)

zfloat

Vertical DEM exaggeration factor. (default: 1)

scalefloat

Scale factor of pixel size units versus height units (insert 112000 when having elevation values in meters in a geodetic projection).