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)
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jun 1, 2019 at 6:14
2
  • 1
    Have you tried : vl = QgsVectorLayer( "LineString" ,"temp" ,"memory") ? Commented Jun 1, 2019 at 7:47
  • 1
    Don't give the solution in your question post, post it directly as answer. Commented Jun 1, 2019 at 20:04

1 Answer 1

3

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

vl = QgsVectorLayer( "LineString" ,"temp" ,"memory")
PeterJ
1193 gold badges3 silver badges8 bronze badges
answered Jun 2, 2019 at 11:04
1
  • Don't forget to accept your answer by clicking the green-faded tick on the left-hand side :) Commented Jun 13, 2019 at 10:29

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.