本文整理汇总了Python中qgis.core.QgsComposerLabel.setFrame方法的典型用法代码示例。如果您正苦于以下问题:Python QgsComposerLabel.setFrame方法的具体用法?Python QgsComposerLabel.setFrame怎么用?Python QgsComposerLabel.setFrame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsComposerLabel
的用法示例。
在下文中一共展示了QgsComposerLabel.setFrame方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_impact_title
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setFrame [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.setFrame(self.showFramesFlag)
self.composition.addItem(myLabel)
return myLabelHeight
示例2: draw_disclaimer
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setFrame [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.setFrame(self.showFramesFlag)
self.composition.addItem(myLabel)
示例3: draw_title
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setFrame [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.setFrame(self.showFramesFlag)
self.composition.addItem(myLabel)
return myLabelHeight
示例4: drawImpactTitle
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setFrame [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
示例5: drawTitle
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setFrame [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
示例6: drawHostAndTime
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setFrame [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)
示例7: draw_scalebar
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setFrame [as 别名]
def draw_scalebar(self, composer_map, top_offset):
"""Add a numeric scale to the bottom left of the map.
We draw the scale bar manually because QGIS does not yet support
rendering a scale bar for a geographic map in km.
.. seealso:: :meth:`drawNativeScaleBar`
:param composer_map: Composer map on which to draw the scalebar.
:type composer_map: QgsComposerMap
:param top_offset: Vertical offset at which the logo should be drawn.
:type top_offset: int
"""
LOGGER.debug('InaSAFE Map drawScaleBar called')
myCanvas = self.iface.mapCanvas()
myRenderer = myCanvas.mapRenderer()
#
# Add a linear map scale
#
myDistanceArea = QgsDistanceArea()
myDistanceArea.setSourceCrs(myRenderer.destinationCrs().srsid())
myDistanceArea.setProjectionsEnabled(True)
# Determine how wide our map is in km/m
# Starting point at BL corner
myComposerExtent = composer_map.extent()
myStartPoint = QgsPoint(myComposerExtent.xMinimum(),
myComposerExtent.yMinimum())
# Ending point at BR corner
myEndPoint = QgsPoint(myComposerExtent.xMaximum(),
myComposerExtent.yMinimum())
myGroundDistance = myDistanceArea.measureLine(myStartPoint, myEndPoint)
# Get the equivalent map distance per page mm
myMapWidth = self.mapWidth
# How far is 1mm on map on the ground in meters?
myMMToGroundDistance = myGroundDistance / myMapWidth
#print 'MM:', myMMDistance
# How long we want the scale bar to be in relation to the map
myScaleBarToMapRatio = 0.5
# How many divisions the scale bar should have
myTickCount = 5
myScaleBarWidthMM = myMapWidth * myScaleBarToMapRatio
myPrintSegmentWidthMM = myScaleBarWidthMM / myTickCount
# Segment width in real world (m)
# We apply some logic here so that segments are displayed in meters
# if each segment is less that 1000m otherwise km. Also the segment
# lengths are rounded down to human looking numbers e.g. 1km not 1.1km
myUnits = ''
myGroundSegmentWidth = myPrintSegmentWidthMM * myMMToGroundDistance
if myGroundSegmentWidth < 1000:
myUnits = 'm'
myGroundSegmentWidth = round(myGroundSegmentWidth)
# adjust the segment width now to account for rounding
myPrintSegmentWidthMM = myGroundSegmentWidth / myMMToGroundDistance
else:
myUnits = 'km'
# Segment with in real world (km)
myGroundSegmentWidth = round(myGroundSegmentWidth / 1000)
myPrintSegmentWidthMM = ((myGroundSegmentWidth * 1000) /
myMMToGroundDistance)
# Now adjust the scalebar width to account for rounding
myScaleBarWidthMM = myTickCount * myPrintSegmentWidthMM
#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)
myRect.setLineWidth(myLineWidth)
myRect.setFrame(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
#.........这里部分代码省略.........