Help: Batch Repjection of Landsat 8

668
4
12-04-2016 12:26 AM
ZiaAhmed
New Contributor III

Hi All,

I am trying to reproject  all surface bands of several  Landsat 8 image to a local coordinate system. Following script works fine for all bands of a single sheet  of image.

But I would like to  reproject all sheets  by batch processing  and saved them in a another folder with similar sub-folders  name of input  folder.   

My input folder structure  like this:

G:\RemoteSensing_Data\Landsat\Landsat_08\Year_2014\Path_136\UTM\LC81360432014002

G:\RemoteSensing_Data\Landsat\Landsat_08\Year_2014\Path_136\UTM\LC81360432014082

G:\RemoteSensing_Data\Landsat\Landsat_08\Year_2014\Path_136\UTM\LC81360442014002

G:\RemoteSensing_Data\Landsat\Landsat_08\Year_2014\Path_136\UTM\LC81360442014082

Output folder will be like this

G:\RemoteSensing_Data\Landsat\Landsat_08\Year_2014\Path_136\BUTM\LC81360432014002

G:\RemoteSensing_Data\Landsat\Landsat_08\Year_2014\Path_136\BUTM\LC81360432014082

G:\RemoteSensing_Data\Landsat\Landsat_08\Year_2014\Path_136\BUTM\LC81360442014002

G:\RemoteSensing_Data\Landsat\Landsat_08\Year_2014\Path_136\BUTM\LC81360442014082

try:
    import arcpy
    arcpy.env.workspace =  r"G:/RemoteSensing_Data/Landsat/Landsat_08/Year_2014/Path_136/UTM/LC81360432014002"
    rasterListA = arcpy.ListRasters("*_sr_*","TIF")
    print(rasterListA)
    # Projection files (.prj)
    inPut_cs = "G:\\RemoteSensing_Data\\Landsat\\Projection_File\\UTM_zone_46_N.prj"
    outPut_cs = "G:\\RemoteSensing_Data\\Landsat\\Projection_File\\BUTM.prj"
    #Projection
    for raster in rasterListA:
        projOutA="G:\\RemoteSensing_Data\\Landsat\\Landsat_08\\Year_2014\\Path_136\\BUTM\\Full\\LC81360432014002\\"+raster
        arcpy.ProjectRaster_management(raster, projOutA, outPut_cs,"BILINEAR", inPut_cs)
except:
    print "Projection failed."
    print arcpy.GetMessages()

I appreciated if some one help me out.

Zia

0 Kudos
4 Replies
DanPatterson_Retired
MVP Esteemed Contributor

does the BUTM folder exist?

throw in some print statements to see if the origin file exists and the destination file path looks right.

And format your code using syntax highlighting with the python parser

finally, the error message would be nice... best to take everything out of a try-except block since if not properly done will actually hide the error and be less than helpful

0 Kudos
ZiaAhmed
New Contributor III

Thanks. Yes, it does not contain sub-folders similar to UTM folders.  I will try accordingly.

0 Kudos
ZiaAhmed
New Contributor III

I try following code it can all rasters from 4 sub-folders UTM folder. I can re-project all files but I need save they in perspective sub-folders in the  BUTM folder

import arcpy
arcpy.env.workspace =  r"G:/RemoteSensing_Data/Landsat/Landsat_08/Year_2014/Path_136/UTM/"
folders = arcpy.ListWorkspaces()
for folder in folders:
 arcpy.env.workspace = folder
 rasters = arcpy.ListRasters("*_sr_*","TIF")
 print (rasters)

