Last active
June 8, 2017 15:14
-
-
Save johnniehard/34981d45a53c12f4454cee49f96e71f6 to your computer and use it in GitHub Desktop.
Batch process an input directory with GoSpatial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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