EcohydroLib  1.29
Variables
NHDPlusV2Setup Namespace Reference

Builds SQLite3 databases from NHDPlus V2 data archives downloaded from http://www.horizon-systems.com/NHDPlus/NHDPlusV2_home.php. More...

Variables

tuple parser = argparse.ArgumentParser(description='Assemble regional NHDPLus V2 data into a national dataset')
 
string help = 'The configuration file'
 
 required = True,
 
 default = False,
 
tuple args = parser.parse_args()
 
tuple config = ConfigParser.RawConfigParser()
 
tuple pathOfOgr = config.get('GDAL/OGR', 'PATH_OF_OGR2OGR')
 
tuple pathOfFind = config.get('UTIL', 'PATH_OF_FIND')
 
tuple pathOfSevenZip = config.get('UTIL', 'PATH_OF_SEVEN_ZIP')
 
tuple pathOfSqlite = config.get('UTIL', 'PATH_OF_SQLITE')
 
tuple nhdPlusDB = os.path.join(args.outputDir, "NHDPlusDB.sqlite")
 
tuple zipFiles = subprocess.check_output("%s %s -type f -name *.7z -print" % (pathOfFind, args.archiveDir,), shell=True)
 
string sevenZCommand = "%s x -y -o%s %s"
 
tuple returnCode = os.system(sevenZCommand)
 
tuple gageLocDB = os.path.join(args.outputDir, "GageLoc.sqlite")
 
tuple gageLoc = subprocess.check_output("%s %s -type f -iname GageLoc.shp -print" % (pathOfFind, args.outputDir,), shell=True)
 
list gageLocShp = gageLoc[0]
 
string ogrCommand = '%s -gt 65536 -f "SQLite" -t_srs "EPSG:4326" %s %s'
 
string sqliteCommand = "%s %s 'CREATE INDEX IF NOT EXISTS reachcode_measure_idx on GageLoc (reachcode,measure)'"
 
tuple conusCatchment = os.path.join(args.outputDir, "Catchment.sqlite")
 
tuple shapefiles = subprocess.check_output("%s %s -type f -iname Catchment.shp -print" % (pathOfFind, args.outputDir,), shell=True)
 
tuple numFiles = len(shapefiles)
 
int currFile = 0
 
tuple pctComplete = (float(currFile) / float(numFiles))
 
tuple conn = sqlite3.connect(nhdPlusDB)
 
tuple cursor = conn.cursor()
 
tuple dbfs = subprocess.check_output("%s %s -type f -iname PlusFlowlineVAA.dbf -print" % (pathOfFind, args.outputDir,), shell=True)
 
tuple f = open(file, 'rb')
 
tuple db = list(dbfreader(f))
 
list records = db[2:]
 
list GNIS_NBR = record[13]
 
tuple dbf = subprocess.check_output("%s %s -type f -iname GageLoc.dbf -print" % (pathOfFind, args.outputDir,), shell=True)
 

Detailed Description

Builds SQLite3 databases from NHDPlus V2 data archives downloaded from http://www.horizon-systems.com/NHDPlus/NHDPlusV2_home.php.

Assembles regional NHDPlus V2 data into national dataset suitable for gage- reach based region of interest extraction

Note
Requires GDAL/OGR that has been built with SQLite3 support
Requires 7z to extract data from archive files

This software is provided free of charge under the New BSD License. Please see the following license information:

Copyright (c) 2013, University of North Carolina at Chapel Hill All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Author
Brian Miles brian.nosp@m._mil.nosp@m.es@un.nosp@m.c.ed.nosp@m.u

Usage:

1 NHDPlusSetup.py -i <config_file> -a <archive_dir> -o <output_dir>

Variable Documentation

tuple NHDPlusV2Setup.args = parser.parse_args()
tuple NHDPlusV2Setup.config = ConfigParser.RawConfigParser()
tuple NHDPlusV2Setup.conn = sqlite3.connect(nhdPlusDB)
tuple NHDPlusV2Setup.conusCatchment = os.path.join(args.outputDir, "Catchment.sqlite")
int NHDPlusV2Setup.currFile = 0
tuple NHDPlusV2Setup.cursor = conn.cursor()
tuple NHDPlusV2Setup.db = list(dbfreader(f))
tuple NHDPlusV2Setup.dbf = subprocess.check_output("%s %s -type f -iname GageLoc.dbf -print" % (pathOfFind, args.outputDir,), shell=True)
tuple NHDPlusV2Setup.dbfs = subprocess.check_output("%s %s -type f -iname PlusFlowlineVAA.dbf -print" % (pathOfFind, args.outputDir,), shell=True)
NHDPlusV2Setup.default = False,
tuple NHDPlusV2Setup.f = open(file, 'rb')
tuple NHDPlusV2Setup.gageLoc = subprocess.check_output("%s %s -type f -iname GageLoc.shp -print" % (pathOfFind, args.outputDir,), shell=True)
tuple NHDPlusV2Setup.gageLocDB = os.path.join(args.outputDir, "GageLoc.sqlite")
list NHDPlusV2Setup.gageLocShp = gageLoc[0]
int NHDPlusV2Setup.GNIS_NBR = record[13]
string NHDPlusV2Setup.help = 'The configuration file'
tuple NHDPlusV2Setup.nhdPlusDB = os.path.join(args.outputDir, "NHDPlusDB.sqlite")
tuple NHDPlusV2Setup.numFiles = len(shapefiles)
string NHDPlusV2Setup.ogrCommand = '%s -gt 65536 -f "SQLite" -t_srs "EPSG:4326" %s %s'
tuple NHDPlusV2Setup.parser = argparse.ArgumentParser(description='Assemble regional NHDPLus V2 data into a national dataset')
tuple NHDPlusV2Setup.pathOfFind = config.get('UTIL', 'PATH_OF_FIND')
tuple NHDPlusV2Setup.pathOfOgr = config.get('GDAL/OGR', 'PATH_OF_OGR2OGR')
tuple NHDPlusV2Setup.pathOfSevenZip = config.get('UTIL', 'PATH_OF_SEVEN_ZIP')
tuple NHDPlusV2Setup.pathOfSqlite = config.get('UTIL', 'PATH_OF_SQLITE')
tuple NHDPlusV2Setup.pctComplete = (float(currFile) / float(numFiles))
list NHDPlusV2Setup.records = db[2:]
NHDPlusV2Setup.required = True,
tuple NHDPlusV2Setup.returnCode = os.system(sevenZCommand)
string NHDPlusV2Setup.sevenZCommand = "%s x -y -o%s %s"
tuple NHDPlusV2Setup.shapefiles = subprocess.check_output("%s %s -type f -iname Catchment.shp -print" % (pathOfFind, args.outputDir,), shell=True)
string NHDPlusV2Setup.sqliteCommand = "%s %s 'CREATE INDEX IF NOT EXISTS reachcode_measure_idx on GageLoc (reachcode,measure)'"
tuple NHDPlusV2Setup.zipFiles = subprocess.check_output("%s %s -type f -name *.7z -print" % (pathOfFind, args.archiveDir,), shell=True)