Thursday 20 June 2019

arcgis desktop - How to list raster bands?


I am interested in looping through a directory and listing only the red bands (Band 1) from 4-band NAIP imagery. From there I would like to mosaic all of the band 1 layers into a new single band raster image using Mosaic to New Raster. Is there a way to specify band 1 using arcpy.ListRasters() or should I find a new approach?




Answer



Try this:


import os
import arcpy
bands = []
arcpy.env.workspace = #Set path to dir
for r in arcpy.ListRasters():
rObject = arcpy.Describe(r)
band1 = os.path.join(rObject.catalogPath,"bandx") #bandx = name of band to extract
#outR = # full path to output raster

#arcpy.CompositeBands_management(band1,outR)
bands.append(band1)

#do mosaic here outside loop.

The Composite Bands tool allows you to pull out bands from a multi band image.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...