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:\Radiance\B1.tif;D:\Radiance\B2.tif;D:\Radiance\B3.tif;D:\Radiance\B4.tif", "D:\CANGIO\Anh_SOPT5\Radiance\compbands.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?

  • Could you specify where you stuck and error messages that you receive? – fatih_dur Nov 27 '15 at 4:45
  • I did not any error messages, it works but i would like to shorten my code which created each new individual bands and a new raster. I just want to create only a new raster – user30985 Nov 27 '15 at 4:54
  • can you use in_memory location to save your band info? – Surya Nov 27 '15 at 14:16
1

As indicated in the comment by @Surya, I think the way to accomplish what you are describing (i.e. make the final raster the only one written to disk) is to use an in_memory workspace to write the intermediate bands:

Writing geoprocessing output to the in-memory workspace is an alternative to writing output to a location on disk or a network location.

...

data written to the in-memory workspace is temporary and will be deleted when the application is closed.

...

Tables, feature classes, and rasters can be written to the in-memory workspace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.