EcohydroWorkflowLib  0.973
 All Classes Namespaces Files Functions Variables Pages
Functions | Variables
ecohydroworkflowlib.nhdplus2.networkanalysis Namespace Reference

Methods for querying the NHDPlus V2 data set. More...

Functions

def getNHDReachcodeAndMeasureForGageSourceFea
 Get NHD Reachcode and measure along reach for a streamflow gage identified by a source_fea (e.g.
 
def getLocationForStreamGageByGageSourceFea
 Get lat/lon, in WGS84 (EPSG:4326), from gage point layer (Gage_Loc) for gage identified by a source_fea (e.g.
 
def getLocationForStreamGageByReachcodeAndMeasure
 Get lat/lon, in WGS84 (EPSG:4326), from gage point layer (Gage_Loc) for gage identified by reachcode and measure.
 
def getLocationForStreamGage
 Get lat/lon, in WGS84 (EPSG:4326), from gage point layer (Gage_Loc) for gage identified by reachcode and measure.
 
def getComIdForStreamGage
 Uses NHDFlowline and/or NHDReachCode_ComID table(s) to lookup the ComID associated with a stream gage identified by reach code and measure.
 
def getPlusFlowPredecessors
 Get the immediate predecessors of the NHDPlus2 PlusFlow feature of comID.
 
def getUpstreamReachesSQL
 Recursively searches PlusFlow table in an SQLite database for all stream reaches upstream of a given reach.
 
def getBoundingBoxForCatchmentsForGage
 Get bounding box coordinates (in WGS 84) for the drainage area associated with a given NHD (National Hydrography Dataset) streamflow gage identified by a reach code and measure.
 
def getCatchmentShapefileForGage
 Get shapefile (in WGS 84) for the drainage area associated with a given NHD (National Hydrography Dataset) streamflow gage identified by a reach code and measure.
 
def getCatchmentShapefileForGageOGR
 Get shapefile (in WGS 84) for the drainage area associated with a given NHD (National Hydrography Dataset) streamflow gage identified by a reach code and measure.
 

Variables

int NORTH 0
 
int EAST 90
 
string OGR_SHAPEFILE_DRIVER_NAME "ESRI Shapefile"
 
int UPSTREAM_SEARCH_THRESHOLD 998
 

Detailed Description

Methods for querying the NHDPlus V2 data set.

Requires that a NHDPlus V2 database be initialized from data archive files using NHDPlusSetup.py

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

Function Documentation

def ecohydroworkflowlib.nhdplus2.networkanalysis.getBoundingBoxForCatchmentsForGage (   config,
  outputDir,
  reachcode,
  measure,
  deleteIntermediateFiles = True 
)

Get bounding box coordinates (in WGS 84) for the drainage area associated with a given NHD (National Hydrography Dataset) streamflow gage identified by a reach code and measure.

Parameters
configA Python ConfigParser containing the following sections and options: 'GDAL/OGR' and option 'PATH_OF_OGR2OGR' (absolute path of ogr2ogr binary) 'NHDPLUS2' and option 'PATH_OF_NHDPLUS2_DB' (absolute path to SQLite3 DB of NHDFlow data) 'NHDPLUS2', 'PATH_OF_NHDPLUS2_CATCHMENT' (absolute path to NHD catchment SQLite3 spatial DB)
outputDirString representing the absolute/relative path of the directory into which output rasters should be written
reachcodeString representing NHD streamflow gage
measureFloat representing the measure along reach where Stream Gage is located in percent from downstream end of the one or more NHDFlowline features that are assigned to the ReachCode (see NHDPlusV21 GageLoc table)
deleteIntermediateFilesA boolean, True if intermediate files generated from the analysis should be deleted
Returns
A dictionary with keys: minX, minY, maxX, maxY, srs. The key srs is set to 'EPSG:4326' (WGS 84)
     @exception ConfigParser.NoSectionError
     @exception ConfigParser.NoOptionError
     @exception IOError(errno.ENOTDIR) if outputDir is not a directory
     @exception IOError(errno.EACCESS) if outputDir is not writable
def ecohydroworkflowlib.nhdplus2.networkanalysis.getCatchmentShapefileForGage (   config,
  outputDir,
  catchmentFilename,
  reachcode,
  measure,
  deleteIntermediateFiles = True 
)

Get shapefile (in WGS 84) for the drainage area associated with a given NHD (National Hydrography Dataset) streamflow gage identified by a reach code and measure.

Note
Deprecated. Uses ogr2ogr binary and is limited to gages with <1000 upstream reaches. use getCatchmentShapefileForGageOGR instead
No return value. catchmentFilename will be written to outputDir if successful
Parameters
configA Python ConfigParser containing the following sections and options: 'GDAL/OGR' and option 'PATH_OF_OGR2OGR' (absolute path of ogr2ogr binary) 'NHDPLUS2' and option 'PATH_OF_NHDPLUS2_DB' (absolute path to SQLite3 DB of NHDFlow data) 'NHDPLUS2', 'PATH_OF_NHDPLUS2_CATCHMENT' (absolute path to NHD catchment shapefile)
outputDirString representing the absolute/relative path of the directory into which output rasters should be written
catchmentFilenameString representing name of file to save catchment shapefile to
reachcodeString representing NHD streamflow gage
measureFloat representing the measure along reach where Stream Gage is located in percent from downstream end of the one or more NHDFlowline features that are assigned to the ReachCode (see NHDPlusV21 GageLoc table)
Exceptions
ConfigParser.NoSectionError
ConfigParser.NoOptionError
IOError(errno.ENOTDIR)if outputDir is not a directory
IOError(errno.EACCESS)if outputDir is not writable
Exceptionif number of upstream reaches is greater than 1000
Exceptionof catchment shapefile extraction fails
def ecohydroworkflowlib.nhdplus2.networkanalysis.getCatchmentShapefileForGageOGR (   config,
  outputDir,
  catchmentFilename,
  reachcode,
  measure,
  deleteIntermediateFiles = True 
)

Get shapefile (in WGS 84) for the drainage area associated with a given NHD (National Hydrography Dataset) streamflow gage identified by a reach code and measure.

Note
Capable of handling gages with more than 1000 upstream reaches
No return value. catchmentFilename will be written to outputDir if successful
Parameters
configA Python ConfigParser containing the following sections and options: 'NHDPLUS2' and option 'PATH_OF_NHDPLUS2_DB' (absolute path to SQLite3 DB of NHDFlow data) 'NHDPLUS2', 'PATH_OF_NHDPLUS2_CATCHMENT' (absolute path to NHD catchment shapefile)
outputDirString representing the absolute/relative path of the directory into which output rasters should be written
catchmentFilenameString representing name of file to save catchment shapefile to
reachcodeString representing NHD streamflow gage
measureFloat representing the measure along reach where Stream Gage is located in percent from downstream end of the one or more NHDFlowline features that are assigned to the ReachCode (see NHDPlusV21 GageLoc table)
Exceptions
ConfigParser.NoSectionError
ConfigParser.NoOptionError
IOError(errno.ENOTDIR)if outputDir is not a directory
IOError(errno.EACCESS)if outputDir is not writable
def ecohydroworkflowlib.nhdplus2.networkanalysis.getComIdForStreamGage (   conn,
  reachcode,
  measure 
)

Uses NHDFlowline and/or NHDReachCode_ComID table(s) to lookup the ComID associated with a stream gage identified by reach code and measure.

Parameters
connAn sqlite3 connection to a database that has the NHDFlowline and NHDReachCode_Comid tables
reachcodeAn string representing the Reachcode #param measure A float representing the measure along reach where Stream Gage is located in percent from downstream end of the one or more NHDFlowline features that are assigned to the ReachCode (see NHDPlusV21 GageLoc table)
Returns
An integer representing the ComID associated with a Reachcode, or -1 if a reach with Reachcode was not found.
def ecohydroworkflowlib.nhdplus2.networkanalysis.getLocationForStreamGage (   config,
  whereFilter 
)

Get lat/lon, in WGS84 (EPSG:4326), from gage point layer (Gage_Loc) for gage identified by reachcode and measure.

Parameters
configA Python ConfigParser containing the following sections and options: 'NHDPLUS2', 'PATH_OF_NHDPLUS2_GAGELOC' (absolute path to NHD GageLoc SQLite3 spatial database)
whereFilterString representing the whereFilter to use
Returns
A tuple with (x,y) coordinates in 'EPSG:4326' (WGS 84); None if gage was not found
     @exception ConfigParser.NoSectionError
     @exception ConfigParser.NoOptionError
     @exception IOError(errno.ENOTDIR) if GageLoc is not readable
def ecohydroworkflowlib.nhdplus2.networkanalysis.getLocationForStreamGageByGageSourceFea (   config,
  source_fea 
)

Get lat/lon, in WGS84 (EPSG:4326), from gage point layer (Gage_Loc) for gage identified by a source_fea (e.g.

USGS Site Number)

Parameters
configA Python ConfigParser containing the following sections and options: 'NHDPLUS2', 'PATH_OF_NHDPLUS2_GAGELOC' (absolute path to NHD GageLoc SQLite3 spatial database)
source_feaString representing source_fea of GageLoc gage
Returns
A tuple with (x,y) coordinates in 'EPSG:4326' (WGS 84)
def ecohydroworkflowlib.nhdplus2.networkanalysis.getLocationForStreamGageByReachcodeAndMeasure (   config,
  reachcode,
  measure 
)

Get lat/lon, in WGS84 (EPSG:4326), from gage point layer (Gage_Loc) for gage identified by reachcode and measure.

Parameters
configA Python ConfigParser containing the following sections and options: 'NHDPLUS2', 'PATH_OF_NHDPLUS2_GAGELOC' (absolute path to NHD GageLoc SQLite3 spatial database)
reachcodeString representing NHD streamflow gage
measureFloat representing the measure along reach where Stream Gage is located in percent from downstream end of the one or more NHDFlowline features that are assigned to the ReachCode (see NHDPlusV21 GageLoc table)
Returns
A tuple with (x,y) coordinates in 'EPSG:4326' (WGS 84); None if gage was not found
def ecohydroworkflowlib.nhdplus2.networkanalysis.getNHDReachcodeAndMeasureForGageSourceFea (   config,
  source_fea 
)

Get NHD Reachcode and measure along reach for a streamflow gage identified by a source_fea (e.g.

USGS Site Number)

Parameters
configA Python ConfigParser containing the following sections and options: 'NHDPLUS2', 'PATH_OF_NHDPLUS2_DB' (absolute path to NHDPlus2 SQLite3 database)
source_feaString representing source_fea of GageLoc gage
Returns
A tuple(string, float) representing the reachcode and measure; None if no gage was found.
     @exception ConfigParser.NoSectionError
     @exception ConfigParser.NoOptionError
     @exception IOError(errno.EACCES) if NHDPlus2 DB is not readable
def ecohydroworkflowlib.nhdplus2.networkanalysis.getPlusFlowPredecessors (   conn,
  comID 
)

Get the immediate predecessors of the NHDPlus2 PlusFlow feature of comID.

Parameters
connA connection an SQLite3 database
comdIDString representing the ComID of the reach whose immediate predecessor reaches are to be discovered
Returns
A list of immediate predecessor nodes in the NHDPlus2 PlusFlow graph
def ecohydroworkflowlib.nhdplus2.networkanalysis.getUpstreamReachesSQL (   conn,
  comID,
  allUpstreamReaches 
)

Recursively searches PlusFlow table in an SQLite database for all stream reaches upstream of a given reach.

Note
This method has no return value. Upstream reaches discovered are appended to allUpstreamReaches list.
Parameters
connA connection to an SQLite3 database
comIDThe ComID of the reach whose upstream reaches are to be discovered
allUpstreamReachesA list containing integers representing comIDs of upstream reaches

Variable Documentation

int ecohydroworkflowlib.nhdplus2.networkanalysis.EAST 90
int ecohydroworkflowlib.nhdplus2.networkanalysis.NORTH 0
string ecohydroworkflowlib.nhdplus2.networkanalysis.OGR_SHAPEFILE_DRIVER_NAME "ESRI Shapefile"
int ecohydroworkflowlib.nhdplus2.networkanalysis.UPSTREAM_SEARCH_THRESHOLD 998