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


Python safe_interface.read_file_keywords函数代码示例

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


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

示例1: test_getKeywordFromFile

    def test_getKeywordFromFile(self):
        """Get keyword from a filesystem file's .keyword file."""

        keyword = read_file_keywords(self.rasterShakePath, "category")
        expected_keyword = "hazard"
        message = "Got: %s\n\nExpected %s\n\nDB: %s" % (keyword, expected_keyword, self.rasterShakePath)
        assert keyword == "hazard", message

        # Test we get an exception if keyword is not found
        try:
            _ = read_file_keywords(self.rasterShakePath, "boguskeyword")
        except KeywordNotFoundError:
            pass  # this is good
        except Exception, e:
            message = ("Request for bogus keyword raised incorrect " "exception type: \n %s") % str(e)
            assert (), message
开发者ID:rendyhermawan,项目名称:inasafe,代码行数:16,代码来源:test_safe_interface.py

示例2: test_copy_keywords

 def test_copy_keywords(self):
     """Test we can copy the keywords."""
     out_path = unique_filename(
         prefix='test_copy_keywords', suffix='.keywords')
     self.keyword_io.copy_keywords(self.raster_layer, out_path)
     copied_keywords = read_file_keywords(out_path)
     expected_keywords = self.expected_raster_keywords
     message = 'Got:\n%s\nExpected:\n%s\nSource:\n%s' % (
         copied_keywords, expected_keywords, out_path)
     self.assertEquals(copied_keywords, expected_keywords, message)
开发者ID:SamudraYe,项目名称:inasafe,代码行数:10,代码来源:test_keyword_io.py

示例3: test_get_keyword_from_file

    def test_get_keyword_from_file(self):
        """Get keyword from a filesystem file's .keyword file."""

        keyword = read_file_keywords(self.rasterShakePath, 'category')
        expected_keyword = 'hazard'
        message = 'Got: %s\n\nExpected %s\n\nDB: %s' % (
            keyword, expected_keyword, self.rasterShakePath)
        self.assertEqual(keyword, 'hazard', message)

        # Test we get an exception if keyword is not found
        try:
            _ = read_file_keywords(self.rasterShakePath,
                                   'boguskeyword')
        except KeywordNotFoundError:
            pass  # this is good
        except Exception, e:
            message = ('Request for bogus keyword raised incorrect '
                       'exception type: \n %s') % str(e)
            assert(), message
开发者ID:SamudraYe,项目名称:inasafe,代码行数:19,代码来源:test_safe_interface.py

示例4: test_available_functions

    def test_available_functions(self):
        """Check we can get the available functions from the impact calculator.
        """
        functions = available_functions()
        message = 'No functions available (len=%ss)' % len(functions)
        self.assertTrue(len(functions) > 0, message)

        # Also test if it works when we give it two layers
        # to see if we can determine which functions will
        # work for them.
        keywords1 = read_file_keywords(self.rasterShakePath)
        keywords2 = read_file_keywords(self.vectorPath)
        # We need to explicitly add the layer type to each keyword list
        keywords1['layertype'] = 'raster'
        keywords2['layertype'] = 'vector'

        functions = [keywords1, keywords2]
        functions = available_functions(functions)
        message = 'No functions available (len=%ss)' % len(functions)
        self.assertTrue(len(functions) > 0, message)
开发者ID:SamudraYe,项目名称:inasafe,代码行数:20,代码来源:test_safe_interface.py

示例5: test_availableFunctions

    def test_availableFunctions(self):
        """Check we can get the available functions from the impact calculator.
        """
        myList = availableFunctions()
        message = "No functions available (len=%ss)" % len(myList)
        assert len(myList) > 0, message

        # Also test if it works when we give it two layers
        # to see if we can determine which functions will
        # work for them.
        keywords1 = read_file_keywords(self.rasterShakePath)
        keywords2 = read_file_keywords(self.vectorPath)
        # We need to explicitly add the layer type to each keyword list
        keywords1["layertype"] = "raster"
        keywords2["layertype"] = "vector"

        myList = [keywords1, keywords2]
        myList = availableFunctions(myList)
        message = "No functions available (len=%ss)" % len(myList)
        assert len(myList) > 0, message
