I am trying to find all cells that are a certain distance and within a certain window from a cell of interest.

For example: I want all cells in a distance of 10m within a search window of 10 - 40 degrees (from North).

Any hint how to do that using either a GRASS function or shell?


You could buffer the cell to 10m using r.buffer. Then use r.cost on the constant-value buffer with your starting cell as the starting point, which would make a cone. Run r.slope.aspect to get the aspect angle of the cone. Then use r.mapcalc to set certain angles to nodata or something. This will leave you with a map showing the area within a certain distance and angle window of your starting cell.

Here's some GRASS 6.4 code:

g.region w=0 e=40 s=0 n=40 res=0.5
echo "20,20,0" | r.in.xyz input=- output=cell_of_interest fs=','
r.buffer input=cell_of_interest output=coi_buffer distances=10
r.cost -k input=coi_buffer output=coi_cone start_rast=cell_of_interest 
r.slope.aspect elevation=coi_cone aspect=coi_cone_aspect
# note that angle is w.r.t. west not north
r.mapcalc target='if(coi_cone_aspect>10 && coi_cone_aspect<40,1,null())' 

Here's what the results look like:

  1. The result of r.buffer

enter image description here

  1. The result of r.cost

enter image description here

  1. The result of r.aspect

enter image description here

  1. Final result after r.mapcalc. The angle isn't with respect to north though. So you'll need to convert the angle accordingly.

enter image description here

  • 1
    @wittich Thanks for the edit. I didn't know you could add a language tag like that, but now I do :) – user55937 Feb 27 '16 at 16:36
  • Excellent. I'm glad I was able to help! – user55937 Feb 29 '16 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.