当前位置: 首页>>代码示例>>Python>>正文


Python utilities.read_keywords函数代码示例

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


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

示例1: test_write_keywords

 def test_write_keywords(self):
     """Test writing keywords with no sublayer, no existing file."""
     keywords = DKI_KEYWORDS
     filename = self.make_temp_file()
     write_keywords(keywords, filename)
     # Read back contents and check against control dataset
     control_keywords = read_keywords(SIMPLE_PATH, all_blocks=True)
     actual_keywords = read_keywords(filename, all_blocks=True)
     msg = 'Expected:\n%s\nGot:\n%s\n' % (control_keywords, actual_keywords)
     assert control_keywords == actual_keywords, msg
开发者ID:takmid,项目名称:inasafe,代码行数:10,代码来源:test_utilities.py

示例2: test_write_keywords_singlesublayer

    def test_write_keywords_singlesublayer(self):
        """Test writing keywords for single sublayer, no existing file."""

        filename = self.make_temp_file()
        write_keywords(OSM_KEYWORDS, filename=filename, sublayer='osm')
        # read back contents and check against control dataset
        control_path = test_data_path('other', 'expected_singlelayer.keywords')
        control_keywords = read_keywords(control_path, all_blocks=True)
        actual_keywords = read_keywords(filename, all_blocks=True)
        msg = 'Expected:\n%s\nGot:\n%s\n' % (control_keywords, actual_keywords)
        assert control_keywords == actual_keywords, msg
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:11,代码来源:test_utilities.py

示例3: test_write_keywords_singlesublayer

    def test_write_keywords_singlesublayer(self):
        """Test writing keywords for single sublayer, no existing file."""

        filename = self.make_temp_file()
        write_keywords(OSM_KEYWORDS, filename=filename, sublayer="osm")
        # read back contents and check against control dataset
        control_path = os.path.abspath(os.path.join(UNITDATA, "other", "expected_singlelayer.keywords"))
        control_keywords = read_keywords(control_path, all_blocks=True)
        actual_keywords = read_keywords(filename, all_blocks=True)
        msg = "Expected:\n%s\nGot:\n%s\n" % (control_keywords, actual_keywords)
        assert control_keywords == actual_keywords, msg
开发者ID:rlbartolome,项目名称:inasafe,代码行数:11,代码来源:test_utilities.py

示例4: test_write_keywords_multisublayer

    def test_write_keywords_multisublayer(self):
        """Test writing keywords for named sublayer, no existing file."""

        filename = self.make_temp_file()
        write_keywords(DKI_KEYWORDS, filename=filename, sublayer="dki")
        write_keywords(OSM_KEYWORDS, filename=filename, sublayer="osm")
        # Read back contents and check against control dataset
        control_path = test_data_path("other", "expected_multilayer.keywords")
        control_keywords = read_keywords(control_path, all_blocks=True)
        actual_keywords = read_keywords(filename, all_blocks=True)
        msg = "Expected:\n%s\nGot:\n%s\n" % (control_keywords, actual_keywords)
        assert control_keywords == actual_keywords, msg
开发者ID:Samweli,项目名称:inasafe,代码行数:12,代码来源:test_utilities.py

示例5: test_write_keywords_multisublayer

    def test_write_keywords_multisublayer(self):
        """Test writing keywords for named sublayer, no existing file."""

        filename = self.make_temp_file()
        write_keywords(DKI_KEYWORDS, filename=filename, sublayer='dki')
        write_keywords(OSM_KEYWORDS, filename=filename, sublayer='osm')
        # Read back contents and check against control dataset
        control_path = os.path.abspath(
            os.path.join(UNITDATA, 'other', 'expected_multilayer.keywords'))
        control_keywords = read_keywords(control_path, all_blocks=True)
        actual_keywords = read_keywords(filename, all_blocks=True)
        msg = 'Expected:\n%s\nGot:\n%s\n' % (control_keywords, actual_keywords)
        assert control_keywords == actual_keywords, msg
开发者ID:takmid,项目名称:inasafe,代码行数:13,代码来源:test_utilities.py

示例6: test_read_keywords_for_sublayer

 def test_read_keywords_for_sublayer(self):
     """Test reading keywords for specific sublayer."""
     keywords = read_keywords(KEYWORD_PATH, sublayer='osm_flood')
     expected_keywords = OSM_KEYWORDS
     msg = 'Expected:\n%s\nGot:\n%s\n' % (expected_keywords, keywords)
     self.assertEquals(keywords, expected_keywords, msg)
     LOGGER.debug(keywords)
开发者ID:takmid,项目名称:inasafe,代码行数:7,代码来源:test_utilities.py

示例7: test_read_keywords_simple

 def test_read_keywords_simple(self):
     """Test reading keywords from keywords file with no sublayers"""
     keywords = read_keywords(SIMPLE_PATH)
     expected_keywords = DKI_KEYWORDS
     msg = 'Expected:\n%s\nGot:\n%s\n' % (expected_keywords, keywords)
     self.assertEquals(keywords, expected_keywords, msg)
     LOGGER.debug(keywords)
开发者ID:takmid,项目名称:inasafe,代码行数:7,代码来源:test_utilities.py

