コード例 #1
0
ファイル: batch_dialog.py プロジェクト: gsuhartono/inasafe
    def createPDFReport(self, theTitle, theOutputDirectory, theImpactLayer,
                        theCount=0, theIndex=''):
        """Create PDF report from impact layer.
        Create map & table report PDF based from theImpactLayer data.

        :param theTitle: the report title.
        :param theOutputDirectory: output directory
        :param theImpactLayer: impact layer instance.
        :param theCount: the number of as scenario has been run
        :param theIndex: the index for the beginning of the file name

        See also:
            Dock.printMap()
        """

        myMap = Map(self.iface)

        # FIXME: check if theImpactLayer is the real impact layer...
        myMap.setImpactLayer(theImpactLayer)

        LOGGER.debug('Create Report: %s' % theTitle)
        myMapPath, myTablePath = self.reportPath(
            theOutputDirectory, theTitle, theCount, theIndex)

        # create map pdf
        myMap.printToPdf(myMapPath)

        # create table report pdf
        myHtmlRenderer = HtmlRenderer(myMap.pageDpi)
        myKeywords = myMap.keywordIO.read_keywords(theImpactLayer)
        myHtmlRenderer.printImpactTable(myKeywords, myTablePath)
        LOGGER.debug("Report done %s %s" % (myMapPath, myTablePath))
コード例 #2
0
ファイル: test_map.py プロジェクト: gsuhartono/inasafe
 def test_printToPdf(self):
     """Test making a pdf of the map - this is the most typical use of map.
     """
     LOGGER.info('Testing printToPdf')
     myLayer, _ = load_layer('test_shakeimpact.shp')
     myCanvasLayer = QgsMapCanvasLayer(myLayer)
     CANVAS.setLayerSet([myCanvasLayer])
     myRect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
     CANVAS.setExtent(myRect)
     CANVAS.refresh()
     myMap = Map(IFACE)
     myMap.setImpactLayer(myLayer)
     myMap.composeMap()
     myPath = unique_filename(prefix='mapPdfTest',
                              suffix='.pdf',
                              dir=temp_dir('test'))
     myMap.printToPdf(myPath)
     LOGGER.debug(myPath)
     myMessage = 'Rendered output does not exist: %s' % myPath
     assert os.path.exists(myPath), myMessage
     # pdf rendering is non deterministic so we can't do a hash check
     # test_renderComposition renders just the image instead of pdf
     # so we hash check there and here we just do a basic minimum file
     # size check.
     mySize = os.stat(myPath).st_size
     myExpectedSizes = [
         441541,  # as rendered on ub 13.04 post 17 May 2013
         441428,  # as rendered on ub 13.04 5 Jul 2013
         447217,  # Nadia Linux Mint 14
         447051,  # as rendered on Jenkins post 24 April 2013
         447138,  # Windows 7 SP1 AMD64
         233989,  # OSX 10.8
     ]
     myMessage = '%s\nExpected rendered map pdf to be in %s, got %s' % (
         myPath, myExpectedSizes, mySize)
     self.assertIn(mySize, myExpectedSizes, myMessage)