I am currently running a process that involves the creation of many "Focal Statistics" rasters in ArcGIS. These rasters use varying-radius circular search areas and calculate three different statistics: Mean, Sum, and Standard Deviation (depending on the input data source). They also must be created in a programmatic manner - either from Python, R, or Bash/Command Line.

I would like to move this to an open source alternative but am having trouble finding an open source equivalent to ArcGIS's "Focal Statistics". The raster::focal() function in R is terribly slow, and for the size of my data it will not work. SAGA GIS has the 'simple filter' tool, but that will only calculate the Mean, not the other two statistics.

Does anyone have an alternative that replicates the functionality of "Focal Statistics" in a reasonably fast, free, and programmatic manner with a circular search window?


For staying in R, take a look at the velox package. For performance, it has moved processing into C+, using Rcpp and the Boost Geometry libraries. Operations such as extract, focal, aggregation and rasterization benchmark notably faster than comparable raster package functions.

Unfortunately, it does not look like there is a focal standard deviation per se but, you could submit a development request through the GitHub page or, write a Rcpp function yourself and add it to the package.

  • 1
    Thank you, velox is the answer to some of my other unasked questions! I'll reach out to the devs and see if they plan on updating with other statistics. After some more investigation, I may just run this in GRASS from the command line with the --exec flag and r.neighbors. – Jackson Oct 17 '18 at 19:44
  • Hi Jackson- I have the same question (running focal stats using open source). Were you able to run GRASS? If so- how did you get it working? I want to run focal stats by calling grass from a stand along python script but haven't had luck calling it. There are a lot of resources online and I've followed all of them and keep dead ending. Any advice would be great, thanks! – Sam Dec 7 '18 at 15:32

Within GRASS GIS you can use r.neighbors which looks at each cell in a raster input file, and examines the values assigned to the cells in some user-defined "neighborhood" around it. It outputs a new raster map layer in which each cell is assigned a value that is some (user-specified) function of the values in that cell's neighborhood. Using the -c flag you can run a circular filter.

To call the functionality from outside, the grass-session Python package is interesting (usage example).

  • 1
    This answer led me to the rgrass7 package in R, which seems appropriate for my needs. Thank you! – Jackson Feb 3 at 0:17

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.