• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python safe_interface.temp_dir函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中safe_qgis.safe_interface.temp_dir函数的典型用法代码示例。如果您正苦于以下问题:Python temp_dir函数的具体用法?Python temp_dir怎么用?Python temp_dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了temp_dir函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_windowsDrawingArtifacts

    def test_windowsDrawingArtifacts(self):
        """Test that windows rendering does not make artifacts"""
        # sometimes spurious lines are drawn on the layout
        LOGGER.info('Testing windowsDrawingArtifacts')
        myPath = unique_filename(
            prefix='artifacts',
            suffix='.pdf',
            dir=temp_dir('test'))
        myMap = Map(IFACE)
        setup_printer(myPath)
        myMap.setup_composition()

        myImage = QtGui.QImage(10, 10, QtGui.QImage.Format_RGB32)
        myImage.setDotsPerMeterX(dpi_to_meters(300))
        myImage.setDotsPerMeterY(dpi_to_meters(300))
        #myImage.fill(QtGui.QColor(250, 250, 250))
        # Look at the output, you will see antialiasing issues around some
        # of the boxes drawn...
        # myImage.fill(QtGui.QColor(200, 200, 200))
        myImage.fill(200 + 200 * 256 + 200 * 256 * 256)
        myFilename = os.path.join(temp_dir(), 'greyBox')
        myImage.save(myFilename, 'PNG')
        for i in range(10, 190, 10):
            myPicture = QgsComposerPicture(myMap.composition)
            myPicture.setPictureFile(myFilename)
            if qgis_version() >= 10800:  # 1.8 or newer
                myPicture.setFrameEnabled(False)
            else:
                myPicture.setFrame(False)
            myPicture.setItemPosition(i,  # x
                                      i,  # y
                                      10,  # width
                                      10)  # height
            myMap.composition.addItem(myPicture)
            # Same drawing drawn directly as a pixmap
            # noinspection PyCallByClass,PyTypeChecker,PyArgumentList
            myPixmapItem = myMap.composition.addPixmap(
                QtGui.QPixmap.fromImage(myImage))
            myPixmapItem.setOffset(i, i + 20)
            # Same drawing using our drawImage Helper
            myWidthMM = 1
            myMap.draw_image(myImage, myWidthMM, i, i + 40)

        myImagePath, _, _ = myMap.render()
        # when this test no longer matches our broken render hash
        # we know the issue is fixed

        myTolerance = 0
        myFlag, myMessage = check_images(
            'windowsArtifacts',
            myImagePath,
            myTolerance)
        myMessage += ('\nWe want these images to match, if they do not '
                      'there may be rendering artifacts in windows.\n')
        assert myFlag, myMessage
开发者ID:vdeparday,项目名称:inasafe,代码行数:55,代码来源:test_map.py


示例2: test_addClassToLegend

 def test_addClassToLegend(self):
     """Test we can add a class to the map legend."""
     myLayer, _ = loadLayer('test_shakeimpact.shp')
     myMapLegend = MapLegend(myLayer)
     myColour = QtGui.QColor(12, 34, 126)
     myMapLegend.addClassToLegend(myColour,
                                  theMin=None,
                                  theMax=None,
                                  theCategory=None,
                                  theLabel='bar')
     myMapLegend.addClassToLegend(myColour,
                                  theMin=None,
                                  theMax=None,
                                  theCategory=None,
                                  theLabel='foo')
     myPath = unique_filename(prefix='addClassToLegend',
                              suffix='.png',
                              dir=temp_dir('test'))
     myMapLegend.getLegend().save(myPath, 'PNG')
     LOGGER.debug(myPath)
     # As we have discovered, different versions of Qt and
     # OS platforms cause different output, so place any other possible
     # variants in the safe_qgis/test_data/test_images/ dir e.g.
     # addClassToLegend-variantUbuntu13.04.png
     myTolerance = 0  # to allow for version number changes in disclaimer
     myFlag, myMessage = checkImages('addClassToLegend.png',
                                     myPath,
                                     myTolerance)
     myMessage += ('\nWe want these images to match, if they do already '
                   'copy the test image generated to create a new control '
                   'image.')
     assert myFlag, myMessage
