本文整理汇总了Python中safe.impact_function.impact_function.ImpactFunction.generate_report方法的典型用法代码示例。如果您正苦于以下问题:Python ImpactFunction.generate_report方法的具体用法?Python ImpactFunction.generate_report怎么用?Python ImpactFunction.generate_report使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类safe.impact_function.impact_function.ImpactFunction
的用法示例。
在下文中一共展示了ImpactFunction.generate_report方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_task
# 需要导入模块: from safe.impact_function.impact_function import ImpactFunction [as 别名]
# 或者: from safe.impact_function.impact_function.ImpactFunction import generate_report [as 别名]
#.........这里部分代码省略.........
self.layer_group = self.root.addGroup(group_name)
self.layer_group_container.append(self.layer_group)
# Its a dict containing files for a scenario
success, parameters = self.prepare_task(value)
if not success:
# set status to 'running'
status_item.setText(self.tr('Please update scenario'))
self.disable_busy_cursor()
return False
directory = self.output_directory.text()
if self.scenario_directory_radio.isChecked():
directory = self.source_directory.text()
output_directory = os.path.join(directory, group_name)
if not os.path.exists(output_directory):
os.makedirs(output_directory)
# If impact function parameters loaded successfully, initiate IF.
impact_function = ImpactFunction()
impact_function.datastore = Folder(output_directory)
impact_function.datastore.default_vector_format = "geojson"
impact_function.hazard = parameters[layer_purpose_hazard['key']]
impact_function.exposure = (
parameters[layer_purpose_exposure['key']])
if parameters[layer_purpose_aggregation['key']]:
impact_function.aggregation = (
parameters[layer_purpose_aggregation['key']])
elif parameters['extent']:
impact_function.requested_extent = parameters['extent']
impact_function.crs = parameters['crs']
prepare_status, prepare_message = impact_function.prepare()
if prepare_status == PREPARE_SUCCESS:
LOGGER.info('Impact function ready')
status, message = impact_function.run()
if status == ANALYSIS_SUCCESS:
status_item.setText(self.tr('Analysis Success'))
impact_layer = impact_function.impact
if impact_layer.isValid():
layer_list = [
impact_layer,
impact_function.analysis_impacted,
parameters[layer_purpose_hazard['key']],
parameters[layer_purpose_exposure['key']],
parameters[layer_purpose_aggregation['key']]]
QgsProject.instance().addMapLayers(
layer_list, False)
for layer in layer_list:
self.layer_group.addLayer(layer)
map_canvas = QgsProject.instance().mapLayers()
for layer in map_canvas:
# turn of layer visibility if not impact layer
if map_canvas[layer].id() == impact_layer.id():
self.set_layer_visible(
map_canvas[layer], True)
else:
self.set_layer_visible(
map_canvas[layer], False)
# we need to set analysis_impacted as an active layer
# because we need to get all qgis variables that we
# need from this layer for infographic.
if self.iface:
self.iface.setActiveLayer(
impact_function.analysis_impacted)
report_directory = os.path.join(
output_directory, 'output')
# generate map report and impact report
try:
error_code, message = (
impact_function.generate_report(
all_default_report_components,
report_directory))
except BaseException:
status_item.setText(
self.tr('Report failed to generate.'))
else:
LOGGER.info('Impact layer is invalid')
elif status == ANALYSIS_FAILED_BAD_INPUT:
LOGGER.info('Bad input detected')
elif status == ANALYSIS_FAILED_BAD_CODE:
LOGGER.info(
'Impact function encountered a bug: %s' % message)
else:
LOGGER.warning('Impact function not ready')
send_error_message(self, prepare_message)
else:
LOGGER.exception('Data type not supported: "%s"' % value)
result = False
self.disable_busy_cursor()
return result