2

I am attempting to add a circular string feature (in this case an arc of a circle). The following code runs without error but doesn't create a feature.

I am using version 3.4.2.

vl = QgsVectorLayer("Polygon", "temp", "memory")
from qgis.PyQt.QtCore import QVariant
pr = vl.dataProvider()
pr.addAttributes([QgsField("name", QVariant.String)])
vl.updateFields() 
cString=QgsCircularString()
cString.setPoints([QgsPoint(306580,167317),QgsPoint(306680,167317),QgsPoint(306680,167817)])
print (cString.hasCurvedSegments())
geom_cString=QgsGeometry(cString)
f = QgsFeature()
f.setGeometry(geom_cString)
f.setAttributes(["One"])
pr.addFeature(f)
vl.updateExtents() 
QgsProject.instance().addMapLayer(vl)
  • 1
    Have you tried : vl = QgsVectorLayer( "LineString" ,"temp" ,"memory") ? – J. Monticolo Jun 1 at 7:47
  • 1
    Don't give the solution in your question post, post it directly as answer. – J. Monticolo Jun 1 at 20:04
3

The solution suggested by J. Monticolo in a comment works well:

vl = QgsVectorLayer( "LineString" ,"temp" ,"memory")
  • Don't forget to accept your answer by clicking the green-faded tick on the left-hand side :) – Joseph Jun 13 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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