QgsRubberBand用于显示临时图形。具体函数应用请看接口,注释写的很详细
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| QgsMapCanvas mapCanvas=获取你的画布;
QgsRubberBand *mRubber = nullptr;
mRubber = new QgsRubberBand( mapCanvas,QgsWkbTypes::PointGeometry);
mRubber->setColor(QColor(255,0,0)); mRubber->setWidth(2);
QgsPolyline points;
for(xxxx) { points.append(QgsPoint(x,y,z)); }
QgsGeometry g = QgsGeometry::fromPolyline(points); mRubber->addGeometry(g);
QgsRectangle boundingBox = mRubber->asGeometry().boundingBox(); boundingBox.grow(5); mapCanvas->setExtent(boundingBox); mapCanvas->refresh();
delete mRubber; mRubber=nullprt;
|

从QgsRubberBand获取几何对象保存到shp
1 2 3 4 5
|
QgsFeature f = QgsVectorLayerUtils::createFeature(currentLayer, mRubber->asGeometry()); currentLayer->addFeature(f);
|
