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 Answer 1
The solution suggested by J. Monticolo in a comment works well:
vl = QgsVectorLayer( "LineString" ,"temp" ,"memory")
PeterJ
1193 gold badges3 silver badges8 bronze badges
-
Don't forget to accept your answer by clicking the green-faded tick on the left-hand side :)Joseph– Joseph2019年06月13日 10:29:47 +00:00Commented Jun 13, 2019 at 10:29
lang-py
vl = QgsVectorLayer( "LineString" ,"temp" ,"memory")
?