Skip to content

Instantly share code, notes, and snippets.

@johnniehard
Last active June 8, 2017 15:14
Show Gist options
  • Save johnniehard/34981d45a53c12f4454cee49f96e71f6 to your computer and use it in GitHub Desktop.
Save johnniehard/34981d45a53c12f4454cee49f96e71f6 to your computer and use it in GitHub Desktop.
Batch process an input directory with GoSpatial
'''
Author: Johnnie Hård, johnnie.hard@gmail.com
Purpose: Batch process all files in a directory with gospatial
'''
import os, subprocess
# Set input/output directories
# cwd = the directory where the script gets called.
cwd = os.getcwd()
indir = "Input"
outdir = "Output"
ext = ".dep"
tool = "BreachDepressions"
toolArgs ";2;50;true;true"
# filter to get all of the *.ext files in the input directory
inputfiles = []
for file in os.listdir(indir):
if file.endswith(ext):
inputfiles.append(os.path.join(indir, file))
exe = 'go-spatial_win_amd64'
run = '-run="' + tool + '"'
cwd = '-cwd="' + cwd + '"'
# loop through inputfiles
for file in inputfiles:
inputname = os.path.splitext(os.path.basename(file))[0]
outputfile = os.path.join(outdir, inputname + "_breachDepressions" + ext)
args = '-args="' + file + ';' + outputfile + toolArgs + '"'
subprocess.run([exe, cwd, run, args])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment