Bug report #14608

Processing: Kriging rscripts/Kriging.rsx Automap problem and correction

Added by Martin Laloux 12 months ago. Updated 12 months ago.

Status:Closed Start Date:04/03/2016
Priority:Normal Due date:
Assigned to:Victor Olaya % Done:

0%

Category:Processing/R
Target version:Version 2.14
Platform:Mac OS X Pull Request or Patch supplied:No
Platform version:10.10.5 (Yosemite) Affected version:2.14.0
Status info: Causes crash or corruption:No
Resolution: Tag:

Description

There is a problem with

kriging_result = autoKrige(A~1, Mesure, Grille,model=c("Cir","Lin","Bes","Wav","Hol","Leg","Per","Pen","Mat","Exc","Spl","Ste"))
library(raster)
result<-raster(prediction)
Output<-result

1) prediction is not defined in the script
2) if prediction == kriging_result then with automap, you need prediction = raster(kriging_result$krige_output)

The solution is

library(raster)
prediction raster(kriging_result$krige_output)
Output<-prediction

History

Updated by Martin Laloux 12 months ago

A script that works, without the not required package (gstats, rgl, ....)

##Basic statistics=group
##showplots
##Layer=vector
##Field=Field Layer
##by=number 0.1
##Output=output raster
library(automap)
library(raster)
Y<-as.factor(LayerField)
attribut<-as.data.frame(Y)
A<-as.numeric(Y)
for(j in (1:length(levels(Y))))
for(i in 1:dim(attribut)[1]){
if (attribut[i,1]==levels(Y)[j]){
A[i]=j
}
}
coords<-coordinates(Layer)
MinX<-min(coords[,1])
MinY<-min(coords[,2])
MaxX<-max(coords[,1])
MaxY<-max(coords[,2])
Seqx<-seq(MinX, MaxX, by=by)
Seqy<-seq(MinY, MaxY, by=by)
MSeqx<-rep(Seqx, length(Seqy))
MSeqy<-rep(Seqy, length(Seqx))
MSeqy <- sort(MSeqy, decreasing=F)
Grille <- data.frame(X=MSeqx, Y=MSeqy)
coordinates(Grille)=c("X","Y")
gridded(Grille)<-TRUE
Mesure<- data.frame(LON=coords[,1], LAT=coords[,2],A)
coordinates(Mesure)<-c("LON","LAT")
variogram = autofitVariogram(A~1, Mesure)
plot(variogram)
kriging_result = autoKrige(A~1, Mesure, Grille,model=c("Cir","Lin","Bes","Wav","Hol","Leg","Per","Pen","Mat","Exc","Spl","Ste"))
prediction = raster(kriging_result$krige_output)
Output<-prediction

Updated by Victor Olaya 12 months ago

  • Status changed from Open to Closed

Also available in: Atom