python - Assign Raster band to variable name in Loop - "can't assign" error -
i want write 2 nested loops iterate on rgb bands of series of 8 jpg images. later on these images shall combined 1 array channel channel, each array of channels first has have proper name:
for colorband in [1, 2, 3]: eighth in range(0,8): rastername="20140525-16-20-00_full_"+str(eighth)+"_0.jpg" raster =gdal.open(rastername) band = raster.getrasterband(colorband) "eighth_"+str(eighth)+"_"+colorband = band.readasarray()
unfortunately, returns "can't assign function call" error. couldn't find proper answer how solve in other questions. can help?
the error in line:
"eighth_"+str(eighth)+"_"+colorband = band.readasarray()
it appears trying create variable name , assign result of band.readasarray()
.
you create dictionary, color_dict
, make "eighth_"+str(eighth)+"_"+colorband
key , use assign value of band.readasarray()
. i.e.,
color_dict = {} color_dict["eighth_"+str(eighth)+"_"+colorband] = band.readasarray()
later in code can access data color_dict["eighth_"+str(eighth)+"_"+colorband]
Comments
Post a Comment