[GRASS-dev] using slope/aspect functions inside our module

Glynn Clements glynn at gclements.plus.com
Wed Jul 4 08:14:40 EDT 2007


Yann wrote:

> In a given chain processing module (DN->high-level product) in development, 
> there is a need of calculating slope and aspect, i would like to use the 
> existing code as a library or something to the similar effect.
> 
> Anyone could explain if it is possible and how it could be possible?

It isn't practical to use code from a module in a library.

Even if it was, calculating slope/aspect is so trivial that it's
easier to just write it from scratch than to extract the code from
r.slope.aspect.

FWIW, the calculation which r.slope.aspect uses is essentially:

	dx = ((c1 + 2*c4 + c7) - (c3 + 2*c6 + c9)) / (4 * ewres);
	dy = ((c7 + 2*c8 + c9) - (c1 + 2*c2 + c3)) / (4 * nsres);
	key = dx*dx + dy*dy;
	slp_in_perc = 100*sqrt(key);  
	slp_in_deg = atan(sqrt(key)) * radians_to_degrees;
	aspect = (atan2(dy,dx)/degrees_to_radians);

where the cells are labelled:

	c1 c2 c3
	c4 c5 c6
	c7 c8 c9

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list