开发者ID:maning,项目名称:inasafe,代码行数:32,代码来源:test_map_legend.py


示例3: test_addSymbolToLegend

    def test_addSymbolToLegend(self):
        """Test we can add a symbol to the legend."""
        myLayer, _ = loadLayer('test_floodimpact.tif')
        myMapLegend = MapLegend(myLayer)
        mySymbol = QgsSymbol()
        mySymbol.setColor(QtGui.QColor(12, 34, 56))
        myMapLegend.addSymbolToLegend(mySymbol,
                                      theMin=0,
                                      # expect 2.0303 in legend
                                      theMax=2.02030,
                                      theCategory=None,
                                      theLabel='Foo')
        myPath = unique_filename(prefix='addSymbolToLegend',
                                 suffix='.png',
                                 dir=temp_dir('test'))
        myMapLegend.getLegend().save(myPath, 'PNG')
        LOGGER.debug(myPath)
        # As we have discovered, different versions of Qt and
        # OS platforms cause different output, so myControlImages is a list
        # of 'known good' renders.

        myTolerance = 0  # to allow for version number changes in disclaimer
        myFlag, myMessage = checkImages('addSymbolToLegend.png',
                                        myPath,
                                        myTolerance)
        myMessage += ('\nWe want these images to match, if they do already '
                      'copy the test image generated to create a new control '
                      'image.')
        assert myFlag, myMessage
开发者ID:maning,项目名称:inasafe,代码行数:29,代码来源:test_map_legend.py


示例4: test_getVectorLegend

 def test_getVectorLegend(self):
     """Getting a legend for a vector layer works."""
     myLayer, _ = loadLayer('test_shakeimpact.shp')
     myMapLegend = MapLegend(myLayer)
     myImage = myMapLegend.getVectorLegend()
     myPath = unique_filename(prefix='getVectorLegend',
                              suffix='.png',
                              dir=temp_dir('test'))
     myImage.save(myPath, 'PNG')
     LOGGER.debug(myPath)
     # As we have discovered, different versions of Qt and
     # OS platforms cause different output, so myControlImages is a list
     # of 'known good' renders.
     myControlImages = ['getVectorLegend.png',
                        'getVectorLegend-variantWindosVistaSP2-32.png',
                        'getVectorLegend-variantUB12.04-64.png',
                        'getVectorLegend-variantUB11.04-64.png',
                        'getVectorLegend-variantJenkins.png']
     myTolerance = 0  # to allow for version number changes in disclaimer
     myFlag, myMessage = checkImages(myControlImages,
                                 myPath,
                                 myTolerance)
     myMessage += ('\nWe want these images to match, if they do already '
             'copy the test image generated to create a new control image.')
     assert myFlag, myMessage
开发者ID:simod,项目名称:inasafe,代码行数:25,代码来源:test_map_legend.py


