1

I'm trying to work with the R Kriging script in QGIS (processing toolbox). I have installed R before directly to C:. I also have installed the packages raster, rgdal, sp and automap. When I'm starting the script I always get the following message:

options("repos"="http://cran.at.r-project.org/") .libPaths("C:/R/R-3.2.4revised/library") tryCatch(find.package("automap"), error=function(e) install.packages("automap", dependencies=TRUE)) [1] "C:/R/R-3.2.4revised/library/automap" tryCatch(find.package("raster"), error=function(e) install.packages("raster", dependencies=TRUE)) [1] "C:/R/R-3.2.4revised/library/raster" tryCatch(find.package("rgdal"), error=function(e) install.packages("rgdal", dependencies=TRUE)) [1] "C:/R/R-3.2.4revised/library/rgdal" tryCatch(find.package("raster"), error=function(e) install.packages("raster", dependencies=TRUE)) [1] "C:/R/R-3.2.4revised/library/raster" library("raster") Fehler: Paket 'sp' benötigt von 'raster' nicht gefunden

2

Use the corrected script Bug report #14608: Processing: Kriging rscripts/Kriging.rsx Automap problem and correction, accepted in the master (Kriging.rsx)

It is not a problem of QGIS, it is a problem with you R packages installation.

1) Processing use the Python subprocess module to execute directly the R commands
2) it use an intermediate file named /.../.qgis2/processing/processing_script.r and the results or errors in the file /.../.qgis2/processing/processing_script.r.Rout

The interface

enter image description here

If you look at the resulting processing_script.r, it is possible to see that it uses rgdal to open the file and save the resulting files, transformed by raster

...
library("raster")
library("rgdal")
Layer = readOGR("path to",layer="Leontot") -> the chosen file
Field="DIP_DIR" -> the chosen field 
by=100 -> the mesh size
....
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
writeRaster(Output,"/var/folders/k9/7s3l5fvd5g1dy31b6sms18fr0000gn/T/processinga3894c34cc084250849b9dba9fe06856/f61b07d41ae54f72bb8d4e1298939fe4/Output.tif", overwrite=TRUE)

Threfore:

  1. you can examine the error in the file /.../.qgis2/processing/processing_script.r.Rout
  2. or you can directly use R or RStudio to execute this file and control the errors (why raster cannot find sp)

    R processing_script.r

New

as.factor(LayerField) : Objekt LayerField nicht gefunden Ausführung angehalten = as.factor(LayerField): object LayerField not found execution suspended

You should not modify the original processing_script.r script but run it in R.

The correct command is

Y<-as.factor(Layer[[Field]])

If I use RStudio to control the script:

Layer = readOGR("path_of",layer="sud_for_automap")
# the field chosen in the interface (Field) 
Field="DIP_DIR"
# the values in the field
Layer[[Field]]
[1] 156 154 173 158 163 160 147 160 185 185 160 160 160 165 155 162 164 154 163 165  
[21] 160 162 184 180 175 168 170 172 164 168 165 178 152 175 169 173 165 187 168 168
 ....

It is the same as

 Layer$DIP_DIR
 [1] 156 154 173 158 163 160 147 160 185 185 160 160 160 165 155 162 164 154 163 165
 [21] 160 162 184 180 175 168 170 172 164 168 165 178 152 175 169 173 165 187 168 168
 .....
  • So I changed the library folder to "C:\Users\xxxx\.qgis2\processing\rlibs" and the script works...but unfortunately with another error: "......RPLOTS.html.png") library(automap) library(raster) Y Fehler in as.factor(LayerField) : Objekt 'LayerField' nicht gefunden Ausführung angehalten Converting outputs Loading resulting layers The following layers were not correctly generated. Output You can check the log messages to find more information about the execution of the algorithm" – Pimpel Apr 16 '16 at 13:07
  • Look above ---- – gene Apr 17 '16 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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