<s> """<STR_LIT>""" <EOL> import os . path , errno <EOL> import osr <EOL> from ecohydrolib . spatialdata . utils import deleteGeoTiff <EOL> from ecohydrolib . spatialdata . utils import getSpatialReferenceForRaster <EOL> from ecohydrolib . spatialdata . utils import getMeterConversionFactorForLinearUnitOfShapefile <EOL> from ecohydrolib . spatialdata . utils import getMeterConversionFactorForLinearUnitOfGMLfile <EOL> import attributequery <EOL> RASTER_ATTRIBUTES = attributequery . ATTRIBUTE_LIST_NUMERIC <EOL> RASTER_ATTRIBUTES . append ( '<STR_LIT>' ) <EOL> def deleteSoilRasters ( context , manifest ) : <EOL> """<STR_LIT>""" <EOL> for entry in manifest . keys ( ) : <EOL> if entry . find ( '<STR_LIT>' ) == <NUM_LIT:0> : <EOL> filePath = os . path . join ( context . projectDir , manifest [ entry ] ) <EOL> deleteGeoTiff ( filePath ) <EOL> def rasterizeSSURGOFeatures ( config , outputDir , featureFilename , featureLayername , featureAttrList , getResolutionFromRasterFileNamed = None , rasterResolutionX = None , rasterResolutionY = None ) : <EOL> """<STR_LIT>""" <EOL> gdalCmdPath = config . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not os . access ( gdalCmdPath , os . X_OK ) : <EOL> raise IOError ( errno . EACCES , "<STR_LIT>" % <EOL> gdalCmdPath ) <EOL> gdalCmdPath = os . path . abspath ( gdalCmdPath ) <EOL> if not os . path . isdir ( outputDir ) : <EOL> raise IOError ( errno . ENOTDIR , "<STR_LIT>" % ( outputDir , ) ) <EOL> if not os . access ( outputDir , os . W_OK ) : <EOL> raise IOError ( errno . EACCES , "<STR_LIT>" % ( outputDir , ) ) <EOL> outputDir = os . path . abspath ( outputDir ) <EOL> featureFilepath = os . path . join ( outputDir , featureFilename ) <EOL> if not os . access ( featureFilepath , os . R_OK ) : <EOL> raise IOError ( errno . EACCES , "<STR_LIT>" % ( featureFilepath , ) ) <EOL> if not os . path . isfile ( featureFilepath ) : <EOL> raise IOError ( errno . ENOENT , "<STR_LIT>" % ( featureFilepath , ) ) <EOL> if getResolutionFromRasterFileNamed is None : <EOL> rasterResolutionX = float ( rasterResolutionX ) <EOL> if rasterResolutionX <= <NUM_LIT:0.0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> rasterResolutionY = float ( rasterResolutionY ) <EOL> if rasterResolutionY <= <NUM_LIT:0.0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> else : <EOL> if not os . access ( getResolutionFromRasterFileNamed , os . R_OK ) : <EOL> raise IOError ( errno . EACCES , "<STR_LIT>" % ( getResolutionFromRasterFileNamed ) ) <EOL> featureType = os . path . splitext ( featureFilepath ) [ <NUM_LIT:1> ] . lstrip ( '<STR_LIT:.>' ) . upper ( ) <EOL> if featureType == "<STR_LIT>" : <EOL> soilMeterConvFactor = getMeterConversionFactorForLinearUnitOfGMLfile ( featureFilepath ) <EOL> elif featureType == "<STR_LIT>" : <EOL> soilMeterConvFactor = getMeterConversionFactorForLinearUnitOfShapefile ( featureFilepath ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if getResolutionFromRasterFileNamed is not None : <EOL> demPixelSizeAndUnits = getSpatialReferenceForRaster ( getResolutionFromRasterFileNamed ) <EOL> rasterResolutionX = demPixelSizeAndUnits [ <NUM_LIT:0> ] <EOL> rasterResolutionY = demPixelSizeAndUnits [ <NUM_LIT:1> ] <EOL> demSrs = osr . SpatialReference ( ) <EOL> if demSrs . ImportFromWkt ( demPixelSizeAndUnits [ <NUM_LIT:4> ] ) == <NUM_LIT:0> : <EOL> demMeterConvFactor = demSrs . GetLinearUnits ( ) <EOL> if soilMeterConvFactor != demMeterConvFactor : <EOL> rasterResolutionX = ( demPixelSizeAndUnits [ <NUM_LIT:0> ] * demMeterConvFactor ) <EOL> rasterResolutionY = ( demPixelSizeAndUnits [ <NUM_LIT:1> ] * demMeterConvFactor ) <EOL> else : <EOL> pass <EOL> else : <EOL> pass <EOL> rasterResolutionX = rasterResolutionX / soilMeterConvFactor <EOL> rasterResolutionY = rasterResolutionY / soilMeterConvFactor <EOL> rasterFilenameProto = os . path . splitext ( featureFilename ) [ <NUM_LIT:0> ] <EOL> filesCreated = dict ( ) <EOL> for attr in featureAttrList : <EOL> rasterFilename = "<STR_LIT>" % ( rasterFilenameProto , attr ) <EOL> filesCreated [ attr ] = rasterFilename <EOL> rasterFilepath = os . path . join ( outputDir , rasterFilename ) <EOL> if not os . path . exists ( rasterFilepath ) : <EOL> gdalCommand = "<STR_LIT>" % ( gdalCmdPath , rasterResolutionX , rasterResolutionY , attr , featureLayername , featureFilepath , rasterFilepath ) <EOL> returnCode = os . system ( gdalCommand ) <EOL> if returnCode != <NUM_LIT:0> : <EOL> raise Exception ( "<STR_LIT>" % ( gdalCommand , ) ) <EOL> return filesCreated </s>