示例5: test_printImpactTable

 def test_printImpactTable(self):
     """Test that we can render html from impact table keywords."""
     LOGGER.debug('InaSAFE HtmlRenderer testing printImpactTable')
     myFilename = 'test_floodimpact.tif'
     myLayer, _ = load_layer(myFilename)
     myMessage = 'Layer is not valid: %s' % myFilename
     assert myLayer.isValid(), myMessage
     myPageDpi = 300
     myHtmlRenderer = HtmlRenderer(myPageDpi)
     myPath = unique_filename(prefix='impactTable',
                              suffix='.pdf',
                              dir=temp_dir('test'))
     myKeywordIO = KeywordIO()
     myKeywords = myKeywordIO.read_keywords(myLayer)
     myPath = myHtmlRenderer.print_impact_table(myKeywords,
                                              filename=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 = [20936,  # as rendered on linux ub 12.04 64
                        21523,  # as rendered on linux ub 12.10 64
                        20605,  # as rendered on linux ub 13.04 64
                        21527,  # as rendered on Jenkins post 22 June 2013
                        377191,  # as rendered on OSX
                        252699L,  # as rendered on Windows 7 64 bit
                        251782L,  # as rendered on Windows 8 64 bit amd
                        21491,  # as rendered on Slackware64 14.0
                        ]
     print 'Output pdf to %s' % myPath
     self.assertIn(mySize, myExpectedSizes)
开发者ID:vdeparday,项目名称:inasafe,代码行数:34,代码来源:test_html_renderer.py


示例6: make_pdf

    def make_pdf(self, filename):
        """Generate the printout for our final map.

        :param filename: Path on the file system to which the pdf should be
            saved. If None, a generated file name will be used.
        :type filename: str

        :returns: File name of the output file (equivalent to filename if
                provided).
        :rtype: str
        """
        LOGGER.debug('InaSAFE Map printToPdf called')
        if filename is None:
            myMapPdfPath = unique_filename(
                prefix='report', suffix='.pdf', dir=temp_dir('work'))
        else:
            # We need to cast to python string in case we receive a QString
            myMapPdfPath = str(filename)

        self.compose_map()
        self.printer = setup_printer(myMapPdfPath)
        _, myImage, myRectangle = self.render()
        myPainter = QtGui.QPainter(self.printer)
        myPainter.drawImage(myRectangle, myImage, myRectangle)
        myPainter.end()
        return myMapPdfPath
开发者ID:CharlesRethman,项目名称:inasafe,代码行数:26,代码来源:map.py


示例7: test_renderHtmlToImage

    def test_renderHtmlToImage(self):
        """Test that we can render html to a pixmap."""
        LOGGER.debug('InaSAFE HtmlRenderer testing renderHtmlToImage')
        myHtml = self.sampleHtml(20)
        LOGGER.debug(myHtml)
        myPageDpi = 300
        myRenderer = HtmlRenderer(myPageDpi)
        myPath = unique_filename(prefix='testHtmlToImage',
                                 suffix='.png',
                                 dir=temp_dir('test'))
        LOGGER.debug(myPath)
        myWidth = 250
        myPixmap = myRenderer.renderHtmlToImage(myHtml, myWidth)
        assert not myPixmap.isNull()
        LOGGER.debug(myPixmap.__class__)
        myPixmap.save(myPath)
        myMessage = 'Rendered output does not exist: %s' % myPath
        assert os.path.exists(myPath), myMessage

        myControlImages = ['renderHtmlToImage.png',
                           'renderHtmlToImage-variantOSX10.8.png',
                           'renderHtmlToImage-variantWindosVistaSP2-32.png',
                           'renderHtmlToImage-variantWindowsXPSP3-32.png',
                           'renderHtmlToImage-variantUB11.04-64.png',
                           'renderHtmlToImage-variantLinuxMint-14-x86_64.png',
                           'renderHtmlToImage-variantWindows7-SP1-AMD64.png',
                           'renderHtmlToImage-variantUB11.10-64.png']
        myTolerance = 1000  # to allow for version number changes in disclaimer
        myFlag, myMessage = checkImages(myControlImages, myPath, myTolerance)
        assert myFlag, myMessage
开发者ID:jjdida25,项目名称:inasafe,代码行数:30,代码来源:test_html_renderer.py


示例8: test_defaultTemplate

    def test_defaultTemplate(self):
        """Test that loading default template works"""
        LOGGER.info('Testing defaultTemplate')
        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.set_impact_layer(myLayer)
        myPath = unique_filename(prefix='mapDefaultTemplateTest',
                                 suffix='.pdf',
                                 dir=temp_dir('test'))
        myMap.make_pdf(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

        # Note: You should replace, not append the numbers for a given
        # platform. Also note that this test will break every time the
        # version number of InaSAFE changes so we should ultimately come up
        # with a lower maintenance test strategy.

        myExpectedSizes = [
            400350,  # Slackware64 14.0
        ]
        myMessage = '%s\nExpected rendered map pdf to be in %s, got %s' % (
            myPath, myExpectedSizes, mySize)
        self.assertIn(mySize, myExpectedSizes, myMessage)
开发者ID:vdeparday,项目名称:inasafe,代码行数:35,代码来源:test_map.py


示例9: test_printImpactTable

 def test_printImpactTable(self):
     """Test that we can render html from impact table keywords."""
     LOGGER.debug('InaSAFE HtmlRenderer testing printImpactTable')
     myFilename = 'test_floodimpact.tif'
     myLayer, _ = loadLayer(myFilename)
     myMessage = 'Layer is not valid: %s' % myFilename
     assert myLayer.isValid(), myMessage
     myPageDpi = 300
     myHtmlRenderer = HtmlRenderer(myPageDpi)
     myPath = unique_filename(prefix='impactTable',
                              suffix='.pdf',
                              dir=temp_dir('test'))
     myKeywordIO = KeywordIO()
     myKeywords = myKeywordIO.readKeywords(myLayer)
     myPath = myHtmlRenderer.printImpactTable(myKeywords,
                                              theFilename=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
     myExpectedSize = 20936  # as rendered on linux ub 12.04 64
     myMessage = ('Expected rendered table pdf to be at least %s, got %s'
                  % (myExpectedSize, mySize))
     assert mySize >= myExpectedSize, myMessage
开发者ID:jjdida25,项目名称:inasafe,代码行数:27,代码来源:test_html_renderer.py


示例10: test_add_class_to_legend

 def test_add_class_to_legend(self):
     """Test we can add a class to the map legend."""
     layer, _ = load_layer('test_shakeimpact.shp')
     map_legend = MapLegend(layer)
     colour = QtGui.QColor(12, 34, 126)
     map_legend.add_class(
         colour,
         label='bar')
     map_legend.add_class(
         colour,
         label='foo')
     path = unique_filename(
         prefix='addClassToLegend',
         suffix='.png',
         dir=temp_dir('test'))
     map_legend.get_legend().save(path, 'PNG')
     LOGGER.debug(path)
     # As we have discovered, different versions of Qt and
     # OS platforms cause different output, so place any other possible
     # variants in the safe_qgis/test_data/test_images/ dir e.g.
     # addClassToLegend-variantUbuntu13.04.png
     tolerance = 0  # to allow for version number changes in disclaimer
     flag, message = check_images(
         'addClassToLegend', path, tolerance)
     message += (
         '\nWe want these images to match, if they do already copy the test'
         ' image generated to create a new control image.')
     self.assertTrue(flag, message)
开发者ID:cccs-ip,项目名称:inasafe,代码行数:28,代码来源:test_map_legend.py


示例11: test_getVectorLegend

    def test_getVectorLegend(self):
        """Getting a legend for a vector layer works.
        @note This test is not related do thousand separator since we insert
        our own legend notes and our own layer.
        """
        myLayer, _ = load_layer('test_shakeimpact.shp')
        myMapLegend = MapLegend(
            myLayer,
            theLegendNotes='Thousand separator represented by \',\'',
            theLegendUnits='(people per cell)')
        myImage = myMapLegend.getVectorLegend()
        myPath = unique_filename(
            prefix='getVectorLegend',
            suffix='.png',
            dir=temp_dir('test'))
        myImage.save(myPath, 'PNG')
        LOGGER.debug(myPath)
        # As we have discovered, different versions of Qt and
        # OS platforms cause different output, so myControlImages is a list
        # of 'known good' renders.

        myTolerance = 0  # to allow for version number changes in disclaimer
        myFlag, myMessage = check_images(
            'getVectorLegend', myPath, myTolerance)
        myMessage += ('\nWe want these images to match, if they do already '
                      'copy the test image generated to create a new control '
                      'image.')
        assert myFlag, myMessage
开发者ID:gsuhartono,项目名称:inasafe,代码行数:28,代码来源:test_map_legend.py


示例12: test_printToPdf

 def test_printToPdf(self):
     """Test making a pdf of the map - this is the most typical use of map.
     """
     LOGGER.info('Testing printToPdf')
     myLayer, _ = loadLayer('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
     myExpectedSize = 352798  # as rendered on linux ub 12.04 64
     myMessage = 'Expected rendered map pdf to be at least %s, got %s' % (
         myExpectedSize, mySize)
     assert mySize >= myExpectedSize, myMessage
开发者ID:zzpwelkin,项目名称:inasafe,代码行数:29,代码来源:test_map.py


示例13: test_getVectorLegend

 def test_getVectorLegend(self):
     """Getting a legend for a vector layer works."""
     myLayer, _ = loadLayer('test_shakeimpact.shp')
     myMapLegend = MapLegend(
         myLayer,
         theLegendNotes='Thousand separator represented by \'.\'',
         theLegendUnits='(people per cell)')
     myImage = myMapLegend.getVectorLegend()
     myPath = unique_filename(prefix='getVectorLegend',
                              suffix='.png',
                              dir=temp_dir('test'))
     myImage.save(myPath, 'PNG')
     print myMapLegend.legendUnits
     print myMapLegend.legendNotes
     print myPath
     LOGGER.debug(myPath)
     # As we have discovered, different versions of Qt and
     # OS platforms cause different output, so myControlImages is a list
     # of 'known good' renders.
     myControlImages = ['getVectorLegend.png',
                        'getVectorLegend-variantWindowsVistaSP2-32.png',
                        'getVectorLegend-variantWindowsXPSP3-32.png',
                        'getVectorLegend-variantOSXml.png',
                        'getVectorLegend-variantUB12.04-64.png',
                        'getVectorLegend-variantUB11.04-64.png',
                        'getVectorLegend-variantLinuxMint-14-x86_64.png',
                        'getVectorLegend-variantWindows7-SP1-AMD64.png',
                        'getVectorLegend-variantJenkins.png']
     myTolerance = 0  # to allow for version number changes in disclaimer
     myFlag, myMessage = checkImages(myControlImages, myPath, myTolerance)
     myMessage += ('\nWe want these images to match, if they do already '
                   'copy the test image generated to create a new control '
                   'image.')
     assert myFlag, myMessage
开发者ID:jjdida25,项目名称:inasafe,代码行数:34,代码来源:test_map_legend.py


示例14: printToPdf

    def printToPdf(self, theHtml, theFilename=None):
        """Render an html snippet into the printer, paginating as needed.

        Args:
            * theHtml: str A string containing an html snippet. It will have a
                header and footer appended to it in order to make it a valid
                html document. The header will also apply the bootstrap theme
                to the document.
            * theFilename: str String containing a pdf file path that the
                output will be written to.
        Returns:
            str: The file path of the output pdf (which is the same as the
                theFilename parameter if it was specified.

        Raises:
            None
        """
        LOGGER.info('InaSAFE Map printToPdf called')
        if theFilename is None:
            myHtmlPdfPath = unique_filename(
                prefix='table', suffix='.pdf', dir=temp_dir('work'))
        else:
            # We need to cast to python string in case we receive a QString
            myHtmlPdfPath = str(theFilename)

        self.printer = setup_printer(myHtmlPdfPath)
        self.loadAndWait(theHtmlSnippet=theHtml)
        self.webView.print_(self.printer)

        return myHtmlPdfPath
开发者ID:feyeandal,项目名称:inasafe,代码行数:30,代码来源:html_renderer.py


示例15: clone_shp_layer

def clone_shp_layer(
        name='tsunami_polygon',
        include_keywords=False,
        source_directory=TESTDATA,
        target_directory='testing'):
    """Helper function that copies a test shp layer and returns it.

    :param name: The default name for the shp layer.
    :type name: str

    :param include_keywords: Include keywords file if True.
    :type include_keywords: bool

    :param source_directory: Directory where the file is located.
    :type source_directory: str

    :param target_directory: Subdirectory in InaSAFE temp dir that we want to
        put the files into. Default to 'testing'.
    :type target_directory: str
    """
    extensions = ['.shp', '.shx', '.dbf', '.prj']
    if include_keywords:
        extensions.append('.keywords')
    temp_path = unique_filename(dir=temp_dir(target_directory))
    # copy to temp file
    for ext in extensions:
        src_path = os.path.join(source_directory, name + ext)
        if os.path.exists(src_path):
            target_path = temp_path + ext
            shutil.copy2(src_path, target_path)

    shp_path = '%s.shp' % temp_path
    layer = QgsVectorLayer(shp_path, os.path.basename(shp_path), 'ogr')
    return layer
开发者ID:cccs-ip,项目名称:inasafe,代码行数:34,代码来源:utilities_for_testing.py


示例16: to_pdf

    def to_pdf(self, html, filename=None):
        """Render an html snippet into the printer, paginating as needed.

        :param html: A string containing an html snippet. It will have a
            header and footer appended to it in order to make it a valid
            html document. The header will also apply the bootstrap theme
            to the document.
        :type html: str

        :param filename: String containing a pdf file path that the
            output will be written to. If no file name is given we will make
            up one for you - nice eh?
        :type filename: str

        :returns: The file path of the output pdf (which is the same as the
            filename parameter if it was specified).
        :rtype: str
        """
        LOGGER.info('InaSAFE Map printToPdf called')
        if filename is None:
            html_pdf_path = unique_filename(
                prefix='table', suffix='.pdf', dir=temp_dir())
        else:
            # We need to cast to python string in case we receive a QString
            html_pdf_path = str(filename)

        self.printer = setup_printer(html_pdf_path)
        self.load_and_wait(html_snippet=html)
        self.web_view.print_(self.printer)

        return html_pdf_path
开发者ID:SamudraYe,项目名称:inasafe,代码行数:31,代码来源:html_renderer.py


示例17: render

    def render(self):
        """Render the map composition to an image and save that to disk.

        :returns: A three-tuple of:
            * str: myImagePath - absolute path to png of rendered map
            * QImage: myImage - in memory copy of rendered map
            * QRectF: myTargetArea - dimensions of rendered map
        :rtype: tuple
        """
        LOGGER.debug('InaSAFE Map renderComposition called')
        # NOTE: we ignore self.composition.printAsRaster() and always rasterise
        myWidth = int(self.pageDpi * self.pageWidth / 25.4)
        myHeight = int(self.pageDpi * self.pageHeight / 25.4)
        myImage = QtGui.QImage(QtCore.QSize(myWidth, myHeight),
                               QtGui.QImage.Format_ARGB32)
        myImage.setDotsPerMeterX(dpi_to_meters(self.pageDpi))
        myImage.setDotsPerMeterY(dpi_to_meters(self.pageDpi))

        # Only works in Qt4.8
        #myImage.fill(QtGui.qRgb(255, 255, 255))
        # Works in older Qt4 versions
        myImage.fill(55 + 255 * 256 + 255 * 256 * 256)
        myImagePainter = QtGui.QPainter(myImage)
        mySourceArea = QtCore.QRectF(0, 0, self.pageWidth,
                                     self.pageHeight)
        myTargetArea = QtCore.QRectF(0, 0, myWidth, myHeight)
        self.composition.render(myImagePainter, myTargetArea, mySourceArea)
        myImagePainter.end()
        myImagePath = unique_filename(prefix='mapRender_',
                                      suffix='.png',
                                      dir=temp_dir())
        myImage.save(myImagePath)
        return myImagePath, myImage, myTargetArea
开发者ID:CharlesRethman,项目名称:inasafe,代码行数:33,代码来源:map.py


示例18: test_get_legend

    def test_get_legend(self):
        """Getting a legend for a generic layer works."""
        LOGGER.debug('test_get_legend called')
        layer, _ = load_layer('test_shakeimpact.shp')
        map_legend = MapLegend(layer)
        self.assertTrue(map_legend.layer is not None)
        legend = map_legend.get_legend()
        path = unique_filename(
            prefix='getLegend',
            suffix='.png',
            dir=temp_dir('test'))
        legend.save(path, 'PNG')
        LOGGER.debug(path)
        # As we have discovered, different versions of Qt and
        # OS platforms cause different output, so myControlImages is a list
        # of 'known good' renders.

        tolerance = 0  # to allow for version number changes in disclaimer

        flag, message = check_images('getLegend', path, tolerance)
        message += (
            '\nWe want these images to match, if they do already '
            'copy the test image generated to create a new control '
            'image.')
        self.assertTrue(flag, message)
        LOGGER.debug('test_getLegend done')
开发者ID:cccs-ip,项目名称:inasafe,代码行数:26,代码来源:test_map_legend.py


示例19: test_printToPdf

 def test_printToPdf(self):
     """Test that we can render some html to a pdf (most common use case).
     """
     LOGGER.debug('InaSAFE HtmlRenderer testing printToPdf')
     myHtml = self.sampleHtml()
     myPageDpi = 300
     myRenderer = HtmlRenderer(myPageDpi)
     myPath = unique_filename(prefix='testHtmlTable',
                              suffix='.pdf',
                              dir=temp_dir('test'))
     LOGGER.debug(myPath)
     # If it fails myNewPath will come back as None
     myNewPath = myRenderer.to_pdf(myHtml, myPath)
     myMessage = 'Rendered output does not exist: %s' % myNewPath
     assert os.path.exists(myNewPath), myMessage
     # Also it should use our desired output file name
     myMessage = 'Incorrect path - got: %s\nExpected: %s\n' % (
         myNewPath, myPath)
     assert myNewPath == 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(myNewPath).st_size
     myExpectedSize = 18449  # as rendered on linux ub 11.04-64
     myMessage = ('Expected rendered map pdf to be at least %s, got %s. '
                  'Please update myExpectedSize if the rendered output '
                  'is acceptible on your system.'
                  % (myExpectedSize, mySize))
     assert mySize >= myExpectedSize, myMessage
开发者ID:vdeparday,项目名称:inasafe,代码行数:30,代码来源:test_html_renderer.py


示例20: test_add_symbol_to_legend

    def test_add_symbol_to_legend(self):
        """Test we can add a symbol to the legend."""
        layer, _ = load_layer('test_floodimpact.tif')
        map_legend = MapLegend(layer)
        symbol = QgsFillSymbolV2()
        symbol.setColor(QtGui.QColor(12, 34, 56))
        map_legend.add_symbol(
            symbol,
            minimum=0,
            # expect 2.0303 in legend
            maximum=2.02030,
            label='Foo')
        path = unique_filename(
            prefix='addSymbolToLegend',
            suffix='.png',
            dir=temp_dir('test'))
        map_legend.get_legend().save(path, 'PNG')
        LOGGER.debug(path)
        # As we have discovered, different versions of Qt and
        # OS platforms cause different output, so myControlImages is a list
        # of 'known good' renders.

        tolerance = 0  # to allow for version number changes in disclaimer
        flag, message = check_images(
            'addSymbolToLegend', path, tolerance)
        message += (
            '\nWe want these images to match, if they do already, copy the '
            'test image generated to create a new control image.')
        self.assertTrue(flag, message)
开发者ID:cccs-ip,项目名称:inasafe,代码行数:29,代码来源:test_map_legend.py



注:本文中的safe_qgis.safe_interface.temp_dir函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python safe_interface.unique_filename函数代码示例发布时间:2022-05-27
下一篇:
Python safe_interface.safeTr函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap