示例#1
0
 def testModelExecuteWithMalformedCsv(self):
     with TempDir() as d:
         # raises a ValueError when the malformed line is encountered.
         classify.main(
             config.malformed_csv, 'null.tif',
             'null.tif', 'null.tif', config.bathy_raster,
             os.path.join(d, 'null.tif'))
示例#2
0
def main(out_workspace, input_bathymetry, broad_bpi_inner_radius,
         broad_bpi_outer_radius, fine_bpi_inner_radius,
         fine_bpi_outer_radius, classification_dict, output_zones):
    """
    Compute complete model. The crux of this computation maps ranges
    of values provided in the classification dictionary (a CSV or Excel
    spreadsheet) to bathymetry derivatives: standardized
    fine- and broad- scale BPI and slope.
    """

    # local variables:
    broad_bpi = os.path.join(out_workspace, "broad_bpi")
    fine_bpi = os.path.join(out_workspace, "fine_bpi")
    slope_rast = os.path.join(out_workspace, "slope")
    broad_std = os.path.join(out_workspace, "broad_std")
    fine_std = os.path.join(out_workspace, "fine_std")

    utils.workspace_exists(out_workspace)
    # set geoprocessing environments
    arcpy.env.scratchWorkspace = out_workspace
    arcpy.env.workspace = out_workspace

    # TODO: currently set to automatically overwrite, expose this as option
    arcpy.env.overwriteOutput = True

    try:
        # Process: Build Broad Scale BPI
        utils.msg("Calculating broad-scale BPI...")
        bpi.main(input_bathymetry, broad_bpi_inner_radius,
                 broad_bpi_outer_radius, broad_bpi, bpi_type='broad')

        # Process: Build Fine Scale BPI
        utils.msg("Calculating fine-scale BPI...")
        bpi.main(input_bathymetry, fine_bpi_inner_radius,
                 fine_bpi_outer_radius, fine_bpi, bpi_type='fine')

        # Process: Standardize BPIs
        utils.msg("Standardizing BPI rasters...")
        standardize_bpi.main(broad_bpi, broad_std)
        standardize_bpi.main(fine_bpi, fine_std)

        # Process: Calculate Slope
        slope.main(input_bathymetry, slope_rast)

        # Process: Zone Classification Builder
        outputs_base = arcpy.env.addOutputsToMap
        arcpy.env.addOutputsToMap = True
        utils.msg("Classifying Zones...")
        classify.main(classification_dict, broad_std, fine_std,
                      slope_rast, input_bathymetry, output_zones)
        arcpy.env.addOutputsToMap = outputs_base

    except Exception as e:
        # Print error message if an error occurs
        utils.msg(e, mtype='error')
示例#3
0
文件: testMain.py 项目: chinasio/btm
 def testClassifyWithFgdbLocation(self):
     with TempDir() as d:
         fgdb_name = "classify.gdb"
         fgdb_workspace = os.path.join(d, fgdb_name)
         # create a temporary File Geodatabase location
         arcpy.CreateFileGDB_management(d, fgdb_name)
         self.assertTrue(os.path.exists(fgdb_workspace))
         # TODO: this currently hacks up the path to be a valid name, but should probably
         # instead throw an error and let the user correct the output name.
         classify_raster = os.path.join(fgdb_workspace, 'output_in_fgdb')
         classify.main(config.base_xml, config.broad_std_raster, config.fine_std_raster, \
                 config.slope_raster,  config.bathy_raster, classify_raster)
         # resulting 'fixed' name
         mean = su.raster_properties(classify_raster, "MEAN")
         self.assertAlmostEqual(mean, 5.78153846153846)
示例#4
0
 def testClassifyWithFgdbLocation(self):
     with TempDir() as d:
         fgdb_name = "classify.gdb"
         fgdb_workspace = os.path.join(d, fgdb_name)
         # create a temporary File Geodatabase location
         arcpy.CreateFileGDB_management(d, fgdb_name)
         self.assertTrue(os.path.exists(fgdb_workspace))
         # TODO: this currently hacks up the path to be a valid name,
         # but should probably instead throw an error and let the user
         # correct the output name.
         classify_raster = os.path.join(fgdb_workspace, 'output_in_fgdb')
         classify.main(config.base_xml, config.broad_std_raster,
                       config.fine_std_raster, config.slope_raster,
                       config.bathy_raster, classify_raster)
         # resulting 'fixed' name
         mean = su.raster_properties(classify_raster, "MEAN")
         self.assertAlmostEqual(mean, 5.78153846153846)
示例#5
0
 def testModelExecuteWithMalformedCsv(self):
     with TempDir() as d:
         # raises a ValueError when the malformed line is encountered.
         classify.main(config.malformed_csv, 'null.tif', 'null.tif',
                       'null.tif', config.bathy_raster,
                       os.path.join(d, 'null.tif'))
示例#6
0
def main(out_workspace, input_bathymetry, broad_bpi_inner_radius,
         broad_bpi_outer_radius, fine_bpi_inner_radius, fine_bpi_outer_radius,
         classification_dict, output_zones):
    """
    Compute complete model. The crux of this computation maps ranges
    of values provided in the classification dictionary (a CSV or Excel
    spreadsheet) to bathymetry derivatives: standardized
    fine- and broad- scale BPI and slope.
    """

    # local variables:
    broad_bpi = os.path.join(out_workspace, "broad_bpi")
    fine_bpi = os.path.join(out_workspace, "fine_bpi")
    slope_rast = os.path.join(out_workspace, "slope")
    broad_std = os.path.join(out_workspace, "broad_std")
    fine_std = os.path.join(out_workspace, "fine_std")

    utils.workspace_exists(out_workspace)
    # set geoprocessing environments
    arcpy.env.scratchWorkspace = out_workspace
    arcpy.env.workspace = out_workspace

    # TODO: currently set to automatically overwrite, expose this as option
    arcpy.env.overwriteOutput = True

    try:
        # Process: Build Broad Scale BPI
        utils.msg("Calculating broad-scale BPI...")
        bpi.main(input_bathymetry,
                 broad_bpi_inner_radius,
                 broad_bpi_outer_radius,
                 broad_bpi,
                 bpi_type='broad')

        # Process: Build Fine Scale BPI
        utils.msg("Calculating fine-scale BPI...")
        bpi.main(input_bathymetry,
                 fine_bpi_inner_radius,
                 fine_bpi_outer_radius,
                 fine_bpi,
                 bpi_type='fine')

        # Process: Standardize BPIs
        utils.msg("Standardizing BPI rasters...")
        standardize_bpi.main(broad_bpi, broad_std)
        standardize_bpi.main(fine_bpi, fine_std)

        # Process: Calculate Slope
        slope.main(input_bathymetry, slope_rast)

        # Process: Zone Classification Builder
        outputs_base = arcpy.env.addOutputsToMap
        arcpy.env.addOutputsToMap = True
        utils.msg("Classifying Zones...")
        classify.main(classification_dict, broad_std, fine_std, slope_rast,
                      input_bathymetry, output_zones)
        arcpy.env.addOutputsToMap = outputs_base

    except Exception as e:
        # Print error message if an error occurs
        utils.msg(e, mtype='error')