Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

Writing only final raster with intermediate bands going to disk using ArcPy?

$
0
0

I have a raster with 4 bands.

I would like to create a new raster (its individual bands called new_band) from this raster (its individual bands called old_band) in with :

new_band1 = old_band1 * 2
new_band2= old_band2 * 4
new_band3= old_band3 * 6
new_band4 = old_band4 * 8

My code is:

import sys, os, math, time
import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("spatial")

raster = r"D:IMAGERY.tif"
bands = [['band1', 2], ['band2',4],['band3',6],  ['band4', 8]]
outfolder =r"D:Radiance"

for band in bands:
      num = band[0][4:]
      thisBand = raster + '\band_' + num
      Radiance = arcpy.sa.Float(Raster(thisBand)/float(band[1]))
      outname = 'B' + num + '.tif'
      Radiance.save(os.path.join(outfolder,outname))
#and then combine different bands
  arcpy.CompositeBands_management("D:RadianceB1.tif;D:RadianceB2.tif;D:RadianceB3.tif;D:RadianceB4.tif", "D:CANGIOAnh_SOPT5Radiancecompbands.tif")

In this code, I created both images for individual bands and a new raster.

As I just would like to create a new raster file, not rasters of individual bands, how can I do this?


Viewing all articles
Browse latest Browse all 767

Trending Articles