开发者ID:rendyhermawan,项目名称:inasafe,代码行数:20,代码来源:test_safe_interface.py

示例6: make_point_layer

def make_point_layer():
    """Helper function that returns a single predefined layer."""
    path = 'test_buildings.shp'
    full_path = os.path.join(TESTDATA, path)
    try:
        title = read_file_keywords(full_path, 'title')
    except KeywordNotFoundError:
        title = 'kabupaten_jakarta_singlepart_3_good_attr'
    layer = QgsVectorLayer(full_path, title, 'ogr')
    # noinspection PyArgumentList
    QgsMapLayerRegistry.instance().addMapLayers([layer])
    return layer
开发者ID:cccs-ip,项目名称:inasafe,代码行数:12,代码来源:test_keywords_dialog.py

示例7: makePointLayer

def makePointLayer():
    """Helper function that returns a single predefined layer"""
    myFile = 'test_buildings.shp'
    myPath = os.path.join(TESTDATA, myFile)
    try:
        myTitle = read_file_keywords(myPath, 'title')
    except KeywordNotFoundError:
        myTitle = 'kabupaten_jakarta_singlepart_3_good_attr'
    myLayer = QgsVectorLayer(myPath, myTitle, 'ogr')
    # noinspection PyArgumentList
    QgsMapLayerRegistry.instance().addMapLayer(myLayer)
    return myLayer
开发者ID:vdeparday,项目名称:inasafe,代码行数:12,代码来源:test_keywords_dialog.py

示例8: make_padang_layer

def make_padang_layer():
    """Helper function that returns a single predefined layer."""
    path = 'Shakemap_Padang_2009.asc'
    full_path = os.path.join(HAZDATA, path)
    title = read_file_keywords(full_path, 'title')
    # title = 'An earthquake in Padang like in 2009'
    layer = QgsRasterLayer(full_path, title)
    if qgis_version() >= 10800:  # 1.8 or newer
        # noinspection PyArgumentList
        QgsMapLayerRegistry.instance().addMapLayers([layer])
    else:
        # noinspection PyArgumentList
        QgsMapLayerRegistry.instance().addMapLayer(layer)
    return layer
开发者ID:FlavioFalcao,项目名称:inasafe,代码行数:14,代码来源:test_keywords_dialog.py

示例9: makePadangLayer

def makePadangLayer():
    """Helper function that returns a single predefined layer"""
    myFile = 'Shakemap_Padang_2009.asc'
    myPath = os.path.join(HAZDATA, myFile)
    myTitle = read_file_keywords(myPath, 'title')
    # myTitle = 'An earthquake in Padang like in 2009'
    myLayer = QgsRasterLayer(myPath, myTitle)
    if qgis_version() >= 10800:  # 1.8 or newer
        # noinspection PyArgumentList
        QgsMapLayerRegistry.instance().addMapLayers([myLayer])
    else:
        # noinspection PyArgumentList
        QgsMapLayerRegistry.instance().addMapLayer(myLayer)
    return myLayer
开发者ID:vdeparday,项目名称:inasafe,代码行数:14,代码来源:test_keywords_dialog.py

示例10: load_layer

def load_layer(layer_file, directory=TESTDATA):
    """Helper to load and return a single QGIS layer

    :param layer_file: Path name to raster or vector file.
    :type layer_file: str
    :param directory: Optional parent dir. If None, path name is assumed
        to be absolute.
    :type directory: str, None

    :returns: tuple containing layer and its category.
    :rtype: (QgsMapLayer, str)

    """

    # Extract basename and absolute path
    file_path = os.path.split(layer_file)[-1]  # In case path was absolute
    base_name, extension = os.path.splitext(file_path)
    if directory is None:
        path = layer_file
    else:
        path = os.path.join(directory, layer_file)
    keyword_path = path[:-4] + '.keywords'

    # Determine if layer is hazard or exposure
    keywords = read_file_keywords(keyword_path)
    category = 'undefined'
    if 'category' in keywords:
        category = keywords['category']
    message = 'Could not read %s' % keyword_path
    assert keywords is not None, message

    # Create QGis Layer Instance
    if extension in ['.asc', '.tif']:
        layer = QgsRasterLayer(path, base_name)
    elif extension in ['.shp']:
        layer = QgsVectorLayer(path, base_name, 'ogr')
    else:
        message = 'File %s had illegal extension' % path
        raise Exception(message)

    # noinspection PyUnresolvedReferences
    message = 'Layer "%s" is not valid' % str(layer.source())
    # noinspection PyUnresolvedReferences
    if not layer.isValid():
        print message
    # noinspection PyUnresolvedReferences
    assert layer.isValid(), message
    return layer, category
开发者ID:mahardika,项目名称:inasafe,代码行数:48,代码来源:utilities_for_testing.py

示例11: read_keywords

    def read_keywords(self, layer, keyword=None):
        """Read keywords for a datasource and return them as a dictionary.

        This is a wrapper method that will 'do the right thing' to fetch
        keywords for the given datasource. In particular, if the datasource
        is remote (e.g. a database connection) it will fetch the keywords from
        the keywords store.

        :param layer:  A QGIS QgsMapLayer instance that you want to obtain
            the keywords for.
        :type layer: QgsMapLayer, QgsRasterLayer, QgsVectorLayer,
            QgsPluginLayer

        :param keyword: If set, will extract only the specified keyword
              from the keywords dict.
        :type keyword: str

        :returns: A dict if keyword is omitted, otherwise the value for the
            given key if it is present.
        :rtype: dict, str

        TODO: Don't raise generic exceptions.

        :raises: HashNotFoundError, Exception, OperationalError,
            NoKeywordsFoundError, KeywordNotFoundError, InvalidParameterError,
            UnsupportedProviderError

        """
        source = str(layer.source())
        try:
            flag = self.are_keywords_file_based(layer)
        except UnsupportedProviderError:
            raise

        try:
            if flag:
                keywords = read_file_keywords(source, keyword)
            else:
                keywords = self.read_keyword_from_uri(source, keyword)
            return keywords
        except (HashNotFoundError,
                Exception,
                OperationalError,
                NoKeywordsFoundError,
                KeywordNotFoundError,
                InvalidParameterError,
                UnsupportedProviderError):
            raise
开发者ID:cccs-ip,项目名称:inasafe,代码行数:48,代码来源:keyword_io.py

示例12: make_polygon_layer

def make_polygon_layer():
    """Helper function that returns a single predefined layer."""
    path = 'kabupaten_jakarta_singlepart_3_good_attr.shp'
    full_path = os.path.join(TESTDATA, path)
    try:
        title = read_file_keywords(full_path, 'title')
    except KeywordNotFoundError:
        title = 'kabupaten_jakarta_singlepart_3_good_attr'
    layer = QgsVectorLayer(full_path, title, 'ogr')
    if qgis_version() >= 10800:  # 1.8 or newer
        # noinspection PyArgumentList
        QgsMapLayerRegistry.instance().addMapLayers([layer])
    else:
        # noinspection PyArgumentList
        QgsMapLayerRegistry.instance().addMapLayer(layer)
    return layer
开发者ID:mahardika,项目名称:inasafe,代码行数:16,代码来源:test_keywords_dialog.py

示例13: makePolygonLayer

