Exemple #1
0
    def finish_results(outputname, results, **kwargs):
        """ Merges and cleans up compiled output from `analyze`.

        Parameters
        ----------
        outputname : str
            Path to where the final file sould be saved.
        results : list of str
            Lists of all of the floods, flooded wetlands, and flooded
            buildings, respectively, that will be merged and deleted.
        sourcename : str, optional
            Path to the original source file of the results. If
            provided, its attbutes will be spatially joined to the
            concatenated results.

        Returns
        -------
        None

        """

        sourcename = kwargs.pop('sourcename', None)
        cleanup = kwargs.pop('cleanup', True)

        if outputname is not None:
            if sourcename is not None:
                tmp_fname = utils.create_temp_filename(outputname, filetype='shape')
                utils.concat_results(tmp_fname, *results)
                utils.join_results_to_baseline(
                    outputname,
                    utils.load_data(tmp_fname, 'layer'),
                    utils.load_data(sourcename, 'layer')
                )
                utils.cleanup_temp_results(tmp_fname)

            else:
                utils.concat_results(outputname, *results)

        if cleanup:
            utils.cleanup_temp_results(*results)
    def finish_results(outputname, results, **kwargs):
        """ Merges and cleans up compiled output from `analyze`.

        Parameters
        ----------
        outputname : str
            Path to where the final file sould be saved.
        results : list of str
            Lists of all of the floods, flooded wetlands, and flooded
            buildings, respectively, that will be merged and deleted.
        sourcename : str, optional
            Path to the original source file of the results. If
            provided, its attbutes will be spatially joined to the
            concatenated results.

        Returns
        -------
        None

        """

        sourcename = kwargs.pop('sourcename', None)
        cleanup = kwargs.pop('cleanup', True)

        if outputname is not None:
            if sourcename is not None:
                tmp_fname = utils.create_temp_filename(outputname, filetype='shape')
                utils.concat_results(tmp_fname, *results)
                utils.join_results_to_baseline(
                    outputname,
                    utils.load_data(tmp_fname, 'layer'),
                    utils.load_data(sourcename, 'layer')
                )
                utils.cleanup_temp_results(tmp_fname)

            else:
                utils.concat_results(outputname, *results)

        if cleanup:
            utils.cleanup_temp_results(*results)
def test_concat_results():
    known = resource_filename('tidegates.testing.concat_results', 'known.shp')
    with utils.OverwriteState(True):
        test = utils.concat_results(
            resource_filename('tidegates.testing.concat_results', 'result.shp'),
            resource_filename('tidegates.testing.concat_results', 'input1.shp'),
            resource_filename('tidegates.testing.concat_results', 'input2.shp')
        )

    nt.assert_true(isinstance(test, arcpy.mapping.Layer))
    tgtest.assert_shapefiles_are_close(test.dataSource, known)

    utils.cleanup_temp_results(test)
def test_concat_results():
    known = resource_filename('tidegates.testing.concat_results', 'known.shp')
    with utils.OverwriteState(True):
        test = utils.concat_results(
            resource_filename('tidegates.testing.concat_results',
                              'result.shp'),
            resource_filename('tidegates.testing.concat_results',
                              'input1.shp'),
            resource_filename('tidegates.testing.concat_results',
                              'input2.shp'))

    nt.assert_true(isinstance(test, arcpy.mapping.Layer))
    tgtest.assert_shapefiles_are_close(test.dataSource, known)

    utils.cleanup_temp_results(test)