[u'LC81360432014002LGN00_sr_band1.tif', u'LC81360432014002LGN00_sr_band2.tif', u'LC81360432014002LGN00_sr_band3.tif', u'LC81360432014002LGN00_sr_band4.tif', u'LC81360432014002LGN00_sr_band5.tif', u'LC81360432014002LGN00_sr_band6.tif', u'LC81360432014002LGN00_sr_band7.tif', u'LC81360432014002LGN00_sr_cloud.tif', u'LC81360432014002LGN00_sr_evi.tif', u'LC81360432014002LGN00_sr_ipflag.tif', u'LC81360432014002LGN00_sr_msavi.tif', u'LC81360432014002LGN00_sr_ndvi.tif', u'LC81360432014002LGN00_sr_savi.tif']
[u'LC81360432014082LGN00_sr_band1.tif', u'LC81360432014082LGN00_sr_band2.tif', u'LC81360432014082LGN00_sr_band3.tif', u'LC81360432014082LGN00_sr_band4.tif', u'LC81360432014082LGN00_sr_band5.tif', u'LC81360432014082LGN00_sr_band6.tif', u'LC81360432014082LGN00_sr_band7.tif', u'LC81360432014082LGN00_sr_cloud.tif', u'LC81360432014082LGN00_sr_evi.tif', u'LC81360432014082LGN00_sr_ipflag.tif', u'LC81360432014082LGN00_sr_msavi.tif', u'LC81360432014082LGN00_sr_ndvi.tif', u'LC81360432014082LGN00_sr_savi.tif']
[u'LC81360442014002LGN00_sr_band1.tif', u'LC81360442014002LGN00_sr_band2.tif', u'LC81360442014002LGN00_sr_band3.tif', u'LC81360442014002LGN00_sr_band4.tif', u'LC81360442014002LGN00_sr_band5.tif', u'LC81360442014002LGN00_sr_band6.tif', u'LC81360442014002LGN00_sr_band7.tif', u'LC81360442014002LGN00_sr_cloud.tif', u'LC81360442014002LGN00_sr_evi.tif', u'LC81360442014002LGN00_sr_ipflag.tif', u'LC81360442014002LGN00_sr_msavi.tif', u'LC81360442014002LGN00_sr_ndvi.tif', u'LC81360442014002LGN00_sr_savi.tif']
[u'LC81360442014082LGN00_sr_band1.tif', u'LC81360442014082LGN00_sr_band2.tif', u'LC81360442014082LGN00_sr_band3.tif', u'LC81360442014082LGN00_sr_band4.tif', u'LC81360442014082LGN00_sr_band5.tif', u'LC81360442014082LGN00_sr_band6.tif', u'LC81360442014082LGN00_sr_band7.tif', u'LC81360442014082LGN00_sr_cloud.tif', u'LC81360442014082LGN00_sr_evi.tif', u'LC81360442014082LGN00_sr_ipflag.tif', u'LC81360442014082LGN00_sr_msavi.tif', u'LC81360442014082LGN00_sr_ndvi.tif', u'LC81360442014082LGN00_sr_savi.tif']
[u'LC81360452014002LGN00_sr_band1.tif', u'LC81360452014002LGN00_sr_band2.tif', u'LC81360452014002LGN00_sr_band3.tif', u'LC81360452014002LGN00_sr_band4.tif', u'LC81360452014002LGN00_sr_band5.tif', u'LC81360452014002LGN00_sr_band6.tif', u'LC81360452014002LGN00_sr_band7.tif', u'LC81360452014002LGN00_sr_cloud.tif', u'LC81360452014002LGN00_sr_evi.tif', u'LC81360452014002LGN00_sr_ipflag.tif', u'LC81360452014002LGN00_sr_msavi.tif', u'LC81360452014002LGN00_sr_ndvi.tif', u'LC81360452014002LGN00_sr_savi.tif']

0 Kudos
ZiaAhmed
New Contributor III

I am trying to use following got, it saved all files in BUTM  directory, but  not in respective sub-directories.

import arcpy
arcpy.env.workspace =  r"G:/RemoteSensing_Data/Landsat/Landsat_05/Year_1989/Row_138/UTM"
folders = arcpy.ListWorkspaces()

inPut_cs = "G:\\RemoteSensing_Data\\Landsat\\Projection_File\\UTM_zone_45_N.prj"
outPut_cs = "G:\\RemoteSensing_Data\\Landsat\\Projection_File\\BUTM.prj"

for folder in folders:
    arcpy.env.workspace = folder
    print(folder)
    rastersList = arcpy.ListRasters("*_sr_*","TIF")
    for raster in rastersList:
        print(raster)
        projOutA="G:\\RemoteSensing_Data\\Landsat\\Landsat_05\\Year_1989\\Row_138\\BUTM\\"+raster
        arcpy.ProjectRaster_management(raster, projOutA, outPut_cs,"BILINEAR", inPut_cs)
0 Kudos