<s> import os <EOL> import sys <EOL> import errno <EOL> import argparse <EOL> import ConfigParser <EOL> from wcs4demlib . demquery import getDEMForBoundingBox <EOL> from nhdplus2lib . networkanalysis import getBoundingBoxForCatchmentsForGage <EOL> from ssurgolib . featurequery import getMapunitFeaturesForBoundingBox <EOL> from ssurgolib . rasterize import rasterizeSSURGOFeatures <EOL> from spatialdatalib . utils import convertGMLToShapefile <EOL> import ssurgolib . attributequery <EOL> from solimlib . inference import inferSoilPropertiesForSSURGOAndTerrainData <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , required = True , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , required = False , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , required = True , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , required = True , type = float , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , required = False , type = float , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , required = True , <EOL> help = '<STR_LIT>' ) <EOL> args = parser . parse_args ( ) <EOL> soilRasterResolution = - <NUM_LIT:1> <EOL> if args . soilrasterresolution : <EOL> soilRasterResolution = args . soilrasterresolution <EOL> if soilRasterResolution <= <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if not os . access ( args . configfile , os . R_OK ) : <EOL> raise IOError ( errno . EACCES , "<STR_LIT>" % <EOL> args . configfile ) <EOL> config = ConfigParser . RawConfigParser ( ) <EOL> config . read ( args . configfile ) <EOL> if not config . has_option ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> sys . exit ( "<STR_LIT>" & ( args . configfile , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if not config . has_option ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> sys . exit ( "<STR_LIT>" & ( args . configfile , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if not config . has_option ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> sys . exit ( "<STR_LIT>" & ( args . configfile , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if not config . has_option ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> sys . exit ( "<STR_LIT>" & ( args . configfile , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if not config . has_option ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> sys . exit ( "<STR_LIT>" & ( args . configfile , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if args . outdir : <EOL> outdir = args . outdir <EOL> else : <EOL> outdir = os . getcwd ( ) <EOL> if not os . path . isdir ( outdir ) : <EOL> raise IOError ( errno . ENOTDIR , "<STR_LIT>" % ( outdir , ) ) <EOL> if not os . access ( outdir , os . W_OK ) : <EOL> raise IOError ( errno . EACCES , "<STR_LIT>" % <EOL> outdir ) <EOL> outdir = os . path . abspath ( outdir ) <EOL> os . chdir ( outdir ) <EOL> solimCmdPath = config . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not os . access ( solimCmdPath , os . X_OK ) : <EOL> raise IOError ( errno . EACCES , "<STR_LIT>" % ( solimCmdPath , ) ) <EOL> bbox = getBoundingBoxForCatchmentsForGage ( config , outdir , args . reachcode , args . measure ) <EOL> print "<STR_LIT>" % ( args . reachcode , args . measure , bbox [ '<STR_LIT>' ] , bbox [ '<STR_LIT>' ] , bbox [ '<STR_LIT>' ] , bbox [ '<STR_LIT>' ] ) <EOL> demFilename = "<STR_LIT>" % ( args . reachcode ) <EOL> returnCode = getDEMForBoundingBox ( outdir , demFilename , bbox = bbox , srs = args . t_srs ) <EOL> assert ( returnCode ) <EOL> gmlFilenames = getMapunitFeaturesForBoundingBox ( outdir , bbox , mapunitExtended = True , tileBbox = False ) <EOL> for gmlFilename in gmlFilenames : <EOL> gmlFilepath = os . path . join ( outdir , gmlFilename ) <EOL> layerName = os . path . splitext ( gmlFilename ) [ <NUM_LIT:0> ] <EOL> shpFilename = convertGMLToShapefile ( config , outdir , gmlFilepath , layerName , args . t_srs ) <EOL> attrList = [ elem [ : <NUM_LIT:10> ] for elem in ssurgolib . attributequery . attributeListNumeric ] <EOL> if soilRasterResolution == - <NUM_LIT:1> : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> rasterizeSSURGOFeatures ( config = config , outputDir = outdir , featureFilename = shpFilename , featureLayername = layerName , featureAttrList = attrList , getResolutionFromRasterFileNamed = demFilename ) <EOL> else : <EOL> sys . stderr . write ( "<STR_LIT>" % ( soilRasterResolution , soilRasterResolution ) ) <EOL> rasterizeSSURGOFeatures ( config = config , outputDir = outdir , featureFilename = shpFilename , featureLayername = layerName , featureAttrList = attrList , rasterResolutionX = soilRasterResolution , rasterResolutionY = soilRasterResolution ) <EOL> returnCode = inferSoilPropertiesForSSURGOAndTerrainData ( config , outdir , shpFilename , demFilename ) <EOL> assert ( returnCode == <NUM_LIT:0> ) </s>
