本文整理汇总了Python中qgis.core.QgsComposerLabel.setItemPosition方法的典型用法代码示例。如果您正苦于以下问题:Python QgsComposerLabel.setItemPosition方法的具体用法?Python QgsComposerLabel.setItemPosition怎么用?Python QgsComposerLabel.setItemPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsComposerLabel
的用法示例。
在下文中一共展示了QgsComposerLabel.setItemPosition方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_disclaimer
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setItemPosition [as 别名]
def draw_disclaimer(self):
"""Add a disclaimer to the composition."""
LOGGER.debug('InaSAFE Map drawDisclaimer called')
myFontSize = 10
myFontWeight = QtGui.QFont.Normal
myItalicsFlag = True
myFont = QtGui.QFont('verdana',
myFontSize,
myFontWeight,
myItalicsFlag)
myLabel = QgsComposerLabel(self.composition)
myLabel.setFont(myFont)
myLabel.setText(self.disclaimer)
myLabel.adjustSizeToText()
myLabelHeight = 7.0 # mm determined using qgis map composer
myLabelWidth = self.pageWidth # item - position and size...option
myLeftOffset = self.pageMargin
myTopOffset = self.pageHeight - self.pageMargin
myLabel.setItemPosition(myLeftOffset,
myTopOffset,
myLabelWidth,
myLabelHeight,
)
myLabel.setFrameEnabled(self.showFramesFlag)
self.composition.addItem(myLabel)
示例2: drawImpactTitle
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setItemPosition [as 别名]
def drawImpactTitle(self, theTopOffset):
"""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
"""
LOGGER.debug("InaSAFE Map drawImpactTitle called")
myTitle = self.getMapTitle()
if myTitle is None:
myTitle = ""
myFontSize = 20
myFontWeight = QtGui.QFont.Bold
myItalicsFlag = False
myFont = QtGui.QFont("verdana", myFontSize, myFontWeight, myItalicsFlag)
myLabel = QgsComposerLabel(self.composition)
myLabel.setFont(myFont)
myHeading = myTitle
myLabel.setText(myHeading)
myLabelWidth = self.pageWidth - (self.pageMargin * 2)
myLabelHeight = 12
myLabel.setItemPosition(self.pageMargin, theTopOffset, myLabelWidth, myLabelHeight)
myLabel.setFrame(self.showFramesFlag)
self.composition.addItem(myLabel)
return myLabelHeight
示例3: draw_impact_title
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setItemPosition [as 别名]
def draw_impact_title(self, top_offset):
"""Draw the map subtitle - obtained from the impact layer keywords.
:param top_offset: Vertical offset at which the logo should be drawn.
:type top_offset: int
:returns: The height of the label as rendered.
:rtype: float
"""
LOGGER.debug('InaSAFE Map drawImpactTitle called')
myTitle = self.map_title()
if myTitle is None:
myTitle = ''
myFontSize = 20
myFontWeight = QtGui.QFont.Bold
myItalicsFlag = False
myFont = QtGui.QFont(
'verdana', myFontSize, myFontWeight, myItalicsFlag)
myLabel = QgsComposerLabel(self.composition)
myLabel.setFont(myFont)
myHeading = myTitle
myLabel.setText(myHeading)
myLabelWidth = self.pageWidth - (self.pageMargin * 2)
myLabelHeight = 12
myLabel.setItemPosition(
self.pageMargin, top_offset, myLabelWidth, myLabelHeight)
myLabel.setFrameEnabled(self.showFramesFlag)
self.composition.addItem(myLabel)
return myLabelHeight
示例4: draw_title
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setItemPosition [as 别名]
def draw_title(self, top_offset):
"""Add a title to the composition.
:param top_offset: Vertical offset at which the logo should be drawn.
:type top_offset: int
:returns: The height of the label as rendered.
:rtype: float
"""
LOGGER.debug('InaSAFE Map drawTitle called')
myFontSize = 14
myFontWeight = QtGui.QFont.Bold
myItalicsFlag = False
myFont = QtGui.QFont('verdana',
myFontSize,
myFontWeight,
myItalicsFlag)
myLabel = QgsComposerLabel(self.composition)
myLabel.setFont(myFont)
myHeading = self.tr('InaSAFE - Indonesia Scenario Assessment'
' for Emergencies')
myLabel.setText(myHeading)
myLabel.adjustSizeToText()
myLabelHeight = 10.0 # determined using qgis map composer
myLabelWidth = 170.0 # item - position and size...option
myLeftOffset = self.pageWidth - self.pageMargin - myLabelWidth
myLabel.setItemPosition(myLeftOffset,
top_offset - 2, # -2 to push it up a little
myLabelWidth,
myLabelHeight,
)
myLabel.setFrameEnabled(self.showFramesFlag)
self.composition.addItem(myLabel)
return myLabelHeight
示例5: draw_disclaimer
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setItemPosition [as 别名]
def draw_disclaimer(self):
"""Add a disclaimer to the composition."""
LOGGER.debug('InaSAFE Map drawDisclaimer called')
font_size = 10
font_weight = QtGui.QFont.Normal
italics_flag = True
font = QtGui.QFont(
'verdana',
font_size,
font_weight,
italics_flag)
label = QgsComposerLabel(self.composition)
label.setFont(font)
label.setText(self.disclaimer)
label.adjustSizeToText()
label_height = 7.0 # mm determined using qgis map composer
label_width = self.page_width # item - position and size...option
left_offset = self.page_margin
top_offset = self.page_height - self.page_margin
label.setItemPosition(
left_offset,
top_offset,
label_width,
label_height,)
label.setFrameEnabled(self.show_frames)
self.composition.addItem(label)
示例6: drawTitle
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setItemPosition [as 别名]
def drawTitle(self, theTopOffset):
"""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
"""
LOGGER.debug("InaSAFE Map drawTitle called")
myFontSize = 14
myFontWeight = QtGui.QFont.Bold
myItalicsFlag = False
myFont = QtGui.QFont("verdana", myFontSize, myFontWeight, myItalicsFlag)
myLabel = QgsComposerLabel(self.composition)
myLabel.setFont(myFont)
myHeading = self.tr("InaSAFE - Indonesia Scenario Assessment" " for Emergencies")
myLabel.setText(myHeading)
myLabel.adjustSizeToText()
myLabelHeight = 10.0 # determined using qgis map composer
myLabelWidth = 170.0 # item - position and size...option
myLeftOffset = self.pageWidth - self.pageMargin - myLabelWidth
myLabel.setItemPosition(
myLeftOffset, theTopOffset - 2, myLabelWidth, myLabelHeight # -2 to push it up a little
)
myLabel.setFrame(self.showFramesFlag)
self.composition.addItem(myLabel)
return myLabelHeight
示例7: draw_impact_title
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setItemPosition [as 别名]
def draw_impact_title(self, top_offset):
"""Draw the map subtitle - obtained from the impact layer keywords.
:param top_offset: Vertical offset at which the logo should be drawn.
:type top_offset: int
:returns: The height of the label as rendered.
:rtype: float
"""
LOGGER.debug('InaSAFE Map drawImpactTitle called')
title = self.map_title()
if title is None:
title = ''
font_size = 20
font_weight = QtGui.QFont.Bold
italics_flag = False
font = QtGui.QFont(
'verdana', font_size, font_weight, italics_flag)
label = QgsComposerLabel(self.composition)
label.setFont(font)
heading = title
label.setText(heading)
label_width = self.page_width - (self.page_margin * 2)
label_height = 12
label.setItemPosition(
self.page_margin, top_offset, label_width, label_height)
label.setFrameEnabled(self.show_frames)
self.composition.addItem(label)
return label_height
示例8: draw_title
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setItemPosition [as 别名]
def draw_title(self, top_offset):
"""Add a title to the composition.
:param top_offset: Vertical offset at which the logo should be drawn.
:type top_offset: int
:returns: The height of the label as rendered.
:rtype: float
"""
LOGGER.debug('InaSAFE Map drawTitle called')
font_size = 14
font_weight = QtGui.QFont.Bold
italics_flag = False
font = QtGui.QFont(
'verdana',
font_size,
font_weight,
italics_flag)
label = QgsComposerLabel(self.composition)
label.setFont(font)
heading = self.tr(
'InaSAFE - Indonesia Scenario Assessment for Emergencies')
label.setText(heading)
label.adjustSizeToText()
label_height = 10.0 # determined using qgis map composer
label_width = 170.0 # item - position and size...option
left_offset = self.page_width - self.page_margin - label_width
label.setItemPosition(
left_offset,
top_offset - 2, # -2 to push it up a little
label_width,
label_height)
label.setFrameEnabled(self.show_frames)
self.composition.addItem(label)
return label_height
示例9: drawHostAndTime
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setItemPosition [as 别名]
def drawHostAndTime(self, theTopOffset):
"""Add a disclaimer to the composition.
Args:
theTopOffset - vertical offset at which to begin drawing
Returns:
None
Raises:
None
"""
LOGGER.debug('InaSAFE Map drawDisclaimer called')
#elapsed_time: 11.612545
#user: timlinux
#host_name: ultrabook
#time_stamp: 2012-10-13_23:10:31
#myUser = self.keywordIO.readKeywords(self.layer, 'user')
#myHost = self.keywordIO.readKeywords(self.layer, 'host_name')
myDateTime = self.keywordIO.readKeywords(self.layer, 'time_stamp')
myTokens = myDateTime.split('_')
myDate = myTokens[0]
myTime = myTokens[1]
#myElapsedTime = self.keywordIO.readKeywords(self.layer,
# 'elapsed_time')
#myElapsedTime = humaniseSeconds(myElapsedTime)
myLongVersion = get_version()
myTokens = myLongVersion.split('.')
myVersion = '%s.%s.%s' % (myTokens[0], myTokens[1], myTokens[2])
myLabelText = self.tr('Date and time of assessment: %1 %2\n'
'Special note: This assessment is a guide - we '
'strongly recommend that you ground truth the '
'results shown here before deploying resources '
'and / or personnel.\n'
'Assessment carried out using InaSAFE release '
'%3 (QGIS plugin version).').arg(
myDate).arg(myTime).arg(myVersion)
myFontSize = 6
myFontWeight = QtGui.QFont.Normal
myItalicsFlag = True
myFont = QtGui.QFont('verdana',
myFontSize,
myFontWeight,
myItalicsFlag)
myLabel = QgsComposerLabel(self.composition)
myLabel.setFont(myFont)
myLabel.setText(myLabelText)
myLabel.adjustSizeToText()
myLabelHeight = 50.0 # mm determined using qgis map composer
myLabelWidth = (self.pageWidth / 2) - self.pageMargin
myLeftOffset = self.pageWidth / 2 # put in right half of page
myLabel.setItemPosition(myLeftOffset,
theTopOffset,
myLabelWidth,
myLabelHeight,
)
myLabel.setFrame(self.showFramesFlag)
self.composition.addItem(myLabel)
示例10: draw_host_and_time
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setItemPosition [as 别名]
def draw_host_and_time(self, top_offset):
"""Add a note with hostname and time to the composition.
:param top_offset: Vertical offset at which the logo should be drawn.
:type top_offset: int
"""
LOGGER.debug('InaSAFE Map drawDisclaimer called')
#elapsed_time: 11.612545
#user: timlinux
#host_name: ultrabook
#time_stamp: 2012-10-13_23:10:31
#myUser = self.keyword_io.readKeywords(self.layer, 'user')
#myHost = self.keyword_io.readKeywords(self.layer, 'host_name')
date_time = self.keyword_io.read_keywords(self.layer, 'time_stamp')
tokens = date_time.split('_')
date = tokens[0]
time = tokens[1]
#myElapsedTime = self.keyword_io.readKeywords(self.layer,
# 'elapsed_time')
#myElapsedTime = humaniseSeconds(myElapsedTime)
long_version = get_version()
tokens = long_version.split('.')
version = '%s.%s.%s' % (tokens[0], tokens[1], tokens[2])
label_text = self.tr(
'Date and time of assessment: %s %s\n'
'Special note: This assessment is a guide - we strongly recommend '
'that you ground truth the results shown here before deploying '
'resources and / or personnel.\n'
'Assessment carried out using InaSAFE release %s (QGIS '
'plugin version).') % (date, time, version)
font_size = 6
font_weight = QtGui.QFont.Normal
italics_flag = True
font = QtGui.QFont(
'verdana',
font_size,
font_weight,
italics_flag)
label = QgsComposerLabel(self.composition)
label.setFont(font)
label.setText(label_text)
label.adjustSizeToText()
label_height = 50.0 # mm determined using qgis map composer
label_width = (self.page_width / 2) - self.page_margin
left_offset = self.page_width / 2 # put in right half of page
label.setItemPosition(
left_offset,
top_offset,
label_width,
label_height,)
label.setFrameEnabled(self.show_frames)
self.composition.addItem(label)
示例11: draw_scalebar
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setItemPosition [as 别名]
#.........这里部分代码省略.........
#print "SBWMM:", myScaleBarWidthMM
#print "SWMM:", myPrintSegmentWidthMM
#print "SWM:", myGroundSegmentWidthM
#print "SWKM:", myGroundSegmentWidthKM
# start drawing in line segments
myScaleBarHeight = 5 # mm
myLineWidth = 0.3 # mm
myInsetDistance = 7 # how much to inset the scalebar into the map by
myScaleBarX = self.pageMargin + myInsetDistance
myScaleBarY = (
top_offset + self.mapHeight - myInsetDistance -
myScaleBarHeight) # mm
# Draw an outer background box - shamelessly hardcoded buffer
myRect = QgsComposerShape(myScaleBarX - 4, # left edge
myScaleBarY - 3, # top edge
myScaleBarWidthMM + 13, # right edge
myScaleBarHeight + 6, # bottom edge
self.composition)
myRect.setShapeType(QgsComposerShape.Rectangle)
myPen = QtGui.QPen()
myPen.setColor(QtGui.QColor(255, 255, 255))
myPen.setWidthF(myLineWidth)
myRect.setPen(myPen)
#myRect.setLineWidth(myLineWidth)
myRect.setFrameEnabled(False)
myBrush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
# workaround for missing setTransparentFill missing from python api
myRect.setBrush(myBrush)
self.composition.addItem(myRect)
# Set up the tick label font
myFontWeight = QtGui.QFont.Normal
myFontSize = 6
myItalicsFlag = False
myFont = QtGui.QFont('verdana',
myFontSize,
myFontWeight,
myItalicsFlag)
# Draw the bottom line
myUpshift = 0.3 # shift the bottom line up for better rendering
myRect = QgsComposerShape(myScaleBarX,
myScaleBarY + myScaleBarHeight - myUpshift,
myScaleBarWidthMM,
0.1,
self.composition)
myRect.setShapeType(QgsComposerShape.Rectangle)
myPen = QtGui.QPen()
myPen.setColor(QtGui.QColor(255, 255, 255))
myPen.setWidthF(myLineWidth)
myRect.setPen(myPen)
#myRect.setLineWidth(myLineWidth)
myRect.setFrameEnabled(False)
self.composition.addItem(myRect)
# Now draw the scalebar ticks
for myTickCountIterator in range(0, myTickCount + 1):
myDistanceSuffix = ''
if myTickCountIterator == myTickCount:
myDistanceSuffix = ' ' + myUnits
myRealWorldDistance = ('%.0f%s' %
(myTickCountIterator *
myGroundSegmentWidth,
myDistanceSuffix))
#print 'RW:', myRealWorldDistance
myMMOffset = myScaleBarX + (myTickCountIterator *
myPrintSegmentWidthMM)
#print 'MM:', myMMOffset
myTickHeight = myScaleBarHeight / 2
# Lines are not exposed by the api yet so we
# bodge drawing lines using rectangles with 1px height or width
myTickWidth = 0.1 # width or rectangle to be drawn
myUpTickLine = QgsComposerShape(
myMMOffset,
myScaleBarY + myScaleBarHeight - myTickHeight,
myTickWidth,
myTickHeight,
self.composition)
myUpTickLine.setShapeType(QgsComposerShape.Rectangle)
myPen = QtGui.QPen()
myPen.setWidthF(myLineWidth)
myUpTickLine.setPen(myPen)
#myUpTickLine.setLineWidth(myLineWidth)
myUpTickLine.setFrameEnabled(False)
self.composition.addItem(myUpTickLine)
#
# Add a tick label
#
myLabel = QgsComposerLabel(self.composition)
myLabel.setFont(myFont)
myLabel.setText(myRealWorldDistance)
myLabel.adjustSizeToText()
myLabel.setItemPosition(
myMMOffset - 3,
myScaleBarY - myTickHeight)
myLabel.setFrameEnabled(self.showFramesFlag)
self.composition.addItem(myLabel)
示例12: draw_scalebar
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setItemPosition [as 别名]
#.........这里部分代码省略.........
#print "SWKM:", myGroundSegmentWidthKM
# start drawing in line segments
scalebar_height = 5 # mm
line_width = 0.3 # mm
inset_distance = 7 # how much to inset the scalebar into the map by
scalebar_x = self.page_margin + inset_distance
scalebar_y = (
top_offset + self.map_height - inset_distance -
scalebar_height) # mm
# Draw an outer background box - shamelessly hardcoded buffer
rectangle = QgsComposerShape(
scalebar_x - 4, # left edge
scalebar_y - 3, # top edge
scale_bar_width_mm + 13, # right edge
scalebar_height + 6, # bottom edge
self.composition)
rectangle.setShapeType(QgsComposerShape.Rectangle)
pen = QtGui.QPen()
pen.setColor(QtGui.QColor(255, 255, 255))
pen.setWidthF(line_width)
rectangle.setPen(pen)
#rectangle.setLineWidth(line_width)
rectangle.setFrameEnabled(False)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
# workaround for missing setTransparentFill missing from python api
rectangle.setBrush(brush)
self.composition.addItem(rectangle)
# Set up the tick label font
font_weight = QtGui.QFont.Normal
font_size = 6
italics_flag = False
font = QtGui.QFont(
'verdana',
font_size,
font_weight,
italics_flag)
# Draw the bottom line
up_shift = 0.3 # shift the bottom line up for better rendering
rectangle = QgsComposerShape(
scalebar_x,
scalebar_y + scalebar_height - up_shift,
scale_bar_width_mm,
0.1,
self.composition)
rectangle.setShapeType(QgsComposerShape.Rectangle)
pen = QtGui.QPen()
pen.setColor(QtGui.QColor(255, 255, 255))
pen.setWidthF(line_width)
rectangle.setPen(pen)
#rectangle.setLineWidth(line_width)
rectangle.setFrameEnabled(False)
self.composition.addItem(rectangle)
# Now draw the scalebar ticks
for tick_counter in range(0, tick_count + 1):
distance_suffix = ''
if tick_counter == tick_count:
distance_suffix = ' ' + units
real_world_distance = (
'%.0f%s' %
(tick_counter *
ground_segment_width,
distance_suffix))
#print 'RW:', myRealWorldDistance
mm_offset = scalebar_x + (
tick_counter * print_segment_width_mm)
#print 'MM:', mm_offset
tick_height = scalebar_height / 2
# Lines are not exposed by the api yet so we
# bodge drawing lines using rectangles with 1px height or width
tick_width = 0.1 # width or rectangle to be drawn
uptick_line = QgsComposerShape(
mm_offset,
scalebar_y + scalebar_height - tick_height,
tick_width,
tick_height,
self.composition)
uptick_line.setShapeType(QgsComposerShape.Rectangle)
pen = QtGui.QPen()
pen.setWidthF(line_width)
uptick_line.setPen(pen)
#uptick_line.setLineWidth(line_width)
uptick_line.setFrameEnabled(False)
self.composition.addItem(uptick_line)
#
# Add a tick label
#
label = QgsComposerLabel(self.composition)
label.setFont(font)
label.setText(real_world_distance)
label.adjustSizeToText()
label.setItemPosition(
mm_offset - 3,
scalebar_y - tick_height)
label.setFrameEnabled(self.show_frames)
self.composition.addItem(label)