How to extract bounding coordinates from raster files?

1197
1
04-09-2013 06:06 AM
StavrosC
New Contributor II
I'm seeking a Python solution to extract bounding coordinates from 1000+ raster images and save this information in a csv file.  (I'm using ArcGIS 10).  Can anyone suggest some script that will extract this information for a single raster within Python?  I'm fairly new to Python but will be able to create a loop if someone can help me solve this for a single raster. 

Thanks so much for your help!
0 Kudos
1 Reply
MichaelQuinene
New Contributor
import arcpy
from arcpy import env
import csv

#Location of raster files to be processed
rasterWS = "C:/JP2"
env.workspace = rasterWS
#List of rasters within workspace; may need to change file type
rasterList = arcpy.ListRasters("*", "JP2")

#Open csv file for writing.
#If you wish to append rows to an existing file, change argument to "ab" (append)
#Without "ab" argument, an existing file will be overwritten
with open("testcsv.csv", "wb") as csvfile:

    fileWriter = csv.writer(csvfile)
    #Write Column Headers
    headers = ["Filename","XMin", "YMin", "XMax","YMax", "ZMin","ZMax","MMin","MMax"]
    fileWriter.writerow(headers)

    for rasterFile in rasterList:

        #Create raster object and get properties
        raster = arcpy.Raster(rasterFile)
        name = raster.name
        extent = raster.extent

        #Create list from extent string, prepend filename to list, and write list as row in csv
        writeData = str(extent).split()
        writeData.insert(0, name)
        fileWriter.writerow(writeData)



This is a basic script that should get you started.  Change the directory and file type to suit your needs.  Hope this helps.
0 Kudos