def makePolygonLayer():
    """Helper function that returns a single predefined layer"""
    myFile = 'kabupaten_jakarta_singlepart_3_good_attr.shp'
    myPath = os.path.join(TESTDATA, myFile)
    try:
        myTitle = read_file_keywords(myPath, 'title')
    except KeywordNotFoundError:
        myTitle = 'kabupaten_jakarta_singlepart_3_good_attr'
    myLayer = QgsVectorLayer(myPath, myTitle, 'ogr')
    if qgis_version() >= 10800:  # 1.8 or newer
        # noinspection PyArgumentList
        QgsMapLayerRegistry.instance().addMapLayers([myLayer])
    else:
        # noinspection PyArgumentList
        QgsMapLayerRegistry.instance().addMapLayer(myLayer)
    return myLayer
开发者ID:vdeparday,项目名称:inasafe,代码行数:16,代码来源:test_keywords_dialog.py

示例14: load_layer

def load_layer(layer_file, directory=TESTDATA):
    """Helper to load and return a single QGIS layer

    :param layer_file: Path name to raster or vector file.
    :type layer_file: str
    :param directory: Optional parent dir. If None, path name is assumed
        to be absolute.
    :type directory: str, None

    :returns: tuple containing layer and its category.
    :rtype: (QgsMapLayer, str)

    """

    # Extract basename and absolute path
    file_path = os.path.split(layer_file)[-1]  # In case path was absolute
    base_name, extension = os.path.splitext(file_path)
    if directory is None:
        path = layer_file
    else:
        path = os.path.join(directory, layer_file)
    keyword_path = path[:-4] + ".keywords"

    # Determine if layer is hazard or exposure
    keywords = read_file_keywords(keyword_path)
    category = "undefined"
    if "category" in keywords:
        category = keywords["category"]
    message = "Could not read %s" % keyword_path
    assert keywords is not None, message

    # Create QGis Layer Instance
    if extension in [".asc", ".tif"]:
        layer = QgsRasterLayer(path, base_name)
    elif extension in [".shp"]:
        layer = QgsVectorLayer(path, base_name, "ogr")
    else:
        message = "File %s had illegal extension" % path
        raise Exception(message)

    message = 'Layer "%s" is not valid' % str(layer.source())
    assert layer.isValid(), message
    return layer, category
开发者ID:vdeparday,项目名称:inasafe,代码行数:43,代码来源:utilities_for_testing.py

示例15: load_layer

def load_layer(layer_file, directory=TESTDATA):
    """Helper to load and return a single QGIS layer

    :param layer_file: Path name to raster or vector file.
    :type layer_file: str
    :param directory: Optional parent dir. If None, path name is assumed
        to be absolute.
    :type directory: str, None

    :returns: tuple containing layer and its category.
    :rtype: (QgsMapLayer, str)

    """

    # Extract basename and absolute path
    myFilename = os.path.split(layer_file)[-1]  # In case path was absolute
    myBaseName, myExt = os.path.splitext(myFilename)
    if directory is None:
        myPath = layer_file
    else:
        myPath = os.path.join(directory, layer_file)
    myKeywordPath = myPath[:-4] + '.keywords'

    # Determine if layer is hazard or exposure
    myKeywords = read_file_keywords(myKeywordPath)
    myCategory = 'undefined'
    if 'category' in myKeywords:
        myCategory = myKeywords['category']
    myMessage = 'Could not read %s' % myKeywordPath
    assert myKeywords is not None, myMessage

    # Create QGis Layer Instance
    if myExt in ['.asc', '.tif']:
        myLayer = QgsRasterLayer(myPath, myBaseName)
    elif myExt in ['.shp']:
        myLayer = QgsVectorLayer(myPath, myBaseName, 'ogr')
    else:
        myMessage = 'File %s had illegal extension' % myPath
        raise Exception(myMessage)

    myMessage = 'Layer "%s" is not valid' % str(myLayer.source())
    assert myLayer.isValid(), myMessage
    return myLayer, myCategory
开发者ID:CharlesRethman,项目名称:inasafe,代码行数:43,代码来源:utilities_for_testing.py


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