Raster files also contain descriptive information that can be returned by the Describe()
function.
A raster dataset can also be described through the use of the Describe()
function. In this recipe, you will describe a raster dataset by returning its extent and spatial reference. The Describe()
function contains a reference to the general purpose Dataset
properties group and also contains a reference to the SpatialReference
object for the dataset. The SpatialReference
object can then be used to get detailed spatial reference information for the dataset.
Follow these steps to learn how to obtain descriptive information about a raster image file.
C:ArcpyBookCh9DescribeRaster.py
.arcpy
module:import arcpy
arcpy.env.workspace = "C:/ArcpyBook/data "
try
block:try:
Describe()
function on a raster dataset:descRaster = arcpy.Describe("AUSTIN_EAST_NW.sid")
ext = descRaster.extent print("XMin: %f" % (ext.XMin)) print("YMin: %f" % (ext.YMin)) print("XMax: %f" % (ext.XMax)) print("YMax: %f" % (ext.YMax))
SpatialReference
object and print it out:sr = descRaster.SpatialReference print(sr.name) print(sr.type)
Exception
block:except Exception as e: print(e.message)
import arcpy arcpy.env.workspace = "c:/ArcpyBook/data" try: descRaster = arcpy.Describe("AUSTIN_EAST_NW.sid") ext = descRaster.extent print("XMin: %f" % (ext.XMin)) print("YMin: %f" % (ext.YMin)) print("XMax: %f" % (ext.XMax)) print("YMax: %f" % (ext.YMax)) sr = descRaster.SpatialReference print(sr.name) print(sr.type) except Exception as e: print(e.message)
C:ArcpyBookcodeCh9DescribeRaster.py
solution file.XMin: 3111134.862457 YMin: 10086853.262238 XMax: 3131385.723907 YMax: 10110047.019228 NAD83_Texas_Central Projected
This recipe is very similar to previous recipes. The difference is that we're using the Describe()
function against a raster dataset instead of a vector
feature class. In both cases, we've returned the geographic extent of the datasets using the extent object. However, in the script, we've also obtained the SpatialReference
object for the raster dataset and printed out information about this object including its name and type.