波段合成
这是个大坑,目前我没有找到好的解决办法
它是什么问题呢?就是arcgis中的波段合成,生成的是临时图层,需要手动导出
虽然帮助中给了波段合成的代码,但至少对于我来说,是根本无法实现!!!生成的临时图层根本无法转成栅格文件进行存储
import arcpy
from arcpy import env
from arcpy.sa import *
import os
arcpy.CheckOutExtension("spatial")
arcpy.gp.overwriteOutput = 1
env.workspace = "d:/"
for month in range(1, 13):
print("y2010m" + str(month))
Month1 = "y20101m" + str(month).zfill(2)
Month2 = "y20102m" + str(month).zfill(2)
#我发现可能是因为根本就没有输出路径这个参数
DirMonth_result = "y2010m" + str(month).zfill(2)
m1 = Raster(os.path.join('H:/y20101.gdb', Month1))
m2 = Raster(os.path.join('H:/y20102.gdb', Month2))
list = [m1, m2]
arcpy.CompositeBands_management(list,
"compbands" + str(month).zfill(2) + ".tif")
#同样的还有波段提取,一样的找不到提出来的东西在哪里,一把子无语了
```python
import arcpy
from arcpy import env
from arcpy.sa import *
import os
arcpy.CheckOutExtension("spatial")
arcpy.gp.overwriteOutput = 1
for year in range(2001, 2002):
# H:\jieguo\y2001\wet.gdb
for month in range(1, 2):
print(str(year) + str(month))
env.workspace = "H:/PCAtif"
# rasterpath = "pcay" + str(year) + "m" + str(month).zfill(2) + ".tif"
rasterpath = r"H:\PCAtif\pcay2001m01.tif"
# H:\jieguo\pca_band1
savepath = os.path.join("H:/pca_band1/band1_y" + str(year) + "m" + str(month).zfill(2) + ".tif")
arcpy.MakeRasterLayer_management(rasterpath, savepath, "#", "#", "1")
波段提取倒是解决了,不需要手动提取,因为我从源头上解决的问题:把需要的图层直接只选择了输出那一个图层,就不用再提取了
每天都在菜鸡流泪/(ㄒoㄒ)/