In QGIS GUI, a line feature is created from this icon
1.jpg
How to Create a line with a fixed distance from a vector layer in python console.
This my example:
from qgis.core import *
from qgis.PyQt.QtCore import QVariant
capa = QgsVectorLayer("Point?crs=epsg:32718", "temp", "memory")
pr = capa.dataProvider()
pr.addAttributes([
QgsField("codigo", QVariant.Int),
QgsField("nombre", QVariant.String)])
capa.updateFields()
..
In Toolbars / mDigitizeToolBar the is action mActionAddFeatures this create a line feature, i need how to call from Python Console, with parameters .
Best Answer
You can add a LineString to a vector layer with pyqgis-3 with the following code:
Be careful!
I had to correct your code where you put
Point
instead ofLineString
as the layer geometry typecapa = QgsVectorLayer("LineString?crs=epsg:32718", "temp", "memory")