• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utilities.unique_filename函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中safe.common.utilities.unique_filename函数的典型用法代码示例。如果您正苦于以下问题:Python unique_filename函数的具体用法?Python unique_filename怎么用?Python unique_filename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了unique_filename函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_export_import_setting

 def test_export_import_setting(self):
     """Test for export_setting method."""
     profile_file = unique_filename(
         suffix='.json', dir='population_preference')
     original_settings = {
         'key': 'value',
         'key_bool': True,
         'population_preference': generate_default_profile(),
         'key_int': 1,
         'key_float': 2.0
     }
     # Write
     for key, value in list(original_settings.items()):
         set_setting(key, value, self.qsettings)
     # Export
     inasafe_settings = export_setting(profile_file, self.qsettings)
     # Check result
     self.assertTrue(os.path.exists(profile_file))
     self.assertEqual(inasafe_settings['key'], 'value')
     self.assertEqual(
         inasafe_settings['population_preference'],
         generate_default_profile())
     # Import
     read_setting = import_setting(profile_file, self.qsettings)
     self.assertDictEqual(inasafe_settings, read_setting)
     self.assertDictEqual(original_settings, read_setting)
开发者ID:inasafe,项目名称:inasafe,代码行数:26,代码来源:test_settings.py


示例2: test_relative_path

    def test_relative_path(self):
        """Test we calculate the relative paths correctly when saving scenario.
        """
        result, message = setup_scenario(
            self.DOCK,
            hazard='Classified Flood',
            exposure='Population')
        self.assertTrue(result, message)
        fake_dir = standard_data_path()
        scenario_file = unique_filename(
            prefix='scenarioTest', suffix='.txt', dir=fake_dir)
        exposure_layer = self.DOCK.get_exposure_layer().publicSource()
        hazard_layer = self.DOCK.get_hazard_layer().publicSource()

        relative_exposure = self.save_scenario_dialog.relative_path(
            scenario_file, exposure_layer)
        relative_hazard = self.save_scenario_dialog.relative_path(
            scenario_file, hazard_layer)

        if 'win32' in sys.platform:
            # windows
            self.assertEqual(
                'exposure\\pop_binary_raster_20_20.asc',
                relative_exposure)
            self.assertEqual(
                'hazard\\classified_flood_20_20.asc',
                relative_hazard)

        else:
            self.assertEqual(
                'exposure/pop_binary_raster_20_20.asc',
                relative_exposure)
            self.assertEqual(
                'hazard/classified_flood_20_20.asc',
                relative_hazard)
开发者ID:timlinux,项目名称:inasafe,代码行数:35,代码来源:test_save_scenario.py


示例3: testSqliteWriting

 def testSqliteWriting(self):
     """Test that writing a dataset to sqlite works."""
     keywords = read_keywords(SHP_BASE + '.keywords')
     layer = Vector(data=SHP_BASE + '.shp', keywords=keywords)
     test_dir = temp_dir(sub_dir='test')
     test_file = unique_filename(suffix='.sqlite', dir=test_dir)
     layer.write_to_file(test_file, sublayer='foo')
开发者ID:gijs,项目名称:inasafe,代码行数:7,代码来源:test_vector.py


示例4: read_from_qgis_native

    def read_from_qgis_native(self, qgis_layer):
        """Read raster data from qgis layer QgsRasterLayer.

            A stub is used now:
                save all data in a file,
                then call safe.read_from_file

            Raises:
                * TypeError         if qgis is not avialable
                * IOError           if can't store temporary file
                * GetDataError      if can't create copy of qgis_layer's
                                        dataProvider
        """
        base_name = unique_filename()
        file_name = base_name + '.tif'

        file_writer = QgsRasterFileWriter(file_name)
        pipe = QgsRasterPipe()
        provider = qgis_layer.dataProvider()
        if not pipe.set(provider.clone()):
            msg = "Cannot set pipe provider"
            raise GetDataError(msg)

        file_writer.writeRaster(
            pipe,
            provider.xSize(),
            provider.ySize(),
            provider.extent(),
            provider.crs())

        # Write keywords if any
        write_keywords(self.keywords, base_name + '.keywords')
        self.read_from_file(file_name)
开发者ID:severinmenard,项目名称:inasafe,代码行数:33,代码来源:raster.py


