1

I need to use a plugin that's designed for use within the QGIS interface in PyQGIS.

For example, https://github.com/dgoedkoop/joinmultiplelines works great but I want to run it within a script, so that I can pass each group of lines to it to create the entire network.

So something like

layer = iface.activeLayer()
selection = layer.getFeatures() #all features
#selection = layer.selectedFeatures() #only selected features
dpr = layer.dataProvider()

completed_list=[]
for f in selection:
    print (f.id())
    text=f['RoadMntnc']
    if text not in completed_list:
        completed_list.append(text)
        line_selection=f.getFeatures( QgsFeatureRequest().setFilterExpression ( u'"RoadMntnc" = text' ) )
        joined_line=MultipleLinesPlugin(line_selection)
        #merge layers based on https://gis.stackexchange.com/questions/169523/how-to-merge-layers-into-a-single-qgsvectorlayer/169543
        vl = QgsVectorLayer("LineString", "temporary_lines", "memory")
        pr = vl.dataProvider()
        feats1 = joined_line.getFeatures()
        for feature in feats1:
          pr.addFeatures([feature])
    else:
        pass
        
vl.updateExtents()
newfile=r'c:\scratch\roads_joined.shp'
QgsVectorFileWriter.writeAsVectorFormat(v1,newfile,"utf-8",v.sourceCrs(),"ESRI Shapefile")

How could I structure the joined_line=MultipleLinesPlugin(line_selection) to use the plugin?

1
  • You can provide a script tool with your plugin. A script tool can be run from inside the plugin as well. Commented Aug 10, 2019 at 18:23

0

Your Answer

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

Browse other questions tagged or ask your own question.