[英]Assign Raster band to variable name in Loop - “can't assign” error
I want to write two nested loops that iterate over the RGB bands of a series of eight JPG images. 我想编写两个嵌套的循环,这些循环在一系列八个JPG图像的RGB波段上进行迭代。 Later on these images shall be combined into one array channel by channel, so each array of the channels first has to have a proper name:
稍后,这些图像应逐通道合并为一个阵列,因此通道的每个阵列首先必须有一个专有名称:
for ColorBand in [1, 2, 3]:
for 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, this returns a "can't assign to function call" error. 不幸的是,这将返回“无法分配给函数调用”错误。 I couldn't really find a proper answer how to solve this in other questions.
在其他问题上,我找不到真正的解决方法。 Can anyone help?
有人可以帮忙吗?
The error is in the line: 错误在该行中:
"eighth_"+str(eighth)+"_"+ColorBand = band.ReadAsArray()
It appears that you are trying to create a variable name and assign to it the result of band.ReadAsArray()
. 看来您正在尝试创建一个变量名称,并将结果分配给
band.ReadAsArray()
。
You could create a dictionary, say color_dict
and make "eighth_"+str(eighth)+"_"+ColorBand
as the key and use it to assign the value of band.ReadAsArray()
. 您可以创建一个字典,说出
color_dict
并将"eighth_"+str(eighth)+"_"+ColorBand
用作键,并使用它来分配band.ReadAsArray()
的值。 ie, 即
color_dict = {}
color_dict["eighth_"+str(eighth)+"_"+ColorBand] = band.ReadAsArray()
Later in your code you can access this data as color_dict["eighth_"+str(eighth)+"_"+ColorBand]
稍后,您可以在代码中以
color_dict["eighth_"+str(eighth)+"_"+ColorBand]
访问此数据
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.