本文整理汇总了Python中safe_qgis.safe_interface.unique_filename函数的典型用法代码示例。如果您正苦于以下问题:Python unique_filename函数的具体用法?Python unique_filename怎么用?Python unique_filename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unique_filename函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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 myControlImages is a list
# of 'known good' renders.
myControlImages = ['getClassToLegend.png',
'getClassToLegend-variantWindosVistaSP2-32.png',
'getClassToLegend-variantUB12.04-64.png',
'getClassToLegend-variantUB11.04-64.png',
'getClassToLegend-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,代码行数:35,代码来源:test_map_legend.py
示例2: 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
示例3: 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
示例4: 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
示例5: 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
示例6: 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
示例7: test_get_vector_legend
def test_get_vector_legend(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.
"""
layer, _ = load_layer('test_shakeimpact.shp')
map_legend = MapLegend(
layer,
legend_notes='Thousand separator represented by \',\'',
legend_units='(people per cell)')
image = map_legend.vector_legend()
path = unique_filename(
prefix='getVectorLegend',
suffix='.png',
dir=temp_dir('test'))
image.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(
'getVectorLegend', 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
示例8: drawLegend
def drawLegend(self, theTopOffset):
"""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
"""
LOGGER.debug('InaSAFE Map drawLegend called')
myLegend = MapLegend(self.layer, self.pageDpi)
self.legend = myLegend.getLegend()
myPicture1 = QgsComposerPicture(self.composition)
myLegendFilePath = unique_filename(prefix='legend',
suffix='.png',
dir='work')
self.legend.save(myLegendFilePath, 'PNG')
myPicture1.setPictureFile(myLegendFilePath)
myLegendHeight = pointsToMM(self.legend.height(), self.pageDpi)
myLegendWidth = pointsToMM(self.legend.width(), self.pageDpi)
myPicture1.setItemPosition(self.pageMargin,
theTopOffset,
myLegendWidth,
myLegendHeight)
myPicture1.setFrame(False)
self.composition.addItem(myPicture1)
os.remove(myLegendFilePath)
开发者ID:simod,项目名称:inasafe,代码行数:31,代码来源:map.py
示例9: 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
示例10: 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
示例11: 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
示例12: 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
示例13: 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
示例14: 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
示例15: 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
示例16: 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
示例17: 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
示例18: printToPdf
def printToPdf(self, theFilename):
"""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
"""
LOGGER.debug("InaSAFE Map printToPdf called")
if theFilename 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(theFilename)
self.composeMap()
self.printer = setupPrinter(myMapPdfPath)
_, myImage, myRectangle = self.renderComposition()
myPainter = QtGui.QPainter(self.printer)
myPainter.drawImage(myRectangle, myImage, myRectangle)
myPainter.end()
return myMapPdfPath
开发者ID:rlbartolome,项目名称:inasafe,代码行数:27,代码来源:map.py
示例19: 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
示例20: drawLegend
def drawLegend(self, theTopOffset):
"""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
"""
LOGGER.debug("InaSAFE Map drawLegend called")
mapLegendAttributes = self.getMapLegendAtributes()
legendNotes = mapLegendAttributes.get("legend_notes", None)
legendUnits = mapLegendAttributes.get("legend_units", None)
legendTitle = mapLegendAttributes.get("legend_title", None)
LOGGER.debug(mapLegendAttributes)
myLegend = MapLegend(self.layer, self.pageDpi, legendTitle, legendNotes, legendUnits)
self.legend = myLegend.getLegend()
myPicture1 = QgsComposerPicture(self.composition)
myLegendFilePath = unique_filename(prefix="legend", suffix=".png", dir="work")
self.legend.save(myLegendFilePath, "PNG")
myPicture1.setPictureFile(myLegendFilePath)
myLegendHeight = pointsToMM(self.legend.height(), self.pageDpi)
myLegendWidth = pointsToMM(self.legend.width(), self.pageDpi)
myPicture1.setItemPosition(self.pageMargin, theTopOffset, myLegendWidth, myLegendHeight)
myPicture1.setFrame(False)
self.composition.addItem(myPicture1)
os.remove(myLegendFilePath)
开发者ID:rlbartolome,项目名称:inasafe,代码行数:31,代码来源:map.py
注:本文中的safe_qgis.safe_interface.unique_filename函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论