Does anyone know an equivalent package for the velox package for fast zonal statistics in R? This package was by far the best performing tool when working with large raster objects but has been recently removed from CRAN...

  • You can still install it from the source code on github - or at least try, assuming its not come off CRAN because it doesn't work.
    – Spacedman
    Jun 1, 2020 at 7:54

2 Answers 2


I have moved to using the exact_extract function in the exactextractr package. One nice thing is that it returns all cell intersections with the fractional proportion of each cells intersection. You could use the proportion of intersection column as weights or to filter out small intersections.

Also, there are numerous statistics available, including some weighted ones, that are part of the C++ code, so very fast. The package takes sf class polygons and raster class raster data.


You can use the mmand package


#random sampling points:

pts <-  readOGR(
  dsn = ".",
  layer = "random_points",
  encoding = "utf8")

pts$id <- as.numeric(pts$id)

pts <- as.data.frame(pts)


r1 = raster("G:/romain/imperviousness_project/SWI.tif")

#Let's rasterize the points based on their x y coordinates:

z <- rasterize(pts[,2:3], r1, field = pts$id)

#I want to get statistic from a zone of 3*3 pixels around my point (in my example 1 pixel = 5 meters so the total area is 15m2):

kern <- shapeKernel(c(3,3), type="box")
z[,] <- dilate(as.matrix(z), kern)


zonal(r1, z, fun = "mean")

It is also mentionned here: https://stackoverflow.com/questions/50398473/how-to-perform-focal-operation-mean-on-raster-using-3x3-window-in-r-i-have-la

  • 1
    Do you understand what the mmand package is actually doing here? The shapeKernel and dialate functions are from mmand and are just used in creating a 3x3 matrix around each point that is then rasterized and passed to the raster::zonal function. In this case the mmand package has very little to do with calculating zonal statistics and is completely irrelevant outside of the point example (ie., cannot be expanded to polygons). This also creates a huge amount of unnecessary overhead and would be massively slower than just using raster::extract. Jun 1, 2020 at 14:55
  • Ok sorry I didn't know, I only used it once for points ! My bad !
    – wanderzen
    Jun 1, 2020 at 15:15
  • No worries, live and learn. Jun 1, 2020 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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