title: Calculate slope on DEM
body: <p>i have another problem.</p>
  
  <p>I have to compute a slope for each cell in digital elevation model. The slope should be calculated for each center cell in a moving window with shape 3x3 cell and according tot he formula:</p>
  
  <p>Slope=max|x9-xi|/A ; where values i are values from one to eight and value x9 is the center of a window. A is distance to the neighbouring cell midpoint. So for the cells that are diagonal to the center, the distance(A) is sqrt(2) multiplyed by resolution and for the others it's just equal to the resolution.</p>
  
  <p>So what I don't know is how to write a code that will differ from cells that are diagonal and which not? I created an empty numpy array with 'no values' where I want to have slope values with the same resolution. I know I have to loop through rows and columns and that have to ignore the first and last rows and columns. 
  My code so far:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  dem=np.loadtxt('dem.txt',dtype='int',delimiter=',')
  (rows,cols)=np.shape(dem)
  slope2=np.zeros((rows,cols))
     for r in xrange(1,rows-1):
      for c in xrange(1,cols-1):
          temp_win=dem[r-1:r+2,c-1:c+2]
          mid= temp_win[1,1]
          max_d=np.max([temp_win[0,0]],[temp_win[0,2]],[temp_win[2,0]],[temp_win[2,2]])
          max_1=np.max([temp_win[1,1]],[temp_win[1,0]],[temp_win[1,2]],[temp_win[2,1]])
          slope = (np.max([np.abs(mid-max_d)/np.sqrt(2)]),np.max([np.abs(mid-s1/np.sqrt(2))])
          slope_2 = slope[r,c]
  </code></pre>
  
  <p>Does anyone have any idea, I would really appreciate some help?</p>