ListRasters

Summary

The ListRasters function returns a list of the rasters in the current workspace.

Discussion

The workspace environment must be set before using several of the list functions, including ListDatasets, ListFeatureClasses, ListFiles, ListRasters, ListTables, and ListWorkspaces.

Syntax

ListRasters ({wild_card}, {raster_type})
ParameterExplanationData Type
wild_card

Limits the results returned. If a value is not specified, all values are returned. The wildcard is not case sensitive.

SymbolDescriptionExample

*

Represents zero or more characters.

Te* finds Tennessee and Texas.

String
raster_type

Specifies the raster type that will be used to limit the results. The following are valid raster types:

  • BMPBitmap graphic raster dataset format will be used.
  • GIFGraphic Interchange Format for raster datasets will be used.
  • IMG ERDAS IMAGINE raster data format will be used.
  • JP2JPEG 2000 raster dataset format will be used.
  • JPGJoint Photographics Experts Group raster dataset format will be used.
  • PNG Portable Network Graphics raster dataset format will be used.
  • TIFTagged Image File for raster datasets will be used.
  • GRID Grid data format will be used.
  • AllAll supported raster types will be used. This is the default.

(The default value is All)

String
Return Value
Data TypeExplanation
String

The list returned from the function containing raster names in the workspace, optionally limited by the wild_card and raster_type arguments.

Code sample

ListRasters example

List Grid raster names in the workspace.

import arcpy

# Set the current workspace
arcpy.env.workspace = "c:/data/DEMS"

# Get and print a list of GRIDs from the workspace
rasters = arcpy.ListRasters("*", "GRID")
for raster in rasters:
    print(raster)

Related topics