Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wonder if there is a way to interpolate xyz points in a raster within certain bounds using R? In ArcGIS this is called interpolation with barriers. I wonder if there is something similar in R? I would like to use the kriging method.

share|improve this question
xyz points? Are your data measurements in three dimensions? Or is it xy position and measurement z? – Spacedman Sep 18 '12 at 6:43
In this book there is very nice explanation of how to use R to preform a Kriging, maybe it have the answers you need. – Alexandre Neto Sep 18 '12 at 11:46
Linking related question:… – Andre Silva Apr 3 '15 at 16:30

Soap-film smoothing using GAM's may work for you.

Powerpoint on method

R Package download (you will need both the soap and mgcv packages)

share|improve this answer

You can use the gdistance package to create a cost surface raster, then use the shortestPath function to compute the distances between all your data points. You then need to do your interpolation using that distance matrix as your distance metric and not pythagoras. I think gstat will let you feed in a distance matrix for kriging.

You'll probably also need to use shortestPath to compute the distances between your data points and the grid points for your interpolated grid when you come to compute the mean and variance of your kriging estimates over your space.

Assuming this is really two-dimensional...

There was a thread on R-sig-geo in 2010 that is relevant and there was a solution using GRASS to compute the distances and a modified geoR to do the kriging:

share|improve this answer
+1 This is a clever and powerful method. Note, however, that it differs from kriging with barriers (and will get different results), and so might not be a universal substitute for kriging with barriers. Not only that, you should make sure to estimate the variogram using the same method: applying a variogram derived from Euclidean distances to a different distance function is not valid. Moreover, the algorithm is limited: not only do you need the distance matrix for the data points, you also need all distances between interpolation points and data points (that can be a huge number). – whuber Sep 18 '12 at 19:51
What is kriging with barriers if not what I thought it was? – Spacedman Sep 18 '12 at 20:08
What did you think it was, precisely? As implemented by the other Spatial Analyst interpolation techniques, interpolation with "barriers" means that one or more polylines are used to exclude points from local neighborhood searches. The method you describe here potentially keeps those points within the neighborhoods but extends their distances. That will change the interpolated values. – whuber Sep 18 '12 at 20:20
Are those points included in any other part of the process? Its not just clipping out points inside the barrier regions? – Spacedman Sep 18 '12 at 20:36
True. The real fail here is untrained operators sticking their data into plug-in software without thought to what they are actually doing. Which is what a lot of proprietary statistical solutions advertise. – Spacedman Sep 18 '12 at 21:09

Please check out the constrainedKriging package. According to the description:

The package supplies functions for two-dimensional spatial interpolation by constrained,covariance-matching constrained and universal (external drift) kriging for points or block of any shape for data with a nonstationary mean function and an isotropic weakly stationary variogram.

share|improve this answer
This is an interesting package, but it does not address the question: it has no capability to utilize barriers. One of its abilities is to predict average values within arbitrary polygons, but this is not at all the same thing as using barriers to restrict the local neighborhood searches. – whuber Sep 17 '12 at 14:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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