Define Projections for Hard Drive of Files with os.walk

Received a hard drive full of imagery today. Tiles in two UTM zones, luckily specified in file name. Lots of folders. No projections defined. Here’s how to do it.

import os, arcpy
inFolder = r"ROOT PATH OF ALL IMAGERY"
folders = os.walk(inFolder)
sr9 = arcpy.Describe(r"PATH TO FILE ALREADY IN ZONE 9").spatialReference
sr10 = arcpy.Describe(r"PATH TO FILE ALREADY IN ZONE 10").spatialReference
for folder in folders:
 for file in folder[2]:
   if file.endswith(".ers"):
     if 'U10W84' in file: 
       arcpy.DefineProjection_management(os.path.join(folder[0], file), sr10)
     elif 'U9W84' in file: 
       arcpy.DefineProjection_management(os.path.join(folder[0], file), sr9)
     else:
       print file
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s