Python - TypeError: coercing to Unicode: need string or buffer, int found

 
Vista:

TypeError: coercing to Unicode: need string or buffer, int found

Publicado por Cristian Q (1 intervención) el 04/07/2019 23:41:03
Mi objetivo es aplicar una ecuación píxel por píxel entre dos ráster para obtener un ráster de salida que me permita visualizar la factibilidad de cultivar en un área de estudio. Hizo dos bucles 'for' para pasar por dos listas de rásteres, ya que el estudio incluye 52 semanas de estudio, es decir, cada lista contiene 52 rásteres. El problema y el error que muestro se presentan al final del código cuando declaro 'i = i + 1':

line 51, in <module>
TypeError: coercing to Unicode: need string or buffer, int found

Failed to execute (Matlab).

El código es el siguiente:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import arcpy, glob, numpy, os
from arcpy.sa import *
 
arcpy.CheckOutExtension('Spatial')
 
carpeta_in1 = arcpy.GetParameterAsText(0)
carpeta_in2 = arcpy.GetParameterAsText(1)
carpeta_out = arcpy.GetParameterAsText(2)
 
 
Kr = 0.75
Ke = 0.8
Kc = 1
 
# Genera una lista de todos los archivos .asc
EVP = glob.glob(os.path.join(carpeta_in1, "*.tif"))
PPT = glob.glob(os.path.join(carpeta_in2, "*.tif"))
 
i=1
j=1
 
for i in EVP:
    for j in PPT:
 
        ras_evap = Raster(i)
        ras_ppt = Raster(j)
        arr1 = arcpy.RasterToNumPyArray(ras_evap,nodata_to_value=-9999)
        arr2 = arcpy.RasterToNumPyArray(ras_ppt,nodata_to_value=-9999)
 
        MatLab = (((Kc*arr1)-(Ke*arr2))*30*30)/(1000*Kr)
 
        outname = os.path.join(carpeta_out, os.path.basename(i).split(".")[0] + ".tif")
 
        newRaster = arcpy.NumPyArrayToRaster(MatLab,value_to_nodata=-9999)
 
        newRaster.save(outname)
 
        i = i+1
        j = j+1
 
    break
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder