Extraction of line segments in front of the street
Instead of step 5, create a new geometry by expression
(go to Menu Processing / Toolbox
), using the expression boundary ($geometry)
, see:
The result:
It is annoying when it is necessary to do an extraction of line segments and layer is LinesSring type (not Polygon type). It is because it depends of the way as lines were digitized. Your approach was correct but your "Extract by location" method doesn't have a "convexHull" option. In a PyQGIS script you can do that.
First, I downloaded your image and, it was arbitrarily projected with EPSG:32612 by me. Afterward, I digitized two blocks (LineString type); as it can be watched in following image. Observe that I also used the group field (in this case named block) to form a single line for a single plot with dissolve in my Python script.
Complete developed code looks as follows:
import processing
layer = iface.activeLayer()
parameters1 = { 'FIELD' : ['block'],
'INPUT' : layer,
'OUTPUT' : 'TEMPORARY_OUTPUT' }
result1 = processing.run('qgis:dissolve',
parameters1)
parameters2 = { 'INPUT' : result1['OUTPUT'],
'OUTPUT' : 'TEMPORARY_OUTPUT' }
result2 = processing.run('qgis:fixgeometries',
parameters2)
parameters3 = { 'INPUT' : result2['OUTPUT'],
'OUTPUT' : 'TEMPORARY_OUTPUT' }
result3 = processing.run('qgis:linestopolygons',
parameters3)
geoms_hull = [ feat.geometry().convexHull().asWkt() for feat in result3['OUTPUT'].getFeatures() ]
perimeters = [ feat.geometry().length() for feat in result3['OUTPUT'].getFeatures() ]
epsg = layer.crs().postgisSrid()
uri = "Polygon?crs=epsg:" + str(epsg) + "&field=id:integer&field=length:double""&index=yes"
mem_layer = QgsVectorLayer(uri,
'Polygon',
'memory')
prov = mem_layer.dataProvider()
feats = [ QgsFeature() for i in range(len(geoms_hull)) ]
for i, feat in enumerate(feats):
feat.setAttributes([i, perimeters[i]])
feat.setGeometry(QgsGeometry.fromWkt(geoms_hull[i]))
prov.addFeatures(feats)
QgsProject.instance().addMapLayer(mem_layer)
When above code was run in Python Console of QGIS, I got result of following image. Convex Hull geometries (polygon features) perfectly match with each grouped features plot. In the attributes table it were also included your desired sums of the segments that lead to the road.