Ejemplo n.º 1
0
    def testGetCatchmentFeaturesForStreamflowGage(self):
        goodReachcode = "02060003000745"
        goodMeasure = 75.06239
        badReachcode = "klsdklasd"
        badMeasure = "sdfklfkl"

        # Bad reachcode
        exceptionThrown = False
        try:
            (shapefileName, url) = getCatchmentFeaturesForStreamflowGage(
                self.context.config, self.projectDir, "catchment", badReachcode, goodMeasure
            )
        except WebserviceError:
            exceptionThrown = True
        except Exception:
            raise

        self.assertTrue(exceptionThrown)

        # Bad measure
        exceptionThrown = False
        try:
            (shapefileName, url) = getCatchmentFeaturesForStreamflowGage(
                self.context.config, self.projectDir, "catchment", goodReachcode, badMeasure
            )
        except WebserviceError:
            exceptionThrown = True
        except Exception:
            raise

        self.assertTrue(exceptionThrown)

        # Good case
        exceptionThrown = False
        try:
            (shapefileName, url) = getCatchmentFeaturesForStreamflowGage(
                self.context.config, self.projectDir, "catchment", goodReachcode, goodMeasure
            )
        except:
            traceback.print_exc(file=sys.stdout)
            exceptionThrown = True

        self.assertTrue(not exceptionThrown)
        self.assertTrue(shapefileName == "catchment.shp")
        self.assertTrue(os.path.exists(os.path.join(self.projectDir, shapefileName)))
Ejemplo n.º 2
0
    def testGetCatchmentFeaturesForStreamflowGage(self):
        goodReachcode = "02060003000745"
        goodMeasure = 75.06239
        badReachcode = "klsdklasd"
        badMeasure = "sdfklfkl"

        # Bad reachcode
        exceptionThrown = False
        try:
            (shapefileName, url) = getCatchmentFeaturesForStreamflowGage(self.context.config, self.projectDir,
                                                                         'catchment', badReachcode, goodMeasure)
        except WebserviceError:
            exceptionThrown = True
        except Exception:
            raise
        
        self.assertTrue( exceptionThrown )
        
        # Bad measure
        exceptionThrown = False
        try:
            (shapefileName, url) = getCatchmentFeaturesForStreamflowGage(self.context.config, self.projectDir,
                                                                         'catchment', goodReachcode, badMeasure)
        except WebserviceError:
            exceptionThrown = True
        except Exception:
            raise
        
        self.assertTrue( exceptionThrown )
        
        # Good case
        exceptionThrown = False
        try:
            (shapefileName, url) = getCatchmentFeaturesForStreamflowGage(self.context.config, self.projectDir,
                                                                         'catchment', goodReachcode, goodMeasure)
        except:
            traceback.print_exc(file=sys.stdout)
            exceptionThrown = True
        
        self.assertTrue( not exceptionThrown )
        self.assertTrue( shapefileName == 'catchment.shp' )
        self.assertTrue( os.path.exists( os.path.join( self.projectDir, shapefileName ) ) )
        sys.exit("Config file %s does not define option %s in section %s" % \
              (args.configfile, 'NHDPLUS2', 'PATH_OF_NHDPLUS2_CATCHMENT')) 

    shapeFilename = getCatchmentFeaturesForGage(context.config, context.projectDir, outfile, 
                                                reachcode, measure,
                                                format=OGR_SHAPEFILE_DRIVER_NAME)
    source = 'http://www.horizon-systems.com/NHDPlus/NHDPlusV2_home.php'
    writeMetadata = True
    sys.stdout.write('done\n')
else:
    sys.stdout.write('Geting catchment area draining through gage using NHDPlus webservice...')
    sys.stdout.flush()
    
    try:
        (shapeFilename, source) = getCatchmentFeaturesForStreamflowGage(context.config, context.projectDir,
                                                                       outfile, reachcode, measure,
                                                                       format=OGR_SHAPEFILE_DRIVER_NAME)
        writeMetadata = True
    except Exception as e:
        sys.exit( str(e) )
    
    sys.stdout.write('done\n')

if writeMetadata:
    # Write provenance
    asset = AssetProvenance(GenericMetadata.MANIFEST_SECTION)
    asset.name = 'study_area_shapefile'
    asset.dcIdentifier = shapeFilename
    asset.dcSource = source
    asset.dcTitle = 'Study area shapefile'
    asset.dcPublisher = 'USGS'
        measure,
        format=OGR_SHAPEFILE_DRIVER_NAME)
    source = 'http://www.horizon-systems.com/NHDPlus/NHDPlusV2_home.php'
    writeMetadata = True
    sys.stdout.write('done\n')
else:
    sys.stdout.write(
        'Geting catchment area draining through gage using NHDPlus webservice...'
    )
    sys.stdout.flush()

    try:
        (shapeFilename, source) = getCatchmentFeaturesForStreamflowGage(
            context.config,
            context.projectDir,
            outfile,
            reachcode,
            measure,
            format=OGR_SHAPEFILE_DRIVER_NAME)
        writeMetadata = True
    except Exception as e:
        sys.exit(str(e))

    sys.stdout.write('done\n')

if writeMetadata:
    # Write provenance
    asset = AssetProvenance(GenericMetadata.MANIFEST_SECTION)
    asset.name = 'study_area_shapefile'
    asset.dcIdentifier = shapeFilename
    asset.dcSource = source