ws = r'C:\MyDir\MyFGDB.gdb' arcpy.env.workspace = ws rasters = arcpy.ListRasters() for raster in rasters: desc = arcpy.Describe(raster) nam = desc.name print "Results for " + str(nam) result_top = arcpy.GetRasterProperties_management(raster, "TOP") result_bot = arcpy.GetRasterProperties_management(raster, "BOTTOM") result_left = arcpy.GetRasterProperties_management(raster, "LEFT") result_right = arcpy.GetRasterProperties_management(raster, "RIGHT") print "extent top: " + str(result_top) print "extet bottom: " + str(result_bot) print "extent left" + str(result_left) print "extent right" + str(result_right)
#1 rasterPath = r"C:\temp\test.img" rstObj = arcpy.Raster(rasterPath) xmin, ymin, xmax, ymax = rstObj.extent.XMin, rstObj.extent.YMin, rstObj.extent.XMax, rstObj.extent.YMax #2 rasterPath = r"C:\temp\test.img" dscObj = arcpy.Describe(rasterPath) xmin, ymin, xmax, ymax = dsc.extent.XMin, dscObj.extent.YMin, dscObj.extent.XMax, dscObj.extent.YMax #3 rasterPath = r"C:\temp\test.img" xmin = float(arcpy.GetRasterProperties_management(raster, "LEFT").getOutput(0)) ymin = float(arcpy.GetRasterProperties_management(raster, "BOTTOM").getOutput(0)) xmax = float(arcpy.GetRasterProperties_management(raster, "RIGHT").getOutput(0)) ymax = float(arcpy.GetRasterProperties_management(raster, "TOP").getOutput(0))
I'm sure this is long since resolved, but here goes anyway...
There is another way to skin this cat, and maybe one or two more cats. It seems to me that with 9.3, accessing some info got harder, or at least requires a little more code. Since I'm a terrible typist, and therefore begrudge every line of code I have to type, I searched for path of lesser resistance. I reverted to calling the 9.2 geoprocessor.
For example, calling the Clip_management tool:
import arcpy, arcgisscripting
gp2 = arcgisscripting.create() ## the 9.2 geoprocessor
temperatureRaster = "Y:\\Connectivity\\temperature\\fut_mean_temp.tif"
tempDir = "Y:\\Connectivity\\scratch"
fc = 'cora_expert_CAT_buffer_2015Aug19.shp' ## in my current workspace
gp.Clip_management(temperatureRaster,gp2.describe(fc).extent,tempDir + "\\tmpTemperature.tif","layer","#","ClippingGeometry")
There's a bunch of stuff from my specific situation that I've left out that's irrelevant, but the point is you can still call the older geoprocessors and use them to pass info.
So to get all the extents, even if using ArcGIS 10.3:
import arcpy (if you want)
import arcgisscripting
arcpy.env.overwriteOutput = True ## and any other environments you want
gp2 = arcgisscripting.create()
arcpy.env.workspace = "C://rasterDirectory"
for raster in arcpy.ListDatasets():
raster, gp2.describe(raster).extent
That should print them all out. And in string format, so no casting.
Another place I've found this useful is with getCount_management. With 9.3 and higher this returns an object. If you revert to 9.2 with the above approach, it'll still return an integer.
Sorry if it's too little, too late, rambling or if anything is missing. Also, I don't know how to post code, so it might also look like crap.