Get smallest extent from a list of rasters

3200
3
Jump to solution
06-22-2013 07:11 AM
AndrewDavies
New Contributor
Hi all,

I am completely lost here, I am trying to get the smallest extent of a raster from a list of rasters, if I set my workspace, and then use
arcpy.env.extent = "MINOF"
print "Extent is: " + str(arcpy.env.extent)

I get an output:

Extent is "MINOF".

If I try to set MINOF as an Extent variable (i.e. arcpy.env.extent = Extent("MINOF")  ), I get 0 0 0 0 NaN NaN etc etc.

I can't find on any forum an idea to help me get the smallest extent of all of the rasters in my directory or rasterList.

Any ideas?

Thanks
Andy
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor
See the arcpy ListRasters and Describe methods.

Basically loop through the rasters in the workspace and describe them to get the extent and calculate the minimum.

And here's an example:
import arcpy  # Set the current workspace arcpy.env.workspace = "c:/data/DEMS"  # Get the list of rasters in the workspace rasters = arcpy.ListRasters()  for raster in rasters:     ext=arcpy.Describe(raster).extent     try:         xmin=max(xmin,ext.XMin)         ymin=max(ymin,ext.XMax)         xmax=min(xmax,ext.YMin)         ymax=min(ymax,ext.YMax)     except NameError:         xmin,ymin,xmax,ymax=ext.XMin, ext.XMax, ext.YMin, ext.YMax          minext=[xmin,ymin,xmax,ymax]

View solution in original post

0 Kudos
3 Replies
Luke_Pinner
MVP Regular Contributor
See the arcpy ListRasters and Describe methods.

Basically loop through the rasters in the workspace and describe them to get the extent and calculate the minimum.

And here's an example:
import arcpy  # Set the current workspace arcpy.env.workspace = "c:/data/DEMS"  # Get the list of rasters in the workspace rasters = arcpy.ListRasters()  for raster in rasters:     ext=arcpy.Describe(raster).extent     try:         xmin=max(xmin,ext.XMin)         ymin=max(ymin,ext.XMax)         xmax=min(xmax,ext.YMin)         ymax=min(ymax,ext.YMax)     except NameError:         xmin,ymin,xmax,ymax=ext.XMin, ext.XMax, ext.YMin, ext.YMax          minext=[xmin,ymin,xmax,ymax]
0 Kudos
AndrewDavies
New Contributor
Very many thanks for your help, I had thought that the "MINOF" command was meant to set as the minimum of all inputs in a workspace, it's not very clear on the help.

Best
A
0 Kudos
Luke_Pinner
MVP Regular Contributor
I had thought that the "MINOF" command was meant to set as the minimum of all inputs in a workspace, it's not very clear on the help.
No MINOF tells ArcPy to set the output extent to the minimum extent of input datasets when running a geoprocessing operation, not all datasets in a workspace. If you wanted to run a raster calculation, setting arcpy.env.extent = "MINOF" would make arcpy perform the calculation only on the area where the extents of the input rasters overlap.  If you printed arcpy.env.extent, you'd still get "MINOF", but if you described the output raster and printed its extent you'd see the actual minimum extent.

If your question is answered, can you click the check mark to the right of the best answer.
0 Kudos