Module: safe_qgis.map
- InaSAFE Disaster risk assessment tool developed by AusAid -
- InaSAFE map making module.
Contact : ole.moller.nielsen@gmail.com
Note
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
-
class safe_qgis.map.Map(theIface)[source]
A class for creating a map.
-
composeMap()[source]
Place all elements on the map ready for printing.
- Args:
- None
- Returns:
- None
- Raises:
- Any exceptions raised will be propagated.
-
drawDisclaimer()[source]
Add a disclaimer to the composition.
- Args:
- None
- Returns:
- None
- Raises:
- None
-
drawGraticuleMask(theTopOffset)[source]
A helper function to mask out graticule labels on the right side
by over painting a white rectangle with white border on them.
- Args:
- theTopOffset - vertical offset at which the map should be drawn
- Returns:
- None
- Raises:
- None
-
drawHostAndTime(theTopOffset)[source]
Add a disclaimer to the composition.
- Args:
- theTopOffset - vertical offset at which to begin drawing
- Returns:
- None
- Raises:
- None
-
drawImpactTitle(theTopOffset)[source]
Draw the map subtitle - obtained from the impact layer keywords.
- Args:
- theTopOffset - vertical offset at which to begin drawing
- Returns:
- float - the height of the label as rendered
- Raises:
- None
-
drawLegend(theTopOffset)[source]
Add a legend to the map using our custom legend renderer.
Note
getLegend generates a pixmap in 150dpi so if you set
the map to a higher dpi it will appear undersized.
- Args:
- theTopOffset - vertical offset at which to begin drawing
- Returns:
- None
- Raises:
- None
-
drawLogo(theTopOffset)[source]
Add a picture containing the logo to the map top left corner
- Args:
- theTopOffset - vertical offset at which the logo shoudl be drawn
- Returns:
- None
- Raises:
- None
-
drawMap(theTopOffset)[source]
Add a map to the composition and return the compsermap instance.
- Args:
- theTopOffset - vertical offset at which the map should be drawn
- Returns:
- A QgsComposerMap instance is returned
- Raises:
- None
-
drawNativeScaleBar(theComposerMap, theTopOffset)[source]
Draw a scale bar using QGIS’ native drawing - in the case of
geographic maps, scale will be in degrees, not km.
- Args:
- None
- Returns:
- None
- Raises:
- Any exceptions raised by the InaSAFE library will be propagated.
-
drawPixmap(thePixmap, theWidthMM, theLeftOffset, theTopOffset)[source]
Helper to draw a pixmap directly onto the QGraphicsScene.
This is an alternative to using QgsComposerPicture which in
some cases leaves artifacts under windows.
The Pixmap will have a transform applied to it so that
it is rendered with the same resolution as the composition.
Args:
- thePixmap
- theWidthMM - desired width in mm of output on page
- theLeftOffset
- theTopOffset
- Returns:
- QGraphicsSceneItem is returned
- Raises:
- None
-
drawScaleBar(theComposerMap, theTopOffset)[source]
Add a numeric scale to the bottom left of the map
We draw the scale bar manually because QGIS does not yet support
rendering a scalebar for a geographic map in km.
- Args:
- theComposerMap - QgsComposerMap instance used as the basis
scale calculations.
- theTopOffset - vertical offset at which the map should be drawn
- Returns:
- None
- Raises:
- Any exceptions raised by the InaSAFE library will be propagated.
-
drawTitle(theTopOffset)[source]
Add a title to the composition.
- Args:
- theTopOffset - vertical offset at which the map should be drawn
- Returns:
- float - the height of the label as rendered
- Raises:
- None
-
getMapTitle()[source]
Get the map title from the layer keywords if possible.
- Args:
- None
- Returns:
- None on error, otherwise the title
- Raises:
- Any exceptions raised by the InaSAFE library will be propagated.
-
printToPdf(theFilename)[source]
Generate the printout for our final map.
- Args:
- theFilename: str - optional path on the file system to which the
- pdf should be saved. If None, a generated file name will be
used.
- Returns:
- str: file name of the output file (equivalent to theFilename if
- provided).
- Raises:
- None
-
renderComposition()[source]
Render the map composition to an image and save that to disk.
- Args:
- None
- Returns:
- tuple:
- str: myImagePath - absolute path to png of rendered map
- QImage: myImage - in memory copy of rendered map
- QRectF: myTargetArea - dimensions of rendered map
str: Absolute file system path to the rendered image.
- Raises:
- None
-
renderTemplate(theTemplateFilePath, theOutputFilePath)[source]
Load a QgsComposer map from a template and render it
Note
THIS METHOD IS EXPERIMENTAL AND CURRENTLY NON FUNCTIONAL
- Args:
- theTemplateFilePath - path to the template that should be loaded.
theOutputFilePath - path for the output pdf
- Returns:
- None
- Raises:
- None
-
setImpactLayer(theLayer)[source]
Mutator for the impact layer that will be used for stats,
legend and reporting.
- Args:
- theLayer - a valid QgsMapLayer
- Returns:
- None
- Raises:
- Any exceptions raised by the InaSAFE library will be propagated.
-
setupComposition()[source]
Set up the composition ready for drawing elements onto it.
- Args:
- None
- Returns:
- None
- Raises:
- None
-
showComposer()[source]
Show the composition in a composer view so the user can tweak it
if they want to.
- Args:
- None
- Returns:
- None
- Raises:
- None
-
tr(theString)[source]
We implement this since we do not inherit QObject.
- Args:
- theString - string for translation.
- Returns:
- Translated version of theString.
- Raises:
- no exceptions explicitly raised.
-
writeTemplate(theTemplateFilePath)[source]
Write the current composition as a template that can be
re-used in QGIS.
This module forms part of the InaSAFE tool.