示例5: test_sorted_impacted_cities

    def test_sorted_impacted_cities(self):
        """Test getting impacted cities sorted by mmi then population."""
        working_dir = shakemap_extract_dir()
        shake_event = ShakeEvent(
            working_dir=working_dir,
            event_id=SHAKE_ID,
            data_is_local_flag=True)
        table = shake_event.sorted_impacted_cities()

        file_path = unique_filename(
            prefix='test_sorted_impacted_cities',
            suffix='.txt',
            dir=temp_dir('test'))
        cities_file = file(file_path, 'w')
        cities_file.writelines(str(table))
        cities_file.close()
        table = str(table).replace(', \'', ',\n\'')
        table += '\n'

        fixture_path = os.path.join(
            data_dir(), 'tests', 'test_sorted_impacted_cities.txt')
        cities_file = file(fixture_path)
        expected_string = cities_file.read()
        cities_file.close()
        expected_string = expected_string.replace(', \'', ',\n\'')

        self.max_diff = None
        message = 'Expectation:\n%s, Got\n%s' % (expected_string, table)
        self.assertEqual(expected_string, table, message)
开发者ID:jobel-openscience,项目名称:inasafe,代码行数:29,代码来源:test_shake_event.py


示例6: Xtest_print_impact_table

    def Xtest_print_impact_table(self):
        """Test print impact table to pdf."""
        impact_layer_path = test_data_path(
            'impact', 'population_affected_entire_area.shp')
        layer, _ = load_layer(impact_layer_path)
        # noinspection PyUnresolvedReferences,PyArgumentList
        QgsMapLayerRegistry.instance().addMapLayer(layer)
        # noinspection PyCallingNonCallable
        rect = QgsRectangle(106.8194, -6.2108, 106.8201, -6.1964)
        CANVAS.setExtent(rect)
        CANVAS.refresh()

        template = resources_path(
            'qgis-composer-templates', 'a4-portrait-blue.qpt')
        report = ImpactReport(IFACE, template, layer)
        report.template = template  # just to cover set template
        out_path = unique_filename(
            prefix='test_print_impact_table',
            suffix='.pdf',
            dir=temp_dir('test'))
        report.print_impact_table(out_path)

        # Check the file exists
        message = 'Rendered output does not exist: %s' % out_path
        self.assertTrue(os.path.exists(out_path), message)

        # Check the file is not corrupt
        message = 'The output file %s is corrupt' % out_path
        out_size = os.stat(out_path).st_size
        self.assertTrue(out_size > 0, message)
开发者ID:Mloweedgar,项目名称:inasafe,代码行数:30,代码来源:test_impact_report.py


示例7: test_print_default_template

    def test_print_default_template(self):
        """Test printing report to pdf using default template works."""
        impact_layer_path = test_data_path(
            'impact', 'population_affected_entire_area.shp')
        layer, _ = load_layer(impact_layer_path)
        # noinspection PyUnresolvedReferences
        QgsMapLayerRegistry.instance().addMapLayer(layer)
        # noinspection PyCallingNonCallable
        rect = QgsRectangle(106.8194, -6.2108, 106.8201, -6.1964)
        CANVAS.setExtent(rect)
        CANVAS.refresh()

        template = resources_path(
            'qgis-composer-templates', 'inasafe-portrait-a4.qpt')
        report = ImpactReport(IFACE, template, layer)
        out_path = unique_filename(
            prefix='map_default_template_test',
            suffix='.pdf',
            dir=temp_dir('test'))
        report.print_map_to_pdf(out_path)

        # Check the file exists
        message = 'Rendered output does not exist: %s' % out_path
        self.assertTrue(os.path.exists(out_path), message)

        # Check the file is not corrupt
        message = 'The output file %s is corrupt' % out_path
        out_size = os.stat(out_path).st_size
        self.assertTrue(out_size > 0, message)

        # Check the components in composition are default components
        if qgis_version() < 20500:
            safe_logo = report.composition.getComposerItemById(
                'safe-logo').pictureFile()
            north_arrow = report.composition.getComposerItemById(
                'north-arrow').pictureFile()
            org_logo = report.composition.getComposerItemById(
                'organisation-logo').pictureFile()
        else:
            safe_logo = report.composition.getComposerItemById(
                'safe-logo').picturePath()
            north_arrow = report.composition.getComposerItemById(
                'north-arrow').picturePath()
            org_logo = report.composition.getComposerItemById(
                'organisation-logo').picturePath()

        expected_safe_logo = resources_path(
            'img', 'logos', 'inasafe-logo-url.svg')
        expected_north_arrow = resources_path(
            'img', 'north_arrows', 'simple_north_arrow.png')
        expected_org_logo = resources_path('img', 'logos', 'supporters.png')

        message = 'The safe logo path is not the default one'
        self.assertEqual(expected_safe_logo, safe_logo, message)

        message = 'The north arrow path is not the default one'
        self.assertEqual(expected_north_arrow, north_arrow, message)

        message = 'The organisation logo path is not the default one'
        self.assertEqual(expected_org_logo, org_logo, message)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:60,代码来源:test_impact_report.py


