qgis-processing-r icon indicating copy to clipboard operation
qgis-processing-r copied to clipboard

UnicodeDecodeError

Open fgianoli opened this issue 1 year ago • 1 comments

I am working with QGIS 3.32.0-Lima on Windows 11. I am trying to port an R script to QGIS by creating an R script.

However, when I run it, I get an encoding error that I can't understand:

Traceback (most recent call last): File "C:\Users/giano/AppData/Roaming/QGIS/QGIS3\profiles\SGI/python/plugins\processing_r\processing\algorithm.py", line 396, in processAlgorithm output = RUtils.execute_r_algorithm(self, parameters, context, feedback) File "C:\Users/giano/AppData/Roaming/QGIS/QGIS3\profiles\SGI/python/plugins\processing_r\processing\utils.py", line 281, in execute_r_algorithm for line in iter(proc.stdout.readline, ''): File "C:\OSGeo4W\apps\Python39\lib\codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 21: invalid continuation byte Execution failed after 37.93 seconds

The code I am using is as follows, and I have two input rasters, one with Integer values and the other is float.

In fact, the objective is to perform zonal statistics between rasters by calculating the median of the values of raster A for each class of raster B (which the "Raster Layer Zonal statistics" tool does not do) and then reclassify the values of raster A based on the calculated value.

##My scripts=group

##LC=raster
##issue=raster
##output= output raster

library(raster)
library(sf)
library(sp)

x<-resample(issue,LC, method='ngb')
issue <-x

issue <- crop(issue, extent(LC))  
res(issue) <- res(LC)
extent(issue) <- extent(LC)
 
s<- issue
r<- LC
result <- zonal(s, r, 'median')

r2 <- reclassify(r, result)


rc <- function(x) {
 
  x1 <- x[1] 
  x2 <- x[2] 
  ifelse(x1 <=  x2, 0,
  ifelse(x1 >  x2, 1, NA)) }

s2 <- stack(s,r2)

beginCluster(6) 
z1 <- clusterR(s2, calc, args=list(fun=rc))
endCluster()

output<- z1

Is this a an error on the code or a bug?

fgianoli avatar Jul 25 '23 10:07 fgianoli

Would it be possible to run the algorithm in R and post here the output of the algorithm from R console (in R Studio or whatever IDE you use)?

It seems that python has some issues with decoding some of R output lines. But that should not really happen...

JanCaha avatar Aug 05 '23 21:08 JanCaha