Module: is_map

This page contains the documentation for the InaSAFE is_map module.

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 gui.is_map.ISMap(theIface)[source]

A class for creating a map.

addClassToLegend(theColour, theMin=None, theMax=None, theCategory=None, theLabel=None)[source]

Add a class to the current legend. If the legend is not defined, a new one will be created. A legend is just an image file with nicely rendered classes in it.

Args:

  • theColour - Required colour for the class as a QColor

  • theMin - Optional minimum value for the class

  • theMax - Optional maximum value for the class * theCategory - Optional category name (will be used in lieu of

    min/max)

  • theLabel - Optional text label for the class

Returns:
None
Raises:
Throws an exception if the class could not be added for some reason..
addSymbolToLegend(theSymbol, theMin=None, theMax=None, theCategory=None, theLabel=None)[source]

Add a class to the current legend. If the legend is not defined, a new one will be created. A legend is just an image file with nicely rendered classes in it.

Note

This method just extracts the colour from the symbol and then delegates to the addClassToLegend function.

Args:

  • theSymbol - Required symbol for the class as a QgsSymbol

  • theMin - Optional minimum value for the class

  • theMax - Optional maximum value for the class * theCategory - Optional category name (will be used in lieu of

    min/max)

  • theLabel - Optional text label for the class

Returns:
None
Raises:
Throws an exception if the class could not be added for some reason..
drawDisclaimer()[source]

Add a disclaimer to the composition.

Args:
None
Returns:
None
Raises:
None
drawGraticuleMask(theTopOffset)[source]

A helper funtion to mask out graticule labels on the right side by overpainting a white rectangle with white border on them.

Args:
theTopOffset - vertical offset at which the map should be drawn
Returns:
None
Raises:
None
drawImpactTable(theTopOffset)[source]

Render the impact table.

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

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 propogated.
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 propogated.
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
extendLegend()[source]

Grow the legend pixmap enough to accommodate one more legend entry.

Args:
None
Returns:
None
Raises:
Any exceptions raised by the InaSAFE library will be propogated.
getLegend()[source]

Examine the classes of the impact layer associated with this print job.

Args:
None
Returns:
None
Raises:
An InvalidLegendLayer will be raised if a legend cannot be created from the layer.
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 propogated.
getRasterLegend()[source]

Get the legend for a raster layer as an image.

Args:
None
Returns:
An image representing the layer’s legend. self.legend is also populated
Raises:
An InvalidLegendLayer will be raised if a legend cannot be created from the layer.
getVectorLegend()[source]

Get the legend for this layer as a graphic.

Args:
None
Returns:
A QImage object. self.legend is also populated with the image.
Raises:
An InvalidLegendLayer will be raised if a legend cannot be created from the layer.
htmlFooter()[source]

Get a standard html footer for wrapping content in.

htmlHeader()[source]

Get a standard html header for wrapping content in.

makePdf(theFilename)[source]

Method to createa nice little pdf map.

Args:
theFilename - a string containing a filename path with .pdf extension
Returns:
None
Raises:
Any exceptions raised by the InaSAFE library will be propogated.
mmToPoints(theMM)[source]

Convert measurement in points to one in mm.

Args:
theMM - distance in milimeters
Returns:
mm converted value
Raises:
Any exceptions raised by the InaSAFE library will be propogated.
pointsToMM(thePoints)[source]

Convert measurement in points to one in mm.

Args:
thePoints - distance in pixels
Returns:
mm converted value
Raises:
Any exceptions raised by the InaSAFE library will be propogated.
renderHtml(theHtml, theWidthMM)[source]

Render some HTML to a pixmap.

Args:
  • theHtml - HTML to be rendered. It is assumed that the html is a snippet only, containing no body element - a standard header and footer will be appended.
  • theWidthMM- width of the table in mm - will be converted to points based on the resolution of our page.
Returns:
A QPixmap
Raises:
Any exceptions raised by the InaSAFE library will be propogated.
renderImpactTable()[source]

Render the table in the keywords if present. The table is an html table with statistics for the impact layer.

Args:
None
Returns:
None
Raises:
Any exceptions raised by the InaSAFE library will be propogated.
renderPrintout()[source]

Generate the printout for our final map composition.

Args:
None
Returns:
None
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 propogated.
setupComposition()[source]

Set up the composition ready for drawing elements onto it.

Args:
None
Returns:
None
Raises:
None
setupPrinter(theFilename)[source]

Create a QPrinter instance set up to print to an A4 portrait pdf

Args:
theFilename - filename for pdf generated using this printer
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 ourself 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.

Previous topic

Module: is_dock

Next topic

Module: is_keywords_dialog

This Page