0

This is my first time using GRASS to work with Rasters, so please excuse my lack of knowledge on the subject.

I want to run the GRASS r.neighbors function on cells that meet a specific criteria, and ignore running the function that do not meet that criteria. In addition, I still want to use the values that do not meet the criteria in the neighborhood calculations.

For example, I have a raster with integer values, and I want cells with a value of 1, 2, and 3 to run the r.neighbors function, but not values of 4, and 5. When the function gets to cells with values of 1, 2, or 3, r.neighbors should run, and include all cells within the neighborhood (even ones with values 4, and 5). When cells of 4, and 5 are encountered, I simply want to do nothing and move to the next cell.

Here is a very similar Knowledge Base article from Esri that does this, but with NoData cells. I need to do it using GRASS.

Looking at the documentation for r.neighbors, I do not see a clear way to approach this. I do not believe I can simply loop through the raster cells and run the r.neighbors function since the output is a new raster each time it run.

If that is the case, then perhaps I can reverse engineer the r.neighbors function within a conditional? I just have no idea how r.neighbors determines it's neighborhood.

  1. How does r.neighbors walk through the raster collecting cell values?
    • If so, then how does it do this?
    • Ultimately, this is what I want to know the most!
  2. Would I be better off trying to do this outside of GRASS?
    • If so, what are your recommendations?

Right now, I am just stuck on where to go.


I am most interested in learning how (systematically) r.neighbors collects the neighborhood values. What functions, methods, etc. does GRASS use to read specific cell values within a) a certain number of cells OR b) a specific distance in n direction of a given cell? I believe knowing this will help me the most going forward.

closed as too broad by PolyGeo Sep 1 '17 at 19:30

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

1

1) Does r.neighbors walk through the raster collecting cell values?

The neighborhood operators determine a new value for each cell as a function of the values in its neighboring cells. All cells in a raster map, except for the cells at the map boundaries, become the center cell of a neighborhood as the neighborhood window moves from cell to cell throughout the map (Open Source GIS: A GRASS GIS Approach.)

Look also GRASS Tutorial:r.neighbors

2) Would I be better off trying to do this outside of GRASS?

You can use R with GRASS as in Terrain Classification Ideas: Coupling GRASS and R or R without GRASS

  • Thank you for your reply and suggestion. I realized I should have been more clear in what I want (see edit comment above). I am more interested in exactly how the window "finds" the appropriate cells. I understand the theory of it, but if I need to reverse engineer the r.neighbors function, I need to know (systematically) what r.neighbors does to collect the cell values within it's neighborhood window. I will look into R and see how promising it is. Thanks! – evv_gis Nov 18 '14 at 18:37
  • 2
    You can examine the C sources r.neighbors Directory Reference – gene Nov 18 '14 at 18:50
  • See also "r.neighbors treating NULL values" here: lists.osgeo.org/pipermail/grass-user/2014-October/071011.html – markusN Nov 21 '14 at 16:21

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