本文整理汇总了Python中qgis.gui.QgsRubberBand.setWidth方法的典型用法代码示例。如果您正苦于以下问题:Python QgsRubberBand.setWidth方法的具体用法?Python QgsRubberBand.setWidth怎么用?Python QgsRubberBand.setWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.gui.QgsRubberBand
的用法示例。
在下文中一共展示了QgsRubberBand.setWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getSnapRubberBand
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setWidth [as 别名]
def getSnapRubberBand(self):
rubberBand = QgsRubberBand(self.canvas, geometryType = QGis.Point)
rubberBand.setFillColor(QColor(255, 0, 0, 40))
rubberBand.setBorderColor(QColor(255, 0, 0, 200))
rubberBand.setWidth(2)
rubberBand.setIcon(QgsRubberBand.ICON_X)
return rubberBand
示例2: LineDrawer
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setWidth [as 别名]
class LineDrawer(QgsMapToolEmitPoint):
def __init__(self, canvas):
# call the parent constructor
QgsMapToolEmitPoint.__init__(self, canvas)
# store the passed canvas
self.canvas = canvas
# flag to know whether the tool is performing a drawing operation
self.isDrawing = False
# create and setup the rubber band to display the line
self.rubberBand = QgsRubberBand( self.canvas, False ) # False = not a polygon = a line
self.rubberBand.setColor( Qt.red )
self.rubberBand.setWidth( 1 )
def clear(self):
self.rubberBand.reset( False ) # False = not a polygon = a line
def delete(self):
self.canvas.scene().removeItem( self.rubberBand )
def canvasPressEvent(self, e):
# which the mouse button?
if e.button() == Qt.LeftButton:
# left click
# if it's the first left click, clear the rubberband
if not self.isDrawing:
self.clear()
# we are drawing now
self.isDrawing = True
# convert the clicked position to map coordinates
point = self.toMapCoordinates( e.pos() )
# add a new point to the rubber band
self.rubberBand.addPoint( point, True ) # True = display updates on the canvas
# and finally show the rubber band
self.rubberBand.show()
elif e.button() == Qt.RightButton:
# right click, stop drawing
self.isDrawing = False
# emit a signal
self.emit( SIGNAL("editingFinished()") )
def canvasMoveEvent(self, e):
# check if it's already drawing
if not self.isDrawing:
return
# convert the mouse position to map coordinates
point = self.toMapCoordinates( e.pos() )
# move the last point to the new coordinates
self.rubberBand.movePoint( point )
def geometry(self):
return self.rubberBand.asGeometry()
示例3: _draw_rubberband
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setWidth [as 别名]
def _draw_rubberband(self, extent, colour, width=2):
"""
Draw a rubber band on the canvas.
.. versionadded: 2.2.0
:param extent: Extent that the rubber band should be drawn for.
:type extent: QgsRectangle
:param colour: Colour for the rubber band.
:type colour: QColor
:param width: The width for the rubber band pen stroke.
:type width: int
:returns: Rubber band that should be set to the extent.
:rtype: QgsRubberBand
"""
rubberband = QgsRubberBand(
self.iface.mapCanvas(), geometryType=QGis.Line)
rubberband.setColor(colour)
rubberband.setWidth(width)
update_display_flag = False
point = QgsPoint(extent.xMinimum(), extent.yMinimum())
rubberband.addPoint(point, update_display_flag)
point = QgsPoint(extent.xMaximum(), extent.yMinimum())
rubberband.addPoint(point, update_display_flag)
point = QgsPoint(extent.xMaximum(), extent.yMaximum())
rubberband.addPoint(point, update_display_flag)
point = QgsPoint(extent.xMinimum(), extent.yMaximum())
rubberband.addPoint(point, update_display_flag)
point = QgsPoint(extent.xMinimum(), extent.yMinimum())
update_display_flag = True
rubberband.addPoint(point, update_display_flag)
return rubberband
示例4: QgepMapTool
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setWidth [as 别名]
class QgepMapTool( QgsMapTool ):
'''
Base class for all the map tools
'''
highLightedPoints = []
logger = logging.getLogger( __name__ )
def __init__( self, iface, button ):
QgsMapTool.__init__( self, iface.mapCanvas() )
self.canvas = iface.mapCanvas()
self.cursor = QCursor( Qt.CrossCursor )
self.button = button
self.msgBar = iface.messageBar()
settings = QSettings()
currentProfileColor = settings.value( "/QGEP/CurrentProfileColor", u'#FF9500' )
self.rubberBand = QgsRubberBand( self.canvas )
self.rubberBand.setColor( QColor( currentProfileColor ) )
self.rubberBand.setWidth( 3 )
# Gets called when the tool is activated
def activate( self ):
QgsMapTool.activate( self )
self.canvas.setCursor( self.cursor )
self.button.setChecked( True )
# Gets called whenever the tool is deactivated directly or indirectly
def deactivate( self ):
QgsMapTool.deactivate( self )
self.button.setChecked( False )
def isZoomTool( self ):
return False
def setCursor( self, cursor ):
self.cursor = QCursor( cursor )
#===========================================================================
# Events
#===========================================================================
def canvasMoveEvent( self, event ):
try:
self.mouseMoved( event )
except AttributeError:
pass
def canvasReleaseEvent( self, event ):
if event.button() == Qt.RightButton:
self.rightClicked ( event )
else:
self.leftClicked( event )
def canvasDoubleClickEvent( self, event ):
try:
self.doubleClicked( event )
except AttributeError:
pass
示例5: loadLines
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setWidth [as 别名]
def loadLines(self, lines, points, markers, suffix):
no = self.project.readEntry("TUVIEW", "lines{0}no".format(suffix))[0]
if no:
no = int(no)
for i in range(no):
a = self.project.readEntry("TUVIEW", 'lines{0}x{1}'.format(suffix, i))[0]
a = a.split('~~')
b = self.project.readEntry("TUVIEW", 'lines{0}y{1}'.format(suffix, i))[0]
b = b.split('~~')
points.clear()
for j in range(len(a)):
x = float(a[j])
y = float(b[j])
point = QgsPoint(x, y)
points.append(point)
if i + 1 == no:
marker = QgsVertexMarker(self.tuView.canvas)
if suffix == 'cs':
marker.setColor(Qt.red)
marker.setIconSize(10)
marker.setIconType(QgsVertexMarker.ICON_BOX)
else: # 'q'
marker.setColor(Qt.blue)
marker.setIconSize(12)
marker.setIconType(QgsVertexMarker.ICON_DOUBLE_TRIANGLE)
marker.setCenter(QgsPointXY(point))
markers.append(marker)
line = QgsRubberBand(self.tuView.canvas, False)
line.setWidth(2)
if suffix == 'cs':
line.setColor(QColor(Qt.red))
else: # 'q'
line.setColor(QColor(Qt.blue))
line.setToGeometry(QgsGeometry.fromPolyline(points), None)
lines.append(line)
示例6: zoomAndShowWKT
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setWidth [as 别名]
def zoomAndShowWKT(self, wtk):
geom = QgsGeometry.fromWkt(wtk)
canvas = self.iface.mapCanvas()
self.clear()
r = QgsRubberBand(canvas, geom.type() == 3 )
r.setToGeometry(geom, None)
r.setColor(QColor(0, 0, 255))
r.setFillColor(QColor(0, 0, 255, 50))
r.setWidth(3)
pt = geom.pointOnSurface().asPoint()
m = QgsVertexMarker(canvas)
m.setCenter( pt )
m.setColor(QColor(0, 0, 255))
m.setIconSize(5)
m.setIconType(QgsVertexMarker.ICON_BOX)
m.setPenWidth(3)
if geom.type() == 3 or geom.type() == 2:
rec = geom.boundingBox()
canvas.setExtent(rec)
else:
self.moveMapTo( pt[0], pt[1], 0)
self.graphics.append(r)
self.graphics.append(m)
self._refresh_layers()
示例7: _draw_rubberband
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setWidth [as 别名]
def _draw_rubberband(self, geometry, colour, width):
"""Draw a rubber band on the canvas.
.. versionadded: 2.2.0
:param geometry: Extent that the rubber band should be drawn for.
:type geometry: QgsGeometry
:param colour: Colour for the rubber band.
:type colour: QColor
:param width: The width for the rubber band pen stroke.
:type width: int
:returns: Rubber band that should be set to the extent.
:rtype: QgsRubberBand
"""
# noinspection PyArgumentList
rubber_band = QgsRubberBand(
self._map_canvas, geometryType=QGis.Polygon)
rubber_band.setBrushStyle(Qt.NoBrush)
rubber_band.setColor(colour)
rubber_band.setWidth(width)
rubber_band.setToGeometry(geometry, None)
return rubber_band
示例8: highlight
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setWidth [as 别名]
def highlight():
rb = QgsRubberBand( self.canvas, QGis.Polygon)
rb.setBorderColor( QColor( 255, 0, 0 ) )
rb.setWidth( 2 )
rb.setToGeometry( geomRB, None )
return rb
示例9: PlaceMarkerMapTool
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setWidth [as 别名]
class PlaceMarkerMapTool(QgsMapToolEmitPoint):
'''
classdocs
'''
def __init__(self, canvas):
'''
Constructor
'''
self.canvas = canvas
super(PlaceMarkerMapTool, self).__init__(self.canvas)
self.rubberBand = QgsRubberBand(self.canvas, QGis.Polygon)
self.rubberBand.setColor(Qt.red)
self.rubberBand.setWidth(1)
self.reset()
def reset(self):
self.rubberBand.reset(QGis.Polygon)
def canvasReleaseEvent(self, e):
p1 = self.canvas.getCoordinateTransform().toMapCoordinates(e.x() - 2, e.y() - 2)
p2 = self.canvas.getCoordinateTransform().toMapCoordinates(e.x() + 2, e.y() - 2)
p3 = self.canvas.getCoordinateTransform().toMapCoordinates(e.x() + 2, e.y() + 2)
p4 = self.canvas.getCoordinateTransform().toMapCoordinates(e.x() - 2, e.y() + 2)
self.reset()
self.rubberBand.addPoint(p1, False)
self.rubberBand.addPoint(p2, False)
self.rubberBand.addPoint(p3, False)
self.rubberBand.addPoint(p4, True)
self.rubberBand.show()
def deactivate(self):
self.reset()
super(PlaceMarkerMapTool, self).deactivate()
示例10: GetPointMapTool
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setWidth [as 别名]
class GetPointMapTool(QgsMapToolEmitPoint):
coordCaptured = ""
def __init__(self, canvas, iface, dockwidget, currentMapTool):
self.canvas = canvas
self.iface = iface
self.currentMapTool = currentMapTool
self.dockwidget = dockwidget
QgsMapToolEmitPoint.__init__(self, self.canvas)
self.rubberBand = QgsRubberBand(self.canvas, QGis.Point)
self.rubberBand.setColor(QColor(255,5,5))
self.rubberBand.setWidth(1)
self.reset()
def reset(self):
self.startPoint = self.endPoint = None
self.isEmittingPoint = False
self.rubberBand.reset(QGis.Polygon)
def canvasPressEvent(self, e):
self.point = self.toMapCoordinates(e.pos())
self.isEmittingPoint = True
self.showPoint(self.point)
def canvasReleaseEvent(self, e):
self.isEmittingPoint = False
self.coordCaptured = self.pointdef()
if self.coordCaptured is not None:
print "Point:", self.coordCaptured
self.coordCaptured = str(self.coordCaptured).strip("(")
self.coordCaptured = str(self.coordCaptured).strip(")")
self.dockwidget.munLineEdit.setText(self.coordCaptured)
self.iface.mapCanvas().setMapTool(self.currentMapTool)
def canvasMoveEvent(self, e):
if not self.isEmittingPoint:
return
self.endPoint = self.toMapCoordinates(e.pos())
# self.showRect(self.startPoint, self.endPoint)
def showPoint(self, point):
self.rubberBand.reset(QGis.Polygon)
point1 = QgsPoint(point.x(), point.y())
self.rubberBand.addPoint(point1, False)
self.rubberBand.show()
def pointdef(self):
return QgsPoint(self.point)
示例11: addGraphic
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setWidth [as 别名]
def addGraphic(self, geom ):
canvas = self.iface.mapCanvas()
rBand = QgsRubberBand(canvas, True)
self.graphics.append( rBand )
rBand.setToGeometry( geom, None )
rBand.setColor(QtGui.QColor(0,0,255, 70))
if QGis.QGIS_VERSION_INT >= 20600:
rBand.setBorderColor( QtGui.QColor(0,0,250, 220) )
rBand.setWidth(3)
示例12: QgepMapToolAddFeature
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setWidth [as 别名]
class QgepMapToolAddFeature( QgsMapTool ):
def __init__(self, iface, layer):
QgsMapTool.__init__(self, iface.mapCanvas() )
self.iface = iface
self.canvas = iface.mapCanvas()
self.layer = layer
self.rubberband = QgsRubberBand( iface.mapCanvas(), layer.geometryType() )
self.rubberband.setColor( QColor( "#ee5555" ) )
self.rubberband.setWidth( 2 )
self.tempRubberband = QgsRubberBand( iface.mapCanvas(), layer.geometryType() )
self.tempRubberband.setColor( QColor( "#ee5555" ) )
self.tempRubberband.setWidth( 2 )
self.tempRubberband.setLineStyle(Qt.DotLine)
def activate(self):
QgsMapTool.activate( self )
self.canvas.setCursor( QCursor( Qt.CrossCursor ) )
pass
def deactivate(self):
QgsMapTool.deactivate( self )
self.canvas.unsetCursor()
pass
def isZoomTool( self ):
return False
#===========================================================================
# Events
#===========================================================================
def canvasMoveEvent( self, event ):
self.mouseMoved( event )
def canvasReleaseEvent( self, event ):
if event.button() == Qt.RightButton:
self.rightClicked ( event )
else:
self.leftClicked( event )
def leftClicked(self, event):
mousePos = self.canvas.getCoordinateTransform().toMapCoordinates( event.pos().x(), event.pos().y() )
self.rubberband.addPoint( mousePos )
self.tempRubberband.reset()
def rightClicked(self, event):
f = QgsFeature( self.layer.pendingFields() )
f.setGeometry( self.rubberband.asGeometry() )
dlg = self.iface.getFeatureForm( self.layer, f )
dlg.setIsAddDialog(True)
dlg.exec_()
self.rubberband.reset()
self.tempRubberband.reset()
def mouseMoved(self, event):
mousePos = self.canvas.getCoordinateTransform().toMapCoordinates( event.pos().x(), event.pos().y() )
self.tempRubberband.movePoint( mousePos )
示例13: initRubberLayer
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setWidth [as 别名]
def initRubberLayer(self):
if self.rubberLayer:
rb = self.rubberLayer
rb.reset(True)
else:
rb = QgsRubberBand(self.iface.mapCanvas(), True)
rb.setColor(QColor(255, 0, 255, 255))
rb.setWidth(3)
rb.setFillColor(QColor(255, 0, 255, 50))
self.rubberLayer = rb
示例14: getRubberBand
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setWidth [as 别名]
def getRubberBand(self):
geomType = self.iface.activeLayer().geometryType()
if geomType == QGis.Polygon:
rubberBand = QgsRubberBand(self.canvas, True)
rubberBand.setFillColor(QColor(255, 0, 0, 40))
elif geomType == QGis.Line:
rubberBand = QgsRubberBand(self.canvas, False)
rubberBand.setBorderColor(QColor(255, 0, 0, 200))
rubberBand.setWidth(2)
return rubberBand
示例15: onClickedHighlight
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setWidth [as 别名]
def onClickedHighlight(self):
def removeRB():
rb.reset( True )
self.qgisCanvas.scene().removeItem( rb )
rb = QgsRubberBand( self.qgisCanvas, QGis.Polygon)
rb.setBorderColor( QColor( 255, 0, 0 ) )
rb.setWidth( 2 )
rb.setToGeometry( QgsGeometry.fromRect( self.canvas.extent() ), None )
QTimer.singleShot( 2000, removeRB )