本文整理汇总了Python中qgis.core.QgsComposerPicture.setItemPosition方法的典型用法代码示例。如果您正苦于以下问题:Python QgsComposerPicture.setItemPosition方法的具体用法?Python QgsComposerPicture.setItemPosition怎么用?Python QgsComposerPicture.setItemPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsComposerPicture
的用法示例。
在下文中一共展示了QgsComposerPicture.setItemPosition方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_windowsDrawingArtifacts
# 需要导入模块: from qgis.core import QgsComposerPicture [as 别名]
# 或者: from qgis.core.QgsComposerPicture import setItemPosition [as 别名]
def test_windowsDrawingArtifacts(self):
"""Test that windows rendering does not make artifacts"""
# sometimes spurious lines are drawn on the layout
myMap = ISMap(IFACE)
myMap.setupComposition()
myPdfPath = os.path.join(getTempDir(), 'outArtifactsTest.pdf')
myMap.setupPrinter(myPdfPath)
myPixmap = QtGui.QPixmap(10, 10)
myPixmap.fill(QtGui.QColor(250, 250, 250))
myFilename = os.path.join(getTempDir(), 'greyBox')
myPixmap.save(myFilename, 'PNG')
for i in range(10, 190, 10):
myPicture = QgsComposerPicture(myMap.composition)
myPicture.setPictureFile(myFilename)
myPicture.setFrame(False)
myPicture.setItemPosition(i, # x
i, # y
10, # width
10) # height
myMap.composition.addItem(myPicture)
# Same drawing drawn directly as a pixmap
myPixmapItem = myMap.composition.addPixmap(myPixmap)
myPixmapItem.setOffset(i, i + 20)
# Same drawing using our drawPixmap Helper
myWidthMM = 1
myMap.drawPixmap(myPixmap, myWidthMM, i, i + 40)
myMap.renderPrintout()
myUnwantedHash = 'd05e9223d50baf8bb147475aa96d6ba3'
myHash = hashForFile(myPdfPath)
# when this test no longer matches our broken render hash
# we know the issue is fixed
myMessage = 'Windows map render still draws with artifacts.'
assert myHash != myUnwantedHash, myMessage
示例2: drawLegend
# 需要导入模块: from qgis.core import QgsComposerPicture [as 别名]
# 或者: from qgis.core.QgsComposerPicture import setItemPosition [as 别名]
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)
示例3: draw_legend
# 需要导入模块: from qgis.core import QgsComposerPicture [as 别名]
# 或者: from qgis.core.QgsComposerPicture import setItemPosition [as 别名]
def draw_legend(self, top_offset):
"""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.
:param top_offset: Vertical offset at which the logo should be drawn.
:type top_offset: int
"""
LOGGER.debug('InaSAFE Map drawLegend called')
mapLegendAttributes = self.map_legend_attributes()
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.get_legend()
myPicture1 = QgsComposerPicture(self.composition)
myLegendFilePath = unique_filename(
prefix='legend', suffix='.png', dir='work')
self.legend.save(myLegendFilePath, 'PNG')
myPicture1.setPictureFile(myLegendFilePath)
myLegendHeight = points_to_mm(self.legend.height(), self.pageDpi)
myLegendWidth = points_to_mm(self.legend.width(), self.pageDpi)
myPicture1.setItemPosition(self.pageMargin,
top_offset,
myLegendWidth,
myLegendHeight)
myPicture1.setFrameEnabled(False)
self.composition.addItem(myPicture1)
os.remove(myLegendFilePath)
示例4: drawLegend
# 需要导入模块: from qgis.core import QgsComposerPicture [as 别名]
# 或者: from qgis.core.QgsComposerPicture import setItemPosition [as 别名]
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)
示例5: test_windowsDrawingArtifacts
# 需要导入模块: from qgis.core import QgsComposerPicture [as 别名]
# 或者: from qgis.core.QgsComposerPicture import setItemPosition [as 别名]
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
示例6: draw_logo
# 需要导入模块: from qgis.core import QgsComposerPicture [as 别名]
# 或者: from qgis.core.QgsComposerPicture import setItemPosition [as 别名]
def draw_logo(self, top_offset):
"""Add a picture containing the logo to the map top left corner
:param top_offset: Vertical offset at which the logo should be drawn.
:type top_offset: int
"""
myLogo = QgsComposerPicture(self.composition)
myLogo.setPictureFile(':/plugins/inasafe/bnpb_logo.png')
myLogo.setItemPosition(self.pageMargin, top_offset, 10, 10)
myLogo.setFrameEnabled(self.showFramesFlag)
myLogo.setZValue(1) # To ensure it overlays graticule markers
self.composition.addItem(myLogo)
示例7: test_windowsDrawingArtifacts
# 需要导入模块: from qgis.core import QgsComposerPicture [as 别名]
# 或者: from qgis.core.QgsComposerPicture import setItemPosition [as 别名]
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)
setupPrinter(myPath)
myMap.setupComposition()
myImage = QtGui.QImage(10, 10, QtGui.QImage.Format_RGB32)
myImage.setDotsPerMeterX(dpiToMeters(300))
myImage.setDotsPerMeterY(dpiToMeters(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 qgisVersion() >= 10800: # 1.8 or newer
myPicture.setFrameEnabled(False)
else:
myPicture.setFrame(False)
myPicture.setItemPosition(i, i, 10, 10) # x # y # width # height
myMap.composition.addItem(myPicture)
# Same drawing drawn directly as a pixmap
myPixmapItem = myMap.composition.addPixmap(QtGui.QPixmap.fromImage(myImage))
myPixmapItem.setOffset(i, i + 20)
# Same drawing using our drawImage Helper
myWidthMM = 1
myMap.drawImage(myImage, myWidthMM, i, i + 40)
myImagePath, _, _ = myMap.renderComposition()
# when this test no longer matches our broken render hash
# we know the issue is fixed
myControlImages = ["windowsArtifacts.png"]
myTolerance = 0
myFlag, myMessage = checkImages(myControlImages, myImagePath, myTolerance)
myMessage += "\nWe want these images to match, if they do not " "there may be rendering artifacts in windows.\n"
assert myFlag, myMessage
示例8: drawLogo
# 需要导入模块: from qgis.core import QgsComposerPicture [as 别名]
# 或者: from qgis.core.QgsComposerPicture import setItemPosition [as 别名]
def drawLogo(self, theTopOffset):
"""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
"""
myLogo = QgsComposerPicture(self.composition)
myLogo.setPictureFile(":/plugins/inasafe/bnpb_logo.png")
myLogo.setItemPosition(self.pageMargin, theTopOffset, 10, 10)
if qgisVersion() >= 10800: # 1.8 or newer
myLogo.setFrameEnabled(self.showFramesFlag)
else:
myLogo.setFrame(self.showFramesFlag)
myLogo.setZValue(1) # To ensure it overlays graticule markers
self.composition.addItem(myLogo)