Not registered yet?
Register now! It is easy and done in 1 minute and gives you access to special discounts and much more!
I have a point vector layer with angle field. How can I create line segments at these points with certain length and angle?
I did this with style options but I need this physically as lines vector layer:
I put an example of solving the same task with a pyqgis (3.2) standalone application.
Below the python code
from qgis.core import QgsPointXY, QgsApplication, QgsVectorLayer, QgsFeature, QgsGeometry
from PyQt5.QtWidgets import QApplication
qgis_prefix_path = 'C:\\OSGeo4W64\\apps\\qgis'
app = QApplication(sys.argv)
point_path = 'd:/Users/Bogomolov/Qgis/Test_prj/point.shp'
line_path = 'd:/Users/Bogomolov/Qgis/Test_prj/lines.shp'
point_layer = QgsVectorLayer(point_path, "pointlayer", "ogr")
layer = QgsVectorLayer(line_path, "linelayer", "ogr")
for feature in point_layer.getFeatures():
geom: QgsGeometry = feature.geometry()
pnt: QgsPointXY = geom.asPoint()
length = feature['distance']
bearing = feature['bearing']
id = feature['id']
pnt0 = direct_geodetic_task(pnt, length / 2, bearing + 180)
pnt1 = direct_geodetic_task(pnt, length / 2, bearing)
points = 
fields = layer.dataProvider().fields()
feature = QgsFeature()
def direct_geodetic_task(pnt, dist, bear):
if bear > 360.0:
bear = bear - 360
if bear < 0:
bear = 360 + bear
deg = bear * math.pi / 180
dx = dist * math.sin(deg)
dy = dist * math.cos(deg)
x = pnt.x() + dx
y = pnt.y() + dy
return QgsPointXY(x, y)
if __name__ == '__main__':
The result is the same
One possible tool is Geometry by expression in the Processing Toolbox > Vector geometry.
Processing Toolbox > Vector geometry
A Geometry expression to create lines (length= 100 m) is as below:
make_line(project($geometry, 50, radians("angle")), project($geometry, 50, radians("angle"+180)))
project($geometry, 50, radians("angle"))
project($geometry, 50, radians("angle"+180))
NB. Do not forget saving created Modified geometry layer as a new dataset, otherwise it will be lost when you finish QGIS session.
@KaRolthas Thanks! I am glad it worked out.