[Qgis-user] Rubberband class in QGIS 1.7
ASAHI Kosuke
asahi at hcc.co.jp
Mon Jun 20 00:40:19 PDT 2011
Dear All,
I made features select plugin used rubberband class and extended
QgsMapTool class.
It work fine in QGIS 1.6, But not work in QGIS 1.7.
After rubberBand.movePoint() in canvasMoveEvent(), it was crashed.
Please give me any advice. Is this a bug in QGIS 1.7?
All sources are here.
http://d.hatena.ne.jp/waigani/files/sweepselect_test2.zip
I use rubberband class like this.
====================================
class QgsMapToolSweepSelect(QgsMapTool):
def __init__(self, canvas):
QgsMapTool.__init__(self, canvas)
self.canvas = canvas
self.rubberBand = QgsRubberBand(canvas, True)
self.pressed = False
def canvasPressEvent(self, event):
self.center = self.toMapCoordinates(QPoint(event.pos().x(),
event.pos().y()))
for cnt in range(0,359):
self.rubberBand.addPoint(self.center, False)
self.rubberBand.addPoint(self.center, True)
self.pressed = True
def canvasMoveEvent(self, event):
if self.pressed == True:
cpos = self.toMapCoordinates(QPoint(event.pos().x(),
event.pos().y()))
len = math.sqrt((self.center.x()-cpos.x())**2 +
(self.center.y()-cpos.y())**2)
for cnt in range(0,361):
x = math.cos(math.radians(cnt)) * len + self.center.x()
y = math.sin(math.radians(cnt)) * len + self.center.y()
self.rubberBand.movePoint(cnt, QgsPoint(x,y))
def canvasReleaseEvent(self, event):
layer = self.canvas.currentLayer()
if layer == None or layer.type() != QgsMapLayer.VectorLayer:
self.rubberBand.reset()
self.pressed = False
return
layer.removeSelection()
circle = self.rubberBand.asGeometry()
fid = []
provider = layer.dataProvider()
provider.select([], circle.boundingBox(), True, True)
feat = QgsFeature()
while provider.nextFeature(feat):
if circle.intersects(feat.geometry()):
fid.append(feat.id())
for id in fid:
layer.select(id)
self.rubberBand.reset(True)
self.pressed = False
--
ASAHI Kosuke
More information about the Qgis-user
mailing list