示例8: test_converting

    def test_converting(self):
        """Test converting grif file to tiff."""
        dialog = ShakemapConverterDialog(PARENT, IFACE)
        dialog.use_output_default.setEnabled(False)
        grid_path = standard_data_path(
            'hazard',
            'shake_data',
            '20131105060809',
            'output',
            'grid.xml')
        output_raster = unique_filename(
            prefix='result_grid',
            suffix='.tif',
            dir=temp_dir('test'))
        dialog.load_result.setEnabled(True)
        dialog.load_result.setChecked(False)
        dialog.input_path.setText(grid_path)
        dialog.nearest_mode.setChecked(True)
        dialog.output_path.setText(output_raster)
        button = dialog.button_box.button(QDialogButtonBox.Ok)
        button.click()

        msg = 'Raster is not created'
        output_path = '%s-nearest.tif' % output_raster[:-4]
        self.assertTrue(os.path.exists(output_path), msg)
开发者ID:inasafe,项目名称:inasafe,代码行数:25,代码来源:test_shakemap_converter_dialog.py


示例9: clip_raster

def clip_raster(raster, column_count, row_count, output_extent):
    """Clip raster to specified extent, width and height.

    Note there is similar utility in safe_qgis.utilities.clipper, but it uses
    gdal whereas this one uses native QGIS.

    :param raster: Raster
    :type raster: QgsRasterLayer

    :param column_count: Desired width in pixels of new raster
    :type column_count: Int

    :param row_count: Desired height in pixels of new raster
    :type row_count: Int

    :param output_extent: Extent of the clipped region
    :type output_extent: QgsRectangle

    :returns: Clipped region of the raster
    :rtype: QgsRasterLayer
    """
    provider = raster.dataProvider()
    pipe = QgsRasterPipe()
    pipe.set(provider.clone())

    base_name = unique_filename()
    file_name = base_name + ".tif"
    file_writer = QgsRasterFileWriter(file_name)
    file_writer.writeRaster(pipe, column_count, row_count, output_extent, raster.crs())

    return QgsRasterLayer(file_name, "clipped_raster")
开发者ID:Mloweedgar,项目名称:inasafe,代码行数:31,代码来源:qgis_raster_tools.py


示例10: clone_raster_layer

def clone_raster_layer(name, extension, include_keywords, source_directory, target_directory="test"):
    """Helper function that copies a test raster.

    :param name: The default name for the raster layer.
    :type name: str

    :param extension: The extension of the raster file.
    :type extension: str

    :param include_keywords: Include keywords file if True.
    :type include_keywords: bool

    :param source_directory: Directory where the file is located.
    :type source_directory: str

    :param target_directory: Subdirectory in InaSAFE temp dir that we want to
        put the files into. Default to 'testing'.
    :type target_directory: str
    """
    extensions = [".prj", ".sld", "qml", ".prj", extension]
    if include_keywords:
        extensions.append(".xml")
    temp_path = unique_filename(dir=temp_dir(target_directory))
    # copy to temp file
    for ext in extensions:
        src_path = os.path.join(source_directory, name + ext)
        if os.path.exists(src_path):
            trg_path = temp_path + ext
            shutil.copy2(src_path, trg_path)

    raster_path = "%s%s" % (temp_path, extension)
    layer = QgsRasterLayer(raster_path, os.path.basename(raster_path))
    return layer
开发者ID:inasafe,项目名称:inasafe,代码行数:33,代码来源:utilities.py


示例11: test_standard_properties

    def test_standard_properties(self):
        metadata = AggregationLayerMetadata(unique_filename())
        with self.assertRaises(KeyError):
            metadata.get_property('non_existing_key')

        # from BaseMetadata
        metadata.get_property('organisation')
开发者ID:akbargumbira,项目名称:inasafe,代码行数:7,代码来源:test_aggregation_metadata.py


示例12: print_map_to_pdf

    def print_map_to_pdf(self, output_path):
        """Generate the printout for our final map as pdf.

        :param output_path: Path on the file system to which the pdf should be
            saved. If None, a generated file name will be used.
        :type output_path: str

        :returns: File name of the output file (equivalent to filename if
                provided).
        :rtype: str
        """
        LOGGER.debug('InaSAFE Map print_to_pdf called')
        self.setup_composition()
        try:
            self.load_template()
        except TemplateLoadingError:
            raise
        self.draw_composition()

        if output_path is None:
            output_path = unique_filename(
                prefix='report', suffix='.pdf', dir=temp_dir())

        self.composition.exportAsPDF(output_path)
        return output_path
