Buongiorno a tutti,
sto lavorando con QGIS 3.32.0-Lima su Windows 11.
Sto cercando di fare il porting di uno script di R su QGIS creando un R script (https://docs.qgis.org/3.28/en/docs/user_manual/appendices/qgis_r_syntax.html)
Se lo faccio girare però ottengo un errore di enconding che non colgo:
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
Il codice che sto usando è il seguente e ho due raster in ingresso, uno con valori Integer e l’altro è float.
Di fatto l’obiettivo è di fare delle statistiche zonali tra raster calcolando la mediana dei valori del raster A per ciascuna classe del raster B (cosa che il tool “Raster Layer Zonal statistics” non fa) e riclassifica i valori del raster A in funzione del valore calcolato.
##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] ##valore pixel della prima banda
x2 ← x[2] ##valore pixel 2 banda
ifelse(x1 <= x2, 0,
ifelse(x1 > x2, 1, NA)) }
s2 ← stack(s,r2)
beginCluster(6) ##ASSIGN CORE
z1 ← clusterR(s2, calc, args=list(fun=rc))
endCluster()
output<- z1
Qualcuno ha avuto problemi simili di encoding o di script R su QGIS?
Grazie mille
Federico