2
QgsVectorLayer *circleLayer = new QgsVectorLayer("Polygon", "Circle", "memory");

QgsFeature circleFeature = QgsFeature();

circleFeature.setGeometry(QgsGeometry::fromPoint(geometryPoint)->buffer(10000,20));

QgsVectorDataProvider *circleDataProvider = circleLayer->dataProvider();
QgsFeatureList circleFeatureList = QgsFeatureList();
circleFeatureList.append(circleFeature);

if(!circleDataProvider->addFeatures(circleFeatureList)){
    qDebug()<<"Error adding feature!";
    return;
}

circleLayer->updateExtents();

QgsSingleSymbolRendererV2 *circleLayerRenderer = new QgsSingleSymbolRendererV2(QgsSymbolV2::defaultSymbol(circleLayer->geometryType()));
circleLayer->setRendererV2(circleLayerRenderer);

QgsMapLayerRegistry::instance()->addMapLayer(circleLayer, TRUE);
mainLayerSet.push_front(circleLayer);
mpMapCanvas->setLayerSet(mainLayerSet);
mpMapCanvas->refresh();
mpMapCanvas->zoomToFullExtent();

makes Pacman (cuts off last segment of circle) instead of circle in my standalone application. Is this a way to fix this?

4
  • Have you tried to add the vector layer without set a layer renderer ? Mar 28, 2019 at 13:36
  • yes, same result. Mar 28, 2019 at 13:42
  • What are your CRS, units ? Mar 28, 2019 at 13:55
  • EPSG:3857, meters. Tested on EPSG:4326 with degrees, no difference. Mar 28, 2019 at 14:01

2 Answers 2

3

I am working on QGIS 3.6, I've translated your code in Python 3 (few changes from PyQgis 2.x, for example fromPoint, QgsPoint and QgsMapLayerRegistry.instance()) and it's working perfectly :

circleLayer = QgsVectorLayer("Polygon?crs=epsg:3857", "Circle", "memory")

circleFeature = QgsFeature()
circleFeature.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(1000, 1000)).buffer(10000, 20))

circleDataProvider = circleLayer.dataProvider()
if not circleDataProvider.addFeature(circleFeature):
    raise Exception("Error adding feature!")
else:
    QgsProject.instance().addMapLayer(circleLayer, True)

Can you try this in your QGIS installation with the few code modification ?

2
  • I've tried to do this before and it really works fine in QGIS Desktop application. Mar 28, 2019 at 14:40
  • I have few ideas left : that the first and last pair of coordinates of QgsGeometry.fromPointXY(QgsPointXY(1000, 1000)).buffer(10000, 20).asWkt() are the same, circleLayer.getFeature(1).geometry().asWkt() equals QgsGeometry.fromPointXY(QgsPointXY(1000, 1000)).buffer(10000, 20).asWkt(), and finally, is there working on an updated version of QGIS, like 2.18 if you want to stay in 2.x versions ? Mar 28, 2019 at 14:52
0

Using translateFeature() instead of moveVertex(). Works fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.