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

Python utilities.read_keywords函数代码示例

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

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



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


示例16: testSublayerLoading

 def testSublayerLoading(self):
     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)
     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


示例17: read_from_file

    def read_from_file(self, filename):

        # Open data file for reading
        # File must be kept open, otherwise GDAL methods segfault.
        fid = self.fid = gdal.Open(filename, gdal.GA_ReadOnly)
        if fid is None:
            msg = 'Could not open file %s' % filename
            raise Exception(msg)

        # Record raster metadata from file
        basename, ext = os.path.splitext(filename)

        # If file is ASCII, check that projection is around.
        # GDAL does not check this nicely, so it is worth an
        # error message
        if ext == '.asc':
            try:
                open(basename + '.prj')
            except IOError:
                msg = ('Projection file not found for %s. You must supply '
                       'a projection file with extension .prj' % filename)
                raise RuntimeError(msg)

        # Look for any keywords
        self.keywords = read_keywords(basename + '.keywords')

        # Determine name
        if 'title' in self.keywords:
            rastername = self.keywords['title']
        else:
            # Use basename without leading directories as name
            rastername = os.path.split(basename)[-1]

        self.name = rastername
        self.filename = filename

        self.projection = Projection(self.fid.GetProjection())
        self.geotransform = self.fid.GetGeoTransform()
        self.columns = fid.RasterXSize
        self.rows = fid.RasterYSize
        self.number_of_bands = fid.RasterCount

        # Assume that file contains all data in one band
        msg = 'Only one raster band currently allowed'
        if self.number_of_bands > 1:
            msg = ('WARNING: Number of bands in %s are %i. '
                   'Only the first band will currently be '
                   'used.' % (filename, self.number_of_bands))
            # FIXME(Ole): Let us use python warnings here
            raise Exception(msg)

        # Get first band.
        band = self.band = fid.GetRasterBand(1)
        if band is None:
            msg = 'Could not read raster band from %s' % filename
            raise Exception(msg)
开发者ID:inasafe,项目名称:python-safe,代码行数:56,代码来源:raster.py


示例18: test_qgis_vector_layer_loading

    def test_qgis_vector_layer_loading(self):
        """Test that reading from QgsVectorLayer works."""
        keywords = read_keywords(KEYWORD_PATH, EXPOSURE_SUBLAYER_NAME)
        if QGIS_IS_AVAILABLE:
            qgis_layer = QgsVectorLayer(SHP_BASE + ".shp", "test", "ogr")

            layer = Vector(data=qgis_layer, 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,代码行数:11,代码来源:test_vector.py


示例19: test_convert_to_qgis_vector_layer

    def test_convert_to_qgis_vector_layer(self):
        """Test that converting to QgsVectorLayer works."""
        if QGIS_IS_AVAILABLE:
            # Create vector layer
            keywords = read_keywords(SHP_BASE + ".keywords")
            layer = Vector(data=SHP_BASE + ".shp", keywords=keywords)

            # Convert to QgsVectorLayer
            qgis_layer = layer.as_qgis_native()
            provider = qgis_layer.dataProvider()
            count = provider.featureCount()
            self.assertEqual(count, 250, "Expected 250 features, got %s" % count)
开发者ID:ekaakurniawan,项目名称:jaksafe,代码行数:12,代码来源:test_vector.py


示例20: test_qgis_vector_layer_loading

    def test_qgis_vector_layer_loading(self):
        """Test that reading from QgsVectorLayer works."""
        keywords = read_keywords(KEYWORD_PATH, EXPOSURE_SUBLAYER_NAME)
        if qgis_imported:
            qgis_layer = QgsVectorLayer(SHP_BASE + '.shp', 'test', 'ogr')

            layer = Vector(data=qgis_layer, 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:meymeynard,项目名称:angularsafe,代码行数:13,代码来源:test_vector.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python utilities.write_keywords函数代码示例发布时间:2022-05-27
下一篇:
Python raster.Raster类代码示例发布时间: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