示例8: test_read_all_keywords

 def test_read_all_keywords(self):
     """Test reading all keywords for all layers"""
     keywords = read_keywords(KEYWORD_PATH, all_blocks=True)
     expected_keywords = {"osm_buildings": DKI_KEYWORDS, "osm_flood": OSM_KEYWORDS}
     msg = "Expected:\n%s\nGot:\n%s\n" % (expected_keywords, keywords)
     self.assertEquals(keywords, expected_keywords, msg)
     LOGGER.debug(keywords)
开发者ID:Samweli,项目名称:inasafe,代码行数:7,代码来源:test_utilities.py

示例9: test_read_keywords

 def test_read_keywords(self):
     """Test reading keywords - get first block from kwds as default."""
     keywords = read_keywords(KEYWORD_PATH)
     expected_keywords = DKI_KEYWORDS
     msg = 'Expected:\n%s\nGot:\n%s\n' % (expected_keywords, keywords)
     self.assertEquals(keywords, expected_keywords, msg)
     LOGGER.debug(keywords)
开发者ID:takmid,项目名称:inasafe,代码行数:7,代码来源:test_utilities.py

示例10: 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

示例11: test_sqlite_writing

 def test_sqlite_writing(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")
     self.assertTrue(os.path.exists(test_file))
开发者ID:ekaakurniawan,项目名称:jaksafe,代码行数:8,代码来源:test_vector.py

示例12: test_shapefile_loading

 def test_shapefile_loading(self):
     """Test that loading a dataset with no sublayers works."""
     keywords = read_keywords(SHP_BASE + ".keywords")
     layer = Vector(data=SHP_BASE + ".shp", keywords=keywords)
     msg = "Expected layer to be a polygon layer, got a %s" % layer.geometry_type
     self.assertTrue(layer.is_polygon_data, msg)
     count = len(layer)
     self.assertEqual(count, 250, "Expected 250 features, got %s" % count)
开发者ID:ekaakurniawan,项目名称:jaksafe,代码行数:8,代码来源:test_vector.py

示例13: test_sublayer_loading

 def test_sublayer_loading(self):
     """Test if we can load sublayers."""
     keywords = read_keywords(KEYWORD_PATH, EXPOSURE_SUBLAYER_NAME)
     layer = Vector(data=SQLITE_PATH, keywords=keywords, sublayer=EXPOSURE_SUBLAYER_NAME)
     msg = "Expected layer to be a polygon layer, got a %s" % layer.geometry_type
     self.assertTrue(layer.is_polygon_data, msg)
     count = len(layer)
     self.assertEqual(count, 250, "Expected 250 features, got %s" % count)
开发者ID:ekaakurniawan,项目名称:jaksafe,代码行数:8,代码来源:test_vector.py

示例14: testShpLoading

 def testShpLoading(self):
     """Test that loading a dataset with no sublayers works."""
     keywords = read_keywords(SHP_BASE + '.keywords')
     layer = Vector(data=SHP_BASE + '.shp', keywords=keywords)
     msg = ('Expected layer to be a polygon layer, got a %s' %
            layer.geometry_type)
     assert layer.is_polygon_data, msg
     count = len(layer)
     assert count == 250, 'Expected 250 features, got %s' % count
开发者ID:gijs,项目名称:inasafe,代码行数:9,代码来源:test_vector.py

示例15: read_file_keywords

def read_file_keywords(layer_path, keyword=None):
    """Get metadata from the keywords file associated with a local
     file in the file system.

    .. note:: Requires a str representing a file path instance
              as parameter As opposed to read_keywords_from_layer which
              takes a inasafe file object as parameter.

    .. seealso:: read_keywords_from_layer

    :param: layer_path: a string representing a path to a layer
           (e.g. '/tmp/foo.shp', '/tmp/foo.tif')
    :type layer_path: str

    :param keyword: optional - the metadata keyword to retrieve e.g. 'title'
    :type keyword: str

    :return: A string containing the retrieved value for the keyword if
             the keyword argument is specified, otherwise the
             complete keywords dictionary is returned.

    :raises: KeywordNotFoundError, NoKeywordsFoundError, InvalidParameterError

    Note:
        * KeywordNotFoundError - occurs when the keyword is not recognised.
        * NoKeywordsFoundError - occurs when no keyword file exists.
        * InvalidParameterError - occurs when the layer does not exist.
    """
    # check the source layer path is valid
    if not os.path.isfile(layer_path):
        message = tr('Cannot get keywords from a non-existent file. File '
                     '%s does not exist.' % layer_path)
        raise InvalidParameterError(message)

    # check there really is a keywords file for this layer
    # priority for iso path first
    keyword_file_path = os.path.splitext(layer_path)[0]
    keyword_file_path += '.keywords'
    keyword_iso_path = os.path.splitext(layer_path)[0]
    keyword_iso_path += '.xml'
    if not os.path.isfile(keyword_file_path)\
            and not os.path.isfile(keyword_iso_path):
        message = tr('No keywords file found for %s' % keyword_file_path)
        raise NoKeywordsFoundError(message)
    elif os.path.isfile(keyword_file_path) \
            and not os.path.isfile(keyword_iso_path):
        # switch to .keywords file if iso xml file didn't exist
        keyword_iso_path = keyword_file_path

    # now get the requested keyword using the inasafe library
    try:
        dictionary = read_keywords(keyword_iso_path)
    except Exception, e:
        message = tr(
            'Keyword retrieval failed for %s (%s) \n %s' % (
                keyword_file_path, keyword, str(e)))
        raise KeywordNotFoundError(message)
开发者ID:tomkralidis,项目名称:inasafe,代码行数:57,代码来源:utilities.py


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