I have a list of rasters, created by arcpy
using ListRasters
. Rasters are stored in a geodatabase. How can I subset only one raster of the raster list? The goal is to make a new list, but containing only one raster file.
Ultimate goal is to loop through list of rasters and calculate Area solar radiation
for each one of them. But, but for learning/training purposes I wish to explore my parameters only on single raster for now. (I know I can read-in just single raster, but I thought that subsetting might be easy as well?)
I have thought that I can simply subset the element by the index value, but this seems not working in arcpy
. Any advices? I think I am missing something very obvious...
import arcpy, os
# Set working environment
arcpy.env.workspace = os.path.join(inWD, "output/bufRastTwins.gdb")
# List all rasters with defined name wildcard: r_1, r_2, r_3.. to r_100
allRasters = arcpy.ListRasters("r_*")
# Select the first raster from the rasters list
myRasters = allRasters[0]
print myRasters
My attempt leads to loop through raster name, not throught the subsetted raster itself:
print myRaster:
r_1 # first element succesfully created
but for raster in myRasters:
print raster # this is obviously wrong
r
_
1
arcpy.ListRasters
is only returning a list containing "raster names in the workspace". Extracting the first element of this list is only giving you the first raster name within the specified workspace. With it you can do something likeos.path.join(inWD, "output/bufRastTwins.gdb", allRasters[0]
to hae the full path plus name of your raster and use this as your input for further analysis.