本文整理汇总了Python中safe.utilities.keyword_io.KeywordIO.get方法的典型用法代码示例。如果您正苦于以下问题:Python KeywordIO.get方法的具体用法?Python KeywordIO.get怎么用?Python KeywordIO.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类safe.utilities.keyword_io.KeywordIO
的用法示例。
在下文中一共展示了KeywordIO.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: layer_changed
# 需要导入模块: from safe.utilities.keyword_io import KeywordIO [as 别名]
# 或者: from safe.utilities.keyword_io.KeywordIO import get [as 别名]
def layer_changed(self, layer):
"""Enable or disable keywords editor icon when active layer changes.
:param layer: The layer that is now active.
:type layer: QgsMapLayer
"""
if not layer:
enable_keyword_wizard = False
elif not hasattr(layer, 'providerType'):
enable_keyword_wizard = False
elif layer.providerType() == 'wms':
enable_keyword_wizard = False
elif is_raster_layer(layer) and layer.bandCount() > 1:
enable_keyword_wizard = False
else:
enable_keyword_wizard = True
try:
if layer:
if is_raster_layer(layer):
enable_field_mapping_tool = False
else:
keywords = KeywordIO().read_keywords(layer)
layer_purpose = keywords.get('layer_purpose')
if not layer_purpose:
enable_field_mapping_tool = False
if layer_purpose == layer_purpose_exposure['key']:
layer_subcategory = keywords.get('exposure')
elif layer_purpose == layer_purpose_hazard['key']:
layer_subcategory = keywords.get('hazard')
else:
layer_subcategory = None
field_groups = get_field_groups(
layer_purpose, layer_subcategory)
if len(field_groups) == 0:
# No field group, disable field mapping tool.
enable_field_mapping_tool = False
else:
enable_field_mapping_tool = True
else:
enable_field_mapping_tool = False
except (KeywordNotFoundError, NoKeywordsFoundError, MetadataReadError):
# No keywords, disable field mapping tool.
enable_field_mapping_tool = False
self.action_keywords_wizard.setEnabled(enable_keyword_wizard)
self.action_field_mapping.setEnabled(enable_field_mapping_tool)
示例2: check_input_layer
# 需要导入模块: from safe.utilities.keyword_io import KeywordIO [as 别名]
# 或者: from safe.utilities.keyword_io.KeywordIO import get [as 别名]
def check_input_layer(layer, purpose):
"""Function to check if the layer is valid.
The function will also set the monkey patching if needed.
:param layer: The layer to test.
:type layer: QgsMapLayer
:param purpose: The expected purpose of the layer.
:type purpose: basestring
:return: A tuple with the status of the layer and an error message if
needed.
The status is 0 if everything was fine.
The status is 1 if the client should fix something.
:rtype: (int, m.Message)
"""
if not layer.isValid():
title = tr(
'The {purpose} layer is invalid').format(purpose=purpose)
content = tr(
'The impact function needs a {exposure} layer to run. '
'You must provide a valid {exposure} layer.').format(
purpose=purpose)
message = generate_input_error_message(
title, m.Paragraph(content))
return PREPARE_FAILED_BAD_INPUT, message
# We should read it using KeywordIO for the very beginning. To avoid
# get the modified keywords in the patching.
try:
keywords = KeywordIO().read_keywords(layer)
except NoKeywordsFoundError:
title = tr(
'The {purpose} layer does not have keywords.').format(
purpose=purpose)
content = tr(
'The {purpose} layer does not have keywords. Use the wizard '
'to assign keywords to the layer.').format(purpose=purpose)
message = generate_input_error_message(
title, m.Paragraph(content))
return PREPARE_FAILED_BAD_INPUT, message
if keywords.get('layer_purpose') != purpose:
title = tr('The expected {purpose} layer is not an {purpose}.') \
.format(purpose=purpose)
content = tr('The expected {purpose} layer is not an {purpose}.') \
.format(purpose=purpose)
message = generate_input_error_message(
title, m.Paragraph(content))
return PREPARE_FAILED_BAD_INPUT, message
version = keywords.get(inasafe_keyword_version_key)
supported = is_keyword_version_supported(version)
if not supported:
parameters = {
'version': inasafe_keyword_version,
'source': layer.publicSource()
}
title = tr('The {purpose} layer is not up to date.').format(
purpose=purpose)
content = tr(
'The layer {source} must be updated to {version}.').format(
**parameters)
message = generate_input_error_message(
title, m.Paragraph(content))
return PREPARE_FAILED_BAD_INPUT, message
layer.keywords = keywords
if is_vector_layer(layer):
try:
check_inasafe_fields(layer, keywords_only=True)
except InvalidLayerError:
title = tr('The {purpose} layer is not up to date.').format(
purpose=purpose)
content = tr(
'The layer {source} must be updated with the keyword '
'wizard. Your fields which have been set in the keywords '
'previously are not matching your layer.').format(
source=layer.publicSource())
message = generate_input_error_message(
title, m.Paragraph(content))
del layer.keywords
return PREPARE_FAILED_BAD_INPUT, message
return PREPARE_SUCCESS, None