Tuesday, 24 February 2015

qgis - Raster generalization - buffers in rasters, expand pixels?


Is it possible to create buffers for pixels of raster files? Actually I need to expand the pixels classified as 1 (in white in the figure) with a spatial range of 1 or 2 pixels, in order to perform some generalization. I'm using QGIS, is this possible with gdal or something?


enter image description here




Answer



QGIS provides an interface to GRASS GIS, which started life as a raster GIS and therefore should provide some efficient tools to tackle this problem. Referring to its manual pages of raster commands we can find the following solutions:


r.buffer -- direct buffering of white cells.


r.cost -- can compute distances to white cells. Follow this with a comparison to select short-distance cells.


r.grow -- a local morphological operation designed specifically to expand white cells into their immediate neighbors.


r.mfilter -- a general focal filter. Various focal statistics, such as max, mean, sum, median, and standard deviation can detect the presence of white cells within local neighborhoods. Follow this with a comparison to select such cells.


r.neighbors -- an even more general focal filter, which can be used similarly to r.mfilter.


r.resample -- resampling onto a coarser grid is one way to expand the white cells. The result will be somewhat "blocky".


r.spread -- letting white cells "spread" into their neighborhoods will achieve the desired buffering.


We should expect r.buffer, r.grow, and perhaps r.mfilter to use the most efficient code. (I haven't tested these to find out.)



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...