[Qgis-developer] QgsRubberBand and check for identical points in addPoint(...)

Casper Børgesen (CABO) CABO at NIRAS.DK
Tue Oct 4 06:28:05 PDT 2016


Hi,

I was trying to use python to add 3 identical points to a QgsRubberBand using .addPoint(point) and was wondering why I got a core dump when I was trying to move the third point to a new position. Looking into the code I found the following (line 172 in qgsrubberband.cpp):

  if ( mPoints.at<http://doc.qt.io/qt-4.8/qlist.html#at>( geometryIndex ).size() == 2 &&
       mPoints.at<http://doc.qt.io/qt-4.8/qlist.html#at>( geometryIndex ).at( 0 ) == mPoints.at<http://doc.qt.io/qt-4.8/qlist.html#at>( geometryIndex ).at( 1 ) )
  {
       mPoints[geometryIndex].last<http://doc.qt.io/qt-4.8/qlist.html#last>() = p;
  }
  else
  {
      mPoints[geometryIndex] << p;
  }

I was wondering why this special check is made?

I wanted to just add 3 points to the rubber band to initialize it with the points that I needed. It was easy to just copy the same "addPoint" line 2 times, but a workaround is simply adding 3 different dummy points and then later move them to where I want them. The .movePoint don't check for the above and doesn't care if the three points are identical.

My reason for asking is that this is not stated in the API [1] and a core dump is pretty difficult to debug if you're writing python plugins.


Regards, Casper


1.       https://qgis.org/api/classQgsRubberBand.html#a146d5efca562e8c12a02be5662c111d7
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20161004/f4751250/attachment-0001.html>


More information about the Qgis-developer mailing list