本文整理汇总了Python中qgis.core.QgsComposerLabel.setFrameEnabled方法的典型用法代码示例。如果您正苦于以下问题:Python QgsComposerLabel.setFrameEnabled方法的具体用法?Python QgsComposerLabel.setFrameEnabled怎么用?Python QgsComposerLabel.setFrameEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsComposerLabel
的用法示例。
在下文中一共展示了QgsComposerLabel.setFrameEnabled方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_disclaimer
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setFrameEnabled [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: draw_impact_title
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setFrameEnabled [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
示例3: draw_title
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setFrameEnabled [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
示例4: draw_disclaimer
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setFrameEnabled [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)
示例5: draw_impact_title
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setFrameEnabled [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
示例6: draw_title
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setFrameEnabled [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
示例7: draw_host_and_time
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setFrameEnabled [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)
示例8: draw_host_and_time
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setFrameEnabled [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.keywordIO.readKeywords(self.layer, 'user')
#myHost = self.keywordIO.readKeywords(self.layer, 'host_name')
myDateTime = self.keywordIO.read_keywords(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: %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).') % (myDate, myTime, 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,
top_offset,
myLabelWidth,
myLabelHeight,
)
myLabel.setFrameEnabled(self.showFramesFlag)
self.composition.addItem(myLabel)
示例9: draw_scalebar
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setFrameEnabled [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.setEllipsoidalMode(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)
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,
#.........这里部分代码省略.........
示例10: draw_scalebar
# 需要导入模块: from qgis.core import QgsComposerLabel [as 别名]
# 或者: from qgis.core.QgsComposerLabel import setFrameEnabled [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')
canvas = self.iface.mapCanvas()
renderer = canvas.mapRenderer()
#
# Add a linear map scale
#
distance_area = QgsDistanceArea()
distance_area.setSourceCrs(renderer.destinationCrs().srsid())
distance_area.setEllipsoidalMode(True)
# Determine how wide our map is in km/m
# Starting point at BL corner
composer_extent = composer_map.extent()
start_point = QgsPoint(
composer_extent.xMinimum(),
composer_extent.yMinimum())
# Ending point at BR corner
end_point = QgsPoint(
composer_extent.xMaximum(),
composer_extent.yMinimum())
ground_distance = distance_area.measureLine(start_point, end_point)
# Get the equivalent map distance per page mm
map_width = self.mapWidth
# How far is 1mm on map on the ground in meters?
mm_to_ground = ground_distance / map_width
#print 'MM:', myMMDistance
# How long we want the scale bar to be in relation to the map
scalebar_to_map_ratio = 0.5
# How many divisions the scale bar should have
tick_count = 5
scale_bar_width_mm = map_width * scalebar_to_map_ratio
print_segment_width_mm = scale_bar_width_mm / tick_count
# 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
units = ''
ground_segment_width = print_segment_width_mm * mm_to_ground
if ground_segment_width < 1000:
units = 'm'
ground_segment_width = round(ground_segment_width)
# adjust the segment width now to account for rounding
print_segment_width_mm = ground_segment_width / mm_to_ground
else:
units = 'km'
# Segment with in real world (km)
ground_segment_width = round(ground_segment_width / 1000)
print_segment_width_mm = (
(ground_segment_width * 1000) / mm_to_ground)
# Now adjust the scalebar width to account for rounding
scale_bar_width_mm = tick_count * print_segment_width_mm
#print "SBWMM:", scale_bar_width_mm
#print "SWMM:", print_segment_width_mm
#print "SWM:", myGroundSegmentWidthM
#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
#.........这里部分代码省略.........