[QGIS-Developer] Remove all rubberbands from the canvas

Paul Wittle paul.wittle at dorsetcouncil.gov.uk
Tue Sep 22 09:07:16 PDT 2020


I have eventually worked out the issue.

As I thought the use of .addGeometry() meant I was adding new polygons and the previous ones were not being deleted. This was because the object self.rubberband in my script was not persisting through my code and so I replaced it with an variable defined at a higher level (i.e. rubberbandList = {}) and that allowed me to use the scene().removeItem() successfully.

Hope that is helpful to others.
Paul


From: Paul Wittle
Sent: 22 September 2020 14:52
To: Florian Heyder <Florian.J.Heyder at gmail.com>
Subject: RE: [QGIS-Developer] Remove all rubberbands from the canvas

Hi,

Thanks for the tip; I have indeed tried that and whilst it doesn’t error the rubber band is not removed either.

The scene() object is really odd as well as it is barely in any documentation, I certainly can’t find it in the API reference.

A bit of a mystery really but I suspect I’m accidentally adding the rubber band multiple times and then only removing one of them…but I can’t see why at the moment.

Cheers,
Paul


From: Florian Heyder <Florian.J.Heyder at gmail.com<mailto:Florian.J.Heyder at gmail.com>>
Sent: 22 September 2020 10:59
To: Paul Wittle <P.Wittle at dorsetcc.gov.uk<mailto:P.Wittle at dorsetcc.gov.uk>>
Subject: Re: [QGIS-Developer] Remove all rubberbands from the canvas

Try this, you have to remove from scene:
https://webgeodatavore.github.io/pyqgis-samples/gui-group/QgsRubberBand.html

On Tue, Sep 22, 2020 at 4:01 AM Paul Wittle <paul.wittle at dorsetcouncil.gov.uk<mailto:paul.wittle at dorsetcouncil.gov.uk>> wrote:
Hi,

I’m having an issue with the documentation this morning. I’m writing a small python plugin and adding rubberbands to the canvas which is fine but for some reason I can’t seem to remove them from the canvas at the end.

To start with, this is because I’d not put anything in to remove them but now I’m using the iface.mapCanvas.scene().removeItem() function and they still are present.

I have two questions really:

1.      I can’t see scene defined in the documentation for QgsMapCanvas; is this something that should be there?

2.      Is there a way to simply remove all scenes from the canvas?

Any help would be great 😊
Thanks,

Paul Wittle
[cid:image005.jpg at 01D69102.D1AB60C0]<https://www.dorsetcouncil.gov.uk/>
Business Solutions Analyst (GIS)
ICT Operations
Dorset Council
01305 228473 <tel:01305%20228473%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20>
dorsetcouncil.gov.uk<https://www.dorsetcouncil.gov.uk>

[cid:image006.png at 01D69102.D1AB60C0]<https://www.facebook.com/DorsetCouncilUK>
[cid:image007.png at 01D69102.D1AB60C0]<https://instagram.com/DorsetCouncilUK>
[cid:image008.png at 01D69102.D1AB60C0]<https://twitter.com/DorsetCouncilUK>

This e-mail and any files transmitted with it are intended solely for the use of the individual or entity to whom they are addressed. It may contain unclassified but sensitive or protectively marked material and should be handled accordingly. Unless you are the named addressee (or authorised to receive it for the addressee) you may not copy or use it, or disclose it to anyone else. If you have received this transmission in error please notify the sender immediately. All traffic may be subject to recording and/or monitoring in accordance with relevant legislation. Any views expressed in this message are those of the individual sender, except where the sender specifies and with authority, states them to be the views of Dorset Council. Dorset Council does not accept service of documents by fax or other electronic means. Virus checking: Whilst all reasonable steps have been taken to ensure that this electronic communication and its attachments whether encoded, encrypted or otherwise supplied are free from computer viruses, Dorset Council accepts no liability in respect of any loss, cost, damage or expense suffered as a result of accessing this message or any of its attachments. For information on how Dorset Council processes your information, please see www.dorsetcouncil.gov.uk/416433<http://www.dorsetcouncil.gov.uk/416433>
_______________________________________________
QGIS-Developer mailing list
QGIS-Developer at lists.osgeo.org<mailto:QGIS-Developer at lists.osgeo.org>
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
This e-mail and any files transmitted with it are intended solely for the use of the individual or entity to whom they are addressed. It may contain unclassified but sensitive or protectively marked material and should be handled accordingly. Unless you are the named addressee (or authorised to receive it for the addressee) you may not copy or use it, or disclose it to anyone else. If you have received this transmission in error please notify the sender immediately. All traffic may be subject to recording and/or monitoring in accordance with relevant legislation. Any views expressed in this message are those of the individual sender, except where the sender specifies and with authority, states them to be the views of Dorset Council. Dorset Council does not accept service of documents by fax or other electronic means. Virus checking: Whilst all reasonable steps have been taken to ensure that this electronic communication and its attachments whether encoded, encrypted or otherwise supplied are free from computer viruses, Dorset Council accepts no liability in respect of any loss, cost, damage or expense suffered as a result of accessing this message or any of its attachments. For information on how Dorset Council processes your information, please see www.dorsetcouncil.gov.uk/416433
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20200922/aeee8eda/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image005.jpg
Type: image/jpeg
Size: 5729 bytes
Desc: image005.jpg
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20200922/aeee8eda/attachment-0001.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image006.png
Type: image/png
Size: 4194 bytes
Desc: image006.png
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20200922/aeee8eda/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image007.png
Type: image/png
Size: 6142 bytes
Desc: image007.png
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20200922/aeee8eda/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image008.png
Type: image/png
Size: 2536 bytes
Desc: image008.png
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20200922/aeee8eda/attachment-0005.png>


More information about the QGIS-Developer mailing list