Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was wondering if someone could help me write a majority filter for GRASS GIS. I have this map (see below) which I need to run a filter over to make the red areas a bit more dominant. I know I can use r.mapcalc but I'm just not sure of the formula.

alt text

share|improve this question
up vote 8 down vote accepted

The GRASS equivalent of a majority filter can be computed with the r.neighbors command (help page). To get a simple majority filter, something like this should work, using a 3x3 window:

r.neighbors input=input_layer output=majority_filtered_output method=mode size=3

But r.neighbors supports many other options in addition to this. Depending on what you're trying to accomplish, you could also do this by taking the values of interest and classifying them into a new raster, then perform r.grow on the raster, and merge that result back into your dataset.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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