Select to view content in your preferred language

Create Neighborhood with Numpy array to calculate slope

3253
1
11-14-2010 04:56 PM
AndrewRettig
Emerging Contributor
I am hoping someone has experience with creating a neighborhood to calculate the slope for each pixel in a raster.  I can easily convert the raster to an array and then do a calculation and convert back to a raster.  However, I have no experience in creating a 5x5 neighborhood to calculate the slope in numpy or if this is even possible.

Any help or resources would be appreciated.

Andrew
0 Kudos
1 Reply
Luke_Pinner
MVP Regular Contributor
Perhaps use the SciPy NDImage package to implement your slope algorithm.
http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.filters.generic_filter.html

i.e

import scipy.ndimage

def CustomSlope(numpy_array):
   #Do something

slope = scipy.ndimage.generic_filter(elevation_array, CustomSlope, size=(5,5))
0 Kudos