开发者ID:NyakudyaA,项目名称:inasafe,代码行数:25,代码来源:impact_report.py


示例13: create_grid

def create_grid(size):
    """Create a polygonal grid using Processing.

    :param size: The cell size.
    :type size: int

    :return: The grid layer in memory.
    :rtype: QgsVectorLayer
    """
    output_filename = unique_filename(prefix='grid', suffix='.shp')

    result = processing.runalg(
        'qgis:vectorgrid',
        '336199.970553,352338.397991,7636164.67975,7648562.41208',
        size,  # X spacing
        size,  # Y spacing
        0,  # Output as polygons
        output_filename)

    layer = QgsVectorLayer(output_filename, 'grid', 'ogr')
    layer.setCrs(QgsCoordinateReferenceSystem(32740))

    remove_fields(layer, ['xmin', 'xmax', 'ymin', 'ymax'])

    # Make a copy in memory
    memory = create_memory_layer(
        'grid', layer.geometryType(), layer.crs(), layer.fields())
    copy_layer(layer, memory)

    print "NB cells : %s" % layer.featureCount()

    return memory
开发者ID:ePublicHealth,项目名称:GeoPublicHealth,代码行数:32,代码来源:accessibility.py


示例14: test_convert_grid_to_raster_with_ascii

 def test_convert_grid_to_raster_with_ascii(self):
     """Test converting grid.xml to raster (tif file)"""
     grid_title = 'Earthquake'
     grid_source = 'USGS'
     output_raster = unique_filename(
         prefix='result_grid',
         suffix='.tif',
         dir=temp_dir('test'))
     result = convert_mmi_data(
         GRID_PATH,
         grid_title,
         grid_source,
         algorithm=USE_ASCII,
         output_path=output_raster)
     expected_result = output_raster.replace('.tif', '-%s.tif' % USE_ASCII)
     self.assertEqual(
         result, expected_result,
         'Result path not as expected')
     exists = os.path.exists(result)
     self.assertTrue(exists, 'File result : %s does not exist' % result)
     exists = os.path.exists(result[:-3] + 'xml')
     self.assertTrue(
         exists,
         'File result : %s does not exist' % result[:-3] + 'xml')
     exists = os.path.exists(result[:-3] + 'qml')
     self.assertTrue(
         exists,
         'File result : %s does not exist' % result[:-3] + 'qml')
     tif_file = load_layer(result)[0]
     keywords = tif_file.keywords
     self.assertEqual(keywords['hazard'], hazard_earthquake['key'])
     population_classification = list(keywords['thresholds'][
         exposure_population['key']].keys())[0]
     self.assertEqual(
         population_classification, earthquake_mmi_scale['key'])
开发者ID:inasafe,项目名称:inasafe,代码行数:35,代码来源:test_shake_grid.py


示例15: read_from_qgis_native

    def read_from_qgis_native(self, qgis_layer):
        """Read and unpack vector data from qgis layer QgsVectorLayer.

            A stub is used now:
                save all data in a file,
                then call safe.read_from_file

            Raises:
                * TypeError         if qgis is not avialable
                * IOError           if can't store temporary file
        """
        # FIXME (DK): this branch isn't covered by test
        if not QGIS_IS_AVAILABLE:
            msg = ('Used data is QgsVectorLayer instance, '
                   'but QGIS is not available.')
            raise TypeError(msg)

        base_name = unique_filename()
        file_name = base_name + '.shp'
        error = QgsVectorFileWriter.writeAsVectorFormat(
            qgis_layer,
            file_name,
            "UTF8",
            qgis_layer.crs(),
            "ESRI Shapefile"
        )
        if error != QgsVectorFileWriter.NoError:
            # FIXME (DK): this branch isn't covered by test
            msg = ('Can not save data in temporary file.')
            raise IOError(msg)

        # Write keywords if any
        write_keywords(self.keywords, base_name + '.keywords')
        self.read_from_file(file_name)
开发者ID:cchristelis,项目名称:inasafe,代码行数:34,代码来源:vector.py


示例16: html_to_file

def html_to_file(html, file_path=None, open_browser=False):
    """Save the html to an html file adapting the paths to the filesystem.

    if a file_path is passed, it is used, if not a unique_filename is
    generated.

    :param html: the html for the output file.
    :type html: str

    :param file_path: the path for the html output file.
    :type file_path: str

    :param open_browser: if true open the generated html in an external browser
    :type open_browser: bool
    """
    if file_path is None:
        file_path = unique_filename(suffix='.html')

    # Ensure html is in unicode for codecs module
    html = get_unicode(html)
    with codecs.open(file_path, 'w', encoding='utf-8') as f:
        f.write(html)

    if open_browser:
        open_in_browser(file_path)
