0
print("Data {0}, xmin{1}, ymin{2}, xmax{3}, ymax{4}".format(ext.Xmin, ext.Xmax, ext.Ymin, ext.Ymax))

The line of code above is not printing out the extent for each raster in my dataset in the code below. It runs without an error, but nothing is displayed.


myRasterList = []
for RAWR in myRasterList:
    ext = arcpy.Describe(RAWR).Extent
    print(ext.Xmin)
    print ("Data extents {4}, Xmin{0}, Xmax{1}, Ymin{2}, Ymax{3}".format(ext.XMin, ext.XMax, ext.YMin, ext.YMax, RAWR))
import arcpy, sys, os
env = arcpy.env
from arcpy import management as DM
from arcpy.sa import *
from arcpy import analysis as AN
from arcpy import conversion as CV

env.workspace = r"F:/Fall 2019/GEOG 625/Exam Data/ExamData/MichaelBreidert/Pen/HMB.gdb"

scriptdir = os.path.dirname(sys.argv[0])
#ws = arcpy.env.workspace = r"F:\Fall 2019\GEOG 625\Exam Data\ExamData\MichaelBreidert"
# creating variable to hold GDB
hmb = scriptdir + "/HMB.gdb"

myRasterList = []
for RAWR in myRasterList:
    ext = arcpy.Describe(RAWR).Extent
    print("Data {0}, xmin{1}, ymin{2}, xmax{3}, ymax{4}".format(ext.Xmin, ext.Xmax, ext.Ymin, ext.Ymax))

How do I print the extents of all data in my HMB.gdb?

3
  • print("Data {0}, xmin{1}, ymin{2}, xmax{3}, ymax{4}".format(ext.Xmin, ext.Xmax, ext.Ymin, ext.Ymax)) This line of code is not printing out the extent for each raster in my dataset. It runs without an error, but no display – Michael Breidert Oct 8 '19 at 2:09
  • Done, is there more to be needed or should I repost with proper instructions? – Michael Breidert Oct 8 '19 at 3:25
  • print (arcpy.ListRasters()) for RAWR in arcpy.ListRasters(): ext = arcpy.Describe(RAWR).extent print ("~~~~~~~~~~~\n~~~~~~~~~~~") print (RAWR) print ("Xmin{0}, Xmax{1}, ".format(ext.XMin, ext.XMax,)) print ("Ymin{0}, Ymax{1}".format(ext.YMin, ext.YMax)) – Michael Breidert Oct 8 '19 at 5:02
2

Nothing prints because your code never gets to the print() function. Right before the for loop, you explicitly set myRasterList = [] i.e. an empty list, so there's nothing to loop through.

You need to fill myRasterList using the arcpy.ListRasters() function.

You also need to be careful with your (lower and upper) case.

For example (slightly abbreviated from your code above):

import arcpy, sys, os
env = arcpy.env

env.workspace = r"F:/Fall 2019/GEOG 625/Exam Data/ExamData/MichaelBreidert/Pen/HMB.gdb"

myRasterList = arcpy.ListRasters()  # list every raster in env.workspace, 
                                    # i.e. r"F:/Fall 2019/GEOG 625/Exam Data/ExamData/MichaelBreidert/Pen/HMB.gdb"
for RAWR in myRasterList:
    ext = arcpy.Describe(RAWR).extent  # note lower case "extent"
    # note case of "XMin" (not "Xmin") etc.
    print("Data {0}, xmin{1}, ymin{2}, xmax{3}, ymax{4}".format(ext.XMin, ext.XMax, ext.YMin, ext.YMax))  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.