# Continuous smoothing of raster using R?

I have a dataset on some villages like this on a grid: I want to fill the space of the whole grid so that each grid cell has a value that reflects the pressure from the surrounding villages (i.e., the value would be something like average distance to all villages, weighted by the size of each village).

As a first attempt, I tried to smooth it with:

``````    villageRaster <- focal(villageRaster, w=matrix(1, 9, 9), mean)
``````

to give: But there are still large white areas with no values.

Can someone suggest a nice way to smooth across the whole space?

I am using R for this preferably.

• It seems that you are more looking for inverse distance interpolation. You should extract your village positions and use them as SpatialPointsDataFrame, from which you will be able to do idw on your raster grid. Oct 16 '17 at 17:37
• Even if you do not care about 3D interpolation, you can have a look at this question: stackoverflow.com/questions/43240915/… However, you will need to define how you weight your interpolation considering the size of the village. Maybe with the idp? Oct 17 '17 at 6:17

You could look into this approach as suggested Smoothing raster map using R?:

Here are some ideas.

With base plot you can do

`````` plot(x, interpolate=TRUE)
``````

You can also resample your data using disaggregate (x, 5, method='bilinear')

`````` y <- disaggregate x, 5, method='bilinear')
``````

Or indeed smooth it using a focal operation

`````` y <- focal(x, w=matrix(1, 5, 5), mean)
``````

Or a combination

`````` y <- disaggregate(x, 5)
y <- focal(y, w=matrix(1, 5, 5), mean)
``````

The question whether doing this is a good idea or not is another matter, that I'll leave to you to decide

• Yeah I did try that (actually I mention I did that in my question!) but it is not sufficient. Thanks though. Oct 11 '17 at 13:22