Skip to content

Instantly share code, notes, and snippets.

@hallahan
Created November 24, 2013 04:35
Show Gist options
  • Save hallahan/7623367 to your computer and use it in GitHub Desktop.
Save hallahan/7623367 to your computer and use it in GitHub Desktop.
Sums a bunch of binary masks together so you can have classification groups that show how many images in our set are cloudless.
import os
import sys
import arcpy
from arcpy.sa import *
arcpy.CheckOutExtension('Spatial')
arcpy.env.overwriteOutput = True
cwd = os.getcwd()
inputPath = cwd + "\\intermediate\\"
outputPath = cwd + "\\output\\"
inputFiles = os.listdir(inputPath)
sumRaster = None
for img in inputFiles:
if img.split('.')[-1] == 'TIF':
imgPath = inputPath + img
if sumRaster is None:
print('Starting with ' + img + ' in the summed raster...')
sumRaster = Raster(imgPath)
else:
print('Adding ' + img + ' to the summed raster...')
sumRaster += Raster(imgPath)
outputFileName = img.split('_')[0] + '_BINSUM.TIF'
print("Saving final sum of binary masks as " + outputFileName)
sumRaster.save(outputPath + outputFileName)
print("Success!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment