Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeDecodeError #123

Open
fgianoli opened this issue Jul 25, 2023 · 1 comment
Open

UnicodeDecodeError #123

fgianoli opened this issue Jul 25, 2023 · 1 comment

Comments

@fgianoli
Copy link

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?

@JanCaha
Copy link
Collaborator

JanCaha commented Aug 5, 2023

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants