本文整理汇总了Python中safe.report.template_composition.TemplateComposition.load_template方法的典型用法代码示例。如果您正苦于以下问题:Python TemplateComposition.load_template方法的具体用法?Python TemplateComposition.load_template怎么用?Python TemplateComposition.load_template使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类safe.report.template_composition.TemplateComposition
的用法示例。
在下文中一共展示了TemplateComposition.load_template方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_load_template
# 需要导入模块: from safe.report.template_composition import TemplateComposition [as 别名]
# 或者: from safe.report.template_composition.TemplateComposition import load_template [as 别名]
def test_load_template(self):
"""Test we can load template correctly."""
# Copy the inasafe template to temp dir
template_path = os.path.join(
temp_dir('test'), 'a4-portrait-blue.qpt')
shutil.copy2(INASAFE_TEMPLATE_PATH, template_path)
template_composition = TemplateComposition(
template_path=template_path,
map_settings=CANVAS.mapSettings())
template_composition.load_template()
# Check the element of the composition
# In that template, there should be these components:
component_ids = [
'white-inasafe-logo',
'north-arrow',
'organisation-logo',
'impact-map',
'impact-legend']
for component_id in component_ids:
component = template_composition.composition.getComposerItemById(
component_id)
message = ('In this template: %s, there should be this component '
'%s') % (INASAFE_TEMPLATE_PATH, component_id)
self.assertIsNotNone(component, message)
示例2: ImpactReport
# 需要导入模块: from safe.report.template_composition import TemplateComposition [as 别名]
# 或者: from safe.report.template_composition.TemplateComposition import load_template [as 别名]
#.........这里部分代码省略.........
def map_legend_attributes(self):
"""Get the map legend attribute from the layer keywords if possible.
:returns: None on error, otherwise the attributes (notes and units).
:rtype: None, str
"""
LOGGER.debug('InaSAFE Map getMapLegendAttributes called')
legend_attribute_list = [
'legend_notes',
'legend_units',
'legend_title']
legend_attribute_dict = {}
for legend_attribute in legend_attribute_list:
# noinspection PyBroadException
try:
legend_attribute_dict[legend_attribute] = \
self._keyword_io.read_keywords(
self.layer, legend_attribute)
except KeywordNotFoundError:
pass
except Exception: # pylint: disable=broad-except
pass
return legend_attribute_dict
def setup_composition(self):
"""Set up the composition ready."""
# noinspection PyUnresolvedReferences
self._template_composition.composition.setPlotStyle(
QgsComposition.Preview)
self._template_composition.composition.setPrintResolution(
self.page_dpi)
self._template_composition.composition.setPrintAsRaster(True)
def load_template(self):
"""Load the template to composition."""
# Get information for substitutions
# date, time and plugin version
date_time = self._keyword_io.read_keywords(self.layer, 'time_stamp')
if date_time is None:
date = ''
time = ''
else:
tokens = date_time.split('_')
date = tokens[0]
time = tokens[1]
long_version = get_version()
tokens = long_version.split('.')
version = '%s.%s.%s' % (tokens[0], tokens[1], tokens[2])
# Get title of the layer
title = self.map_title
if not title:
title = ''
# Prepare the substitution map
substitution_map = {
'impact-title': title,
'date': date,
'time': time,
'safe-version': version,
'disclaimer': self.disclaimer
}
# Load template
self._template_composition.substitution = substitution_map
try:
self._template_composition.load_template()
示例3: load_template
# 需要导入模块: from safe.report.template_composition import TemplateComposition [as 别名]
# 或者: from safe.report.template_composition.TemplateComposition import load_template [as 别名]
def load_template(self, map_settings):
"""Load composer template for merged report.
Validate it as well. The template needs to have:
1. QgsComposerMap with id 'impact-map' for merged impact map.
2. QgsComposerPicture with id 'safe-logo' for InaSAFE logo.
3. QgsComposerLabel with id 'summary-report' for a summary of two
impacts.
4. QgsComposerLabel with id 'aggregation-area' to indicate the area
of aggregation.
5. QgsComposerScaleBar with id 'map-scale' for impact map scale.
6. QgsComposerLegend with id 'map-legend' for impact map legend.
7. QgsComposerPicture with id 'organisation-logo' for organisation
logo.
8. QgsComposerLegend with id 'impact-legend' for map legend.
9. QgsComposerHTML with id 'merged-report-table' for the merged report.
:param map_settings: Map settings.
:type map_settings: QgsMapSettings, QgsMapRenderer
"""
# Create Composition
template_composition = TemplateComposition(
self.template_path, map_settings)
# Validate the component in the template
component_ids = ['impact-map', 'safe-logo', 'summary-report',
'aggregation-area', 'map-scale', 'map-legend',
'organisation-logo', 'merged-report-table']
template_composition.component_ids = component_ids
if len(template_composition.missing_elements) > 0:
raise ReportCreationError(self.tr(
'Components: %s could not be found' % ', '.join(
template_composition.missing_elements)))
# Prepare map substitution and set to composition
impact_title = '%s and %s' % (
self.first_impact['map_title'],
self.second_impact['map_title'])
substitution_map = {
'impact-title': impact_title,
'hazard-title': self.first_impact['hazard_title'],
'disclaimer': self.disclaimer
}
template_composition.substitution = substitution_map
# Load Template
try:
template_composition.load_template()
except TemplateLoadingError:
raise
# Draw Composition
# Set InaSAFE logo
composition = template_composition.composition
safe_logo = composition.getComposerItemById('safe-logo')
safe_logo.setPictureFile(self.safe_logo_path)
# set organisation logo
org_logo = composition.getComposerItemById('organisation-logo')
org_logo.setPictureFile(self.organisation_logo_path)
# Set Map Legend
legend = composition.getComposerItemById('map-legend')
if qgis_version() < 20400:
layers = map_settings.layerSet()
else:
layers = map_settings.layers()
if qgis_version() < 20600:
legend.model().setLayerSet(layers)
legend.synchronizeWithModel()
else:
root_group = legend.modelV2().rootGroup()
layer_ids = map_settings.layers()
for layer_id in layer_ids:
# noinspection PyUnresolvedReferences
layer = QgsMapLayerRegistry.instance().mapLayer(layer_id)
root_group.addLayer(layer)
legend.synchronizeWithModel()
return composition