本文整理汇总了Python中qgis.gui.QgsRubberBand.setColor方法的典型用法代码示例。如果您正苦于以下问题:Python QgsRubberBand.setColor方法的具体用法?Python QgsRubberBand.setColor怎么用?Python QgsRubberBand.setColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.gui.QgsRubberBand
的用法示例。
在下文中一共展示了QgsRubberBand.setColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _draw_rubberband
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setColor [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
示例2: zoomAndShowWKT
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setColor [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()
示例3: _draw_rubberband
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setColor [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: LineDrawer
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setColor [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()
示例5: QgepMapTool
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setColor [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
示例6: PlaceMarkerMapTool
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setColor [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()
示例7: loadLines
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setColor [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)
示例8: GetPointMapTool
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setColor [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)
示例9: addGraphic
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setColor [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)
示例10: QgepMapToolAddFeature
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setColor [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 )
示例11: _setRubberBandMarker
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setColor [as 别名]
def _setRubberBandMarker(self, geom):
m = QgsRubberBand(self.qgisIface.mapCanvas(), False) # not polygon
if QgsWkbTypes.geometryType(geom.wkbType()) == QgsWkbTypes.LineGeometry:
linegeom = geom
elif QgsWkbTypes.geometryType(geom.wkbType()) == QgsWkbTypes.PolygonGeometry:
linegeom = QgsGeometry.fromPolylineXY(geom.asPolygon()[0])
m.setToGeometry(linegeom, None)
m.setColor(QColor(self.config['rubber_color']))
m.setWidth(self.config['rubber_width'])
return m
示例12: initRubberLayer
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setColor [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
示例13: CurrentSelection
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setColor [as 别名]
class CurrentSelection(QgsRubberBand):
"""
Position marker for the current location in the viewer.
"""
class AniObject(QObject):
def __init__(self, band):
super(CurrentSelection.AniObject, self).__init__()
self.color = QColor()
@pyqtProperty(int)
def alpha(self):
return self.color.alpha()
@alpha.setter
def alpha(self, value):
self.color.setAlpha(value)
def __init__(self, canvas):
super(CurrentSelection, self).__init__(canvas)
self.outline = QgsRubberBand(canvas)
self.outline.setBrushStyle(Qt.NoBrush)
self.outline.setWidth(5)
self.outline.setIconSize(30)
self.aniobject = CurrentSelection.AniObject(self)
self.anim = QPropertyAnimation(self.aniobject, "alpha")
self.anim.setDuration(500)
self.anim.setStartValue(50)
self.anim.setEndValue(100)
self.anim.valueChanged.connect(self.value_changed)
def setOutlineColour(self, color):
self.outline.setColor(color)
def setToGeometry(self, geom, layer):
super(CurrentSelection, self).setToGeometry(geom, layer)
self.outline.setToGeometry(geom, layer)
self.anim.stop()
self.anim.start()
def reset(self, geomtype=QGis.Line):
super(CurrentSelection, self).reset(geomtype)
self.outline.reset(geomtype)
self.anim.stop()
def value_changed(self, value):
self.setColor(self.aniobject.color)
self.update()
def setColor(self, color):
self.aniobject.color = color
super(CurrentSelection, self).setColor(color)
示例14: drawManyPaths
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setColor [as 别名]
def drawManyPaths(self, rows, columns, con, args, geomType, canvasItemList, mapCanvas):
'''
draws multi line string on the mapCanvas.
'''
resultPathsRubberBands = canvasItemList['paths']
rubberBand = None
cur_path_id = None
for row in rows:
cur2 = con.cursor()
result_path_id = str(row[columns[0]])
args['result_node_id'] = sql.Literal(row[columns[1]])
args['result_edge_id'] = sql.Literal(row[columns[2]])
if result_path_id != cur_path_id:
cur_path_id = result_path_id
if rubberBand:
resultPathsRubberBands.append(rubberBand)
rubberBand = None
rubberBand = QgsRubberBand(mapCanvas, Utils.getRubberBandType(False))
rubberBand.setColor(QColor(255, 0, 0, 128))
rubberBand.setWidth(4)
if row[columns[2]] != -1:
query2 = sql.SQL("""
SELECT ST_AsText({transform_s}{geometry}{transform_e})
FROM {edge_schema}.{edge_table}
WHERE {source} = {result_node_id} AND {id} = {result_edge_id}
UNION
SELECT ST_AsText({transform_s}ST_Reverse({geometry}){transform_e})
FROM {edge_schema}.{edge_table}
WHERE {target} = {result_node_id} AND {id} = {result_edge_id}
""").format(**args).as_string(con)
cur2.execute(query2)
row2 = cur2.fetchone()
geom = QgsGeometry().fromWkt(str(row2[0]))
if geom.wkbType() == QgsWkbTypes.MultiLineString:
for line in geom.asMultiPolyline():
for pt in line:
rubberBand.addPoint(pt)
elif geom.wkbType() == QgsWkbTypes.LineString:
for pt in geom.asPolyline():
rubberBand.addPoint(pt)
if rubberBand:
resultPathsRubberBands.append(rubberBand)
rubberBand = None
示例15: DrawPolygon
# 需要导入模块: from qgis.gui import QgsRubberBand [as 别名]
# 或者: from qgis.gui.QgsRubberBand import setColor [as 别名]
class DrawPolygon(QgsMapTool):
'''Outil de sélection par polygone, tiré de selectPlusFr'''
selectionDone = pyqtSignal()
move = pyqtSignal()
def __init__(self, iface, couleur):
canvas = iface.mapCanvas()
QgsMapTool.__init__(self, canvas)
self.canvas = canvas
self.iface = iface
self.status = 0
self.rb = QgsRubberBand(self.canvas, QgsWkbTypes.PolygonGeometry)
self.rb.setColor(couleur)
return None
def keyPressEvent(self, e):
if e.matches(QKeySequence.Undo):
if self.rb.numberOfVertices() > 1:
self.rb.removeLastPoint()
def canvasPressEvent(self, e):
if e.button() == Qt.LeftButton:
if self.status == 0:
self.rb.reset(QgsWkbTypes.PolygonGeometry)
self.status = 1
self.rb.addPoint(self.toMapCoordinates(e.pos()))
else:
if self.rb.numberOfVertices() > 2:
self.status = 0
self.selectionDone.emit()
else:
self.reset()
return None
def canvasMoveEvent(self, e):
if self.rb.numberOfVertices() > 0 and self.status == 1:
self.rb.removeLastPoint(0)
self.rb.addPoint(self.toMapCoordinates(e.pos()))
self.move.emit()
return None
def reset(self):
self.status = 0
self.rb.reset(True)
def deactivate(self):
self.rb.reset(True)
QgsMapTool.deactivate(self)