Geographic Information Systems Asked on September 29, 2021
How do I get a list of band names using ArcPy in ArcGIS Desktop 10.x?
In ArcGIS Pro, I can use Raster('myRaster').bandNames
, but this is not an option in ArcGIS 10.x and I cannot seem to figure out how to access band names.
If you want the band names you can set arcpy.env.workspace
to the raster, then use arcpy.ListRasters()
to list the bands, here's an example wrapped up into a function:
import arcpy
def get_bands(path_to_raster):
""" Get a list of band names from a multiband raster """
# Save previous workspace
oldws = arcpy.env.workspace
#Get raster objects from band names
arcpy.env.workspace = path_to_raster
bands = arcpy.ListRasters()
#Restore previous workspace
arcpy.env.workspace = oldws
return bands
Or if you want the full path:
import os
import arcpy
def get_bands(path_to_raster):
""" Get a list of band names from a multiband raster """
# Save previous workspace
oldws = arcpy.env.workspace
#Get raster objects from band names
arcpy.env.workspace = path_to_raster
bands = [os.path.join(path_to_raster, b) for b in arcpy.ListRasters()]
#Restore previous workspace
arcpy.env.workspace = oldws
return bands
If you don't actually care what the band names are and want to access a raster band by index (band number), use arcpy.MakeRasterLayer_management
arcpy.MakeRasterLayer_management(input_raster, "lyr_band3", band_index="3")
Answered by user2856 on September 29, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP