I want to do a neigbourhood analysis on some raster data. I need to know how big a circle around each raster cell must be to include a certain amount of specified raster cells.
Let's say that for both rasters I want to know the radius of the circle needed to reach an aggregated value of 5. In the first case the "circle" must have a radius of 2 to reach the sum of the desired 5 because a radius of 1 would only include one raster cell that I am interested in. In the second case already a smaller circle with a radius of 1 is sufficient. My outcome should thus be a raster file where every cell has the value of the radius that is needed to reach that defined sum.
I was thinking a long time about a good title for this question. I would welcome better suggestions.
Answer
The answer to your question depends on the scale of your raster and if you want a unique raster "buffer" for the whole layer or per grid cell. For the first choice: The best way on QGIS might be to use the r.neighbors
GRASS plugin inside the Processing toolbox for QGIS 2.0.
See a the manual here: http://grass.osgeo.org/grass65/manuals/r.neighbors.html
To do what you want you might have to build a little model in Processing, but maybe there is an easier way. The general Idea:
- Insert your raster, start the r.neighbors tool and with a size of 3 and obviously sum as method.
- The generated resulting raster will contain the sum of the neighborhood for each grid cell in a 3x3 distance matrix. Use the QGIS Rastercalculator to extract all cell smaller than 5 (like this
RasterLayerName@1 < 5
). - Count the name of cells inside the resulting raster (using raster stats). There is a function somewhere in Processing as well.
- If the number of cells is equal to zero you succeeded and have found your global adequate buffer size. If not than go back to Step 1 and increase the size
No comments:
Post a Comment