开发者ID:felix-yew,项目名称:inasafe,代码行数:25,代码来源:utilities.py


示例17: test_convert_grid_to_raster

 def test_convert_grid_to_raster(self):
     """Test converting grid.xml to raster (tif file)"""
     grid_title = 'Earthquake'
     grid_source = 'USGS'
     output_raster = unique_filename(
         prefix='result_grid',
         suffix='.tif',
         dir=temp_dir('test'))
     result = convert_mmi_data(
         GRID_PATH, grid_title, grid_source, output_path=output_raster,
         algorithm=NEAREST_NEIGHBOUR)
     expected_result = output_raster.replace(
         '.tif', '-%s.tif' % NEAREST_NEIGHBOUR)
     self.assertEqual(
         result, expected_result,
         'Result path not as expected')
     exists = os.path.exists(result)
     self.assertTrue(exists, 'File result : %s does not exist' % result)
     exists = os.path.exists(result[:-3] + 'xml')
     self.assertTrue(
         exists,
         'File result : %s does not exist' % result[:-3] + 'xml')
     exists = os.path.exists(result[:-3] + 'qml')
     self.assertTrue(
         exists,
         'File result : %s does not exist' % result[:-3] + 'qml')
开发者ID:inasafe,项目名称:inasafe,代码行数:26,代码来源:test_shake_grid.py


示例18: test_convert_grid_to_raster

 def test_convert_grid_to_raster(self):
     """Test converting grid.xml to raster (tif file)
     """
     grid_path = os.path.join(TESTDATA, 'grid.xml')
     grid_title = 'Earthquake'
     grid_source = 'USGS'
     output_raster = unique_filename(
         prefix='result_grid',
         suffix='.tif',
         dir=temp_dir('test'))
     result = convert_mmi_data(
         grid_path, grid_title, grid_source, output_raster)
     expected_result = output_raster.replace('.tif', '-nearest.tif')
     self.assertEqual(
         result, expected_result,
         'Result path not as expected')
     exists = os.path.exists(result)
     self.assertTrue(exists, 'File result : %s does not exist' % result)
     exists = os.path.exists(result[:-3] + 'keywords')
     self.assertTrue(
         exists,
         'File result : %s does not exist' % result[:-3] + 'keywords')
     exists = os.path.exists(result[:-3] + 'qml')
     self.assertTrue(
         exists,
         'File result : %s does not exist' % result[:-3] + 'qml')
开发者ID:D2KG,项目名称:FLOOgin,代码行数:26,代码来源:test_shake_grid_converter.py


示例19: clone_shp_layer

def clone_shp_layer(
        name,
        include_keywords,
        source_directory,
        target_directory='test'):
    """Helper function that copies a test shp layer and returns it.

    :param name: The default name for the shp layer.
    :type name: str

    :param include_keywords: Include keywords file if True.
    :type include_keywords: bool

    :param source_directory: Directory where the file is located.
    :type source_directory: str

    :param target_directory: Subdirectory in InaSAFE temp dir that we want to
        put the files into. Default to 'test'.
    :type target_directory: str
    """
    extensions = ['.shp', '.shx', '.dbf', '.prj']
    if include_keywords:
        extensions.append('.keywords')
    temp_path = unique_filename(dir=temp_dir(target_directory))
    # copy to temp file
    for ext in extensions:
        src_path = os.path.join(source_directory, name + ext)
        if os.path.exists(src_path):
            target_path = temp_path + ext
            shutil.copy2(src_path, target_path)

    shp_path = '%s.shp' % temp_path
    layer = QgsVectorLayer(shp_path, os.path.basename(shp_path), 'ogr')
    return layer
开发者ID:Mloweedgar,项目名称:inasafe,代码行数:34,代码来源:utilities.py


示例20: test_sqlite_writing

 def test_sqlite_writing(self):
     """Test that writing a dataset to sqlite works."""
     keywords = {}
     layer = Vector(data=SHP_BASE + '.shp', keywords=keywords)
     test_dir = temp_dir(sub_dir='test')
     test_file = unique_filename(suffix='.sqlite', dir=test_dir)
     layer.write_to_file(test_file, sublayer='foo')
     self.assertTrue(os.path.exists(test_file))
开发者ID:easmetz,项目名称:inasafe,代码行数:8,代码来源:test_vector.py



注:本文中的safe.common.utilities.unique_filename函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utilities.verify函数代码示例发布时间:2022-05-27
下一篇:
Python utilities.unhumanize_number函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap