[R] ordinary kriging: the edges of the polygons are ignored

Federico Calboli f.calboli at imperial.ac.uk
Thu Aug 21 15:30:06 CEST 2014


Hi Jon,

thanks for your reply — it solves my issues completely.

Best

F



On 21 Aug 2014, at 07:58, Jon Skoien <jon.skoien at jrc.ec.europa.eu> wrote:

> 
> Hi Frederico,
> 
> The kriging function seems to come from the kriging package (please give also the package next time you ask a question), which I dont know. I can therefore not tell you why it does not give you the correct result. But R has a huge number of packages which can krige, and autoKrige from automap should fairly easy be able to give you what you want. 
> 
> # You have to create a SpatialPolygon of your house first, from which you can sample:
> pts = cbind(house$x, house$y)
> pts = rbind(pts, pts[1,]) # Repeating the first coordinates, just to close the polygon
> house2 = SpatialPolygons( list( Polygons(list(Polygon(pts)), 1)))
> housegrid = spsample(house2, 10000, "regular") # Sampling 10000 points on a regular grid
> gridded(housegrid) = TRUE # Defining this to be a grid, not a collection of points
> 
> # You need to make a SpatialPointsDataFrame of your temperature data, and then you can interpolate
> coordinates(U) = ~x+y
> res = autoKrige(temp~1, U, housegrid)
> spplot(res$krige_output, col.regions = rev(heat.colors(100)))
> # Your result is in the var1.pred-variable of res$krige_output
> 
> You will generally get more and quicker answers to questions about spatial data and methods from the r-sig-geo list.
> 
> Best wishes,
> Jon
> 
> 
> On 8/20/2014 11:01 PM, Federico Calboli wrote:
>> Hi All,
>> 
>> I am trying to do some kriging of a floor, based on a number of heat sensors.
>> 
>> My data looks like this:
>> 
>>    sensor        temp    x    y
>> 1       1  1.25437406  390 2960
>> 2       2  0.64384594  830 2960
>> 3       3  1.52067733 1420 2960
>> 4       4  1.21441928 3127 2920
>> 5       5  1.04227694 4005 2920
>> 6       6  1.90084852  400 1960
>> 7       7  1.58530250  835 1880
>> 8       8  1.23060971 1130 1960
>> 9       9  0.92749453 1550 1950
>> 10     10  0.76638878 1995 1960
>> 11     11  0.84247092 2540 1950
>> 12     12  0.93999929 3300 1880
>> 13     13  0.61610170 4000 1870
>> 14     14  1.06967332  395 1330
>> 15     15  0.72970917  845 1330
>> 16     16  0.60216970 1135 1300
>> 17     17  0.44648551 1570 1275
>> 18     18  2.49863724 2010 1290
>> 19     19  0.71619206 2540 1320
>> 20     20  1.50984666 3140 1275
>> 21     21 -0.06540552 4000 1258
>> 22     22  1.20017747  400  685
>> 23     23  1.05820693 1575  640
>> 24     24  2.25086655 1830  625
>> 25     25  0.69296059 3120  625
>> 26     26  0.69324786 3990  605
>> 
>> and the floor plan describes the edges of the floor thus:
>> 
>>       x    y
>> 1   210 3200
>> 2   210  420
>> 3  1510  420
>> 4  1510  100
>> 5  4090  100
>> 6  4090 3200
>> 7  2947 3200
>> 8  2947 2850
>> 9  1647 2850
>> 10 1647 3200
>> 11  210 3200
>> 12  210 3200
>> 
>> I run these commands:
>> 
>> house2 <- list(data.frame(house$x, house$y))
>> plot(house.y ~house.x, type = 'l', house2[[1]])
>> points(U[,3], U[,4], pch = 20)
>> housekrig=kriging(U[,3],U[,4],U[,2],polygons=house2,lags = 5) 
>> image(housekrig, xlim = extendrange(U[,3]), ylim = extendrange(U[,4]), col = rev(heat.colors(100)))
>> 
>> and I noticed that the kriging area does not respect the floor plan.  In fact, if I do:
>> 
>> points(U[,3], U[,4], pch = 20)
>> 
>> the sensors and not in the same place, and the kriging has ignored the edges of the polygons altogether.
>> 
>> So my question is, how do I have a kriging of the *whole* surface, based on my sensors?  Any suggestion is welcome, especially if the data does not require reformatting (or if the reformatting is straightforward)!
>> 
>> Best
>> 
>> F
>> 
>> PS I have contacted the maintainer of the package about the issue but I had no reply, and I’d need to solve this one way or another sooner, rather than later.
>> 
>> 
>> 
>> 
>> 
>> ______________________________________________
>> 
>> R-help at r-project.org
>>  mailing list
>> 
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> 
>> PLEASE do read the posting guide 
>> http://www.R-project.org/posting-guide.html
>> 
>> and provide commented, minimal, self-contained, reproducible code.
>> 
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20140821/78983425/attachment.bin>


More information about the R-help mailing list