Bug report #14669
Processing: Kriging rscripts/Kriging_with_model_selection.rsx problem with solution
Status: | Rejected | ||
---|---|---|---|
Priority: | Normal | ||
Assignee: | Victor Olaya | ||
Category: | Processing/Core | ||
Affected QGIS version: | 2.14.0 | Regression?: | No |
Operating System: | Easy fix?: | No | |
Pull Request or Patch supplied: | No | Resolution: | invalid |
Crashes QGIS or corrupts data: | No | Copied to github as #: | 22633 |
Description
As in Kriging.rsx (Bug report #14608), I don't understand why you import here the libraries rgl, spatstat, maptools, pls unused
(only gstats, automap and raster)
The basic solution (with plotting of the variogram) is:
#Basic statistics=group
##showplots
##Layer=vector
##Field=Field Layer
##Selection=Selection Exp;Log;Sph;Gau;Exc;Mat;Cir;Lin;Bes;Pen;Per;Wav;Hol;Leg;Ste
##by= number 0.1
##Output=output raster
library(gstat)
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)
Mesure<- data.frame(LON=coords[,1], LAT=coords[,2], A)
coordinates(Mesure)<-c("LON","LAT")
Models<-c("Exp","Log","Sph","Gau","Exc","Mat","Cir","Lin","Bes","Pen","Per","Wav","Hol","Leg","Ste")
Selection<-Selection+1
select_model<-Models[Selection]
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
v<-autofitVariogram(A~1,Mesure,model = select_model)
plot(v)
prediction <-krige(formula=A~1, Mesure, Grille, model=v$var_model)
result<-raster(prediction)
proj4string(Layer)->crs
proj4string(result)<-crs
Output<-result
But you can use directly gstat for the variogram (as in
History
#1 Updated by Alexander Bruy over 8 years ago
- Resolution set to invalid
- Status changed from Open to Rejected
This should be submitted against QGIS-Processing repository where corresponding script live.
#2 Updated by Giovanni Manghi over 7 years ago
- Regression? set to No
#3 Updated by Giovanni Manghi over 7 years ago
- Easy fix? set to No
#4 Updated by Giovanni Manghi over 7 years ago
Some providers are being removed from QGIS/Processing (will be available as plugin) and so are their categories in the bug tracker. To not leave them orphaned of a category they are being reassigned to processing/core.
#5 Updated by Giovanni Manghi over 7 years ago
- Category changed from 124 to Processing/Core