Slope and Aspect calculations in R
Hello Josh, and list, Figuring out how to link R with GIS may be extremely useful to you, not just for calculating slope and aspect, but also for other analyses in the future. There are also reasons you might not want to; I am one of those people who likes to write his own code. Consequently I implemented the Horne algorithm a while back - this is used in ESRI software for calculating slope. The code, a pretty simple function, is here: https://www.msu.edu/~ashton/classes/866/notes/lab12/slope.R Three caveats: 1. ESRI's version changes the neighborhood shape on the raster edges. The result is a slope grid with slopes calculated for every cell in the input elevation grid. The linked function only calculates slope on the interior cells. It returns a raster of the same dimension as the input, but there are no valid slope values around the edges. 2. Many developers on this list might agree with me that often the hardest part of coding spatial algorithms is dealing with the data structures. Over the years we've seen the development of increasingly sophisticated spatial data structures in R. My implementation dates from the Pleistocene of R, and is simply implemented on a matrix. Your data may have to be restructured to work seamlessly with this script, or you may wish to change the script to fit your structure. 3. While this function works perfectly adequately on smaller grids, it has not been tested on large matrices. It was not developed with speed in mind - the script was for a classroom exercise, and I wanted my students to be able to read the code and relate it to the published algorithm before executing it on fairly small datasets. If I wanted to calculate slope on huge grids, I'd personally do it in GRASS or Arc/Info, or in home-rolled C code. Hope this may be useful! Ashton
On Friday 10 July 2009 14:42:29 Josh London wrote:
Thanks to everyone for the feedback. I may dabble around with SAGA/RSAGA on a linux box we have and also continue to watch for any MacOS builds. Roger, I am especially excited that spgrass6 has the initGRASS() function. by providing access to r.slope.aspect, I think that will be the simplest/quickest route to a solution. I look forward to tapping into other GRASS commands in the future. You may want to consider changing the description of spgrass6 on CRAN. I have interpreted the phrase 'based on starting R from within the GRASS environment' to mean the package is for those who use GRASS and want to access functions within R. cheers, and thanks again for the feedback and help Josh
Ashton Shortridge Associate Professor ashton at msu.edu Dept of Geography http://www.msu.edu/~ashton 235 Geography Building ph (517) 432-3561 Michigan State University fx (517) 432-1671