I want to make a buffer on the start or end point of the line and not the line itself.
Is there some thing in QGIS python plugin development that can get me the points?
You can use the following code to get the start and end points of your line layer and loads this as a memory point layer:
line_layer = qgis.utils.iface.activeLayer()
feat = QgsFeature()
point_layer = QgsVectorLayer("Point?crs=epsg:4326", "point_layer", "memory")
pr = point_layer.dataProvider()
for feature in line_layer.getFeatures():
geom = feature.geometry().asPolyline()
start_point = QgsPoint(geom[0])
end_point = QgsPoint(geom[-1])
feat.setGeometry(QgsGeometry.fromPoint(start_point))
pr.addFeatures([feat])
feat.setGeometry(QgsGeometry.fromPoint(end_point))
pr.addFeatures([feat])
QgsMapLayerRegistry.instance().addMapLayer(point_layer)
Result:
You can then use this memory layer to create buffers around the points.
feat.setAttributes(feature.attributes())
? You should ask this as a new question :)
You can use v.to.points Processing Toolbox Algorithm.
At the next image, it can be observed:
After click in Run, I got "start and end points of each feature" in the shapefile line layer.
However, by using 'Write line vertices' option you can get all points:
layer # your vector layer (line type)
for feature in layer.getFeatures():
geom = feature.geometry().asPolyline()
print "Start: " + geom[0]
print "End: " + geom[-1]