2

Rather than going through the process of creating a plugin is there a way to take algorithms from the history and put them together to create a quick tool like in ArcMap?

For example I have

processing.run("native:buffer", {'INPUT':QgsProcessingFeatureSourceDefinition('_DCDB_July2017_a5475545_fb58_4c0a_b257_588c1ea8c0d4', True),'DISTANCE':1000,'SEGMENTS':5,'END_CAP_STYLE':0,'JOIN_STYLE':0,'MITER_LIMIT':2,'DISSOLVE':False,'OUTPUT':'TEMPORARY_OUTPUT'})

and

processing.run("native:selectbylocation", {'INPUT':'D:/Cadastre/_DCDB_July2017.tab','PREDICATE':[0],'INTERSECT':'Polygon?crs=EPSG:28355&field=OBJECTID:integer&field=LOT:string(5)&field=PLAN:string(10)&field=LOTPLAN:string(15)&field=SEG_NUM:integer&field=PAR_NUM:integer&field=SEGPAR:integer&field=PAR_IND:integer&field=LOT_AREA:double&field=EXCL_AREA:double&field=LOT_VOLUME:double&field=SURV_IND:string(1)&field=TENURE:string(40)&field=PRC:integer&field=PARISH:string(20)&field=COUNTY:string(16)&field=LAC:integer&field=SHIRE_NAME:string(40)&field=FEAT_NAME:string(60)&field=ALIAS_NAME:string(254)&field=LOC:integer&field=LOCALITY:string(30)&field=PARCEL_TYP:string(24)&field=COVER_TYP:string(10)&field=ACC_CODE:string(40)&field=CA_AREA_SQM:double&field=O_SHAPE_AREA:double&field=O_SHAPE_LEN:double&field=Shape_Length:double&field=Shape_Area:double&uid={61b8a064-9170-42ea-b1bd-117e1d914dfb}','METHOD':0})

I want to be able to select a block, click on the button and enter in the buffer distance and it should add a layer with this.

In graphical modeller I can't get it to only buffer on a selection -otherwise this would have been a possible solution.

--- Update based on How to run QGIS algorithms with selected features? I tried the following

import processing
input_vlayer = 'D:\Cadastre\_DCDB_July2017.tab'
intersect_vlayer = 'Some path'

input_vlayer = iface.addVectorLayer(input_vlayer,  'input_vlayer', 'ogr')
intersect_vlayer = iface.addVectorLayer(intersect_vlayer,  
                                       'intersect_vlayer', 'ogr')


for i in range(5):

    # Select the features
    input_vlayer.select(i)
    # Set input params
    params = {'INPUT':input_vlayer,'DISTANCE':1000,'SEGMENTS':5,'END_CAP_STYLE':0,'JOIN_STYLE':0,'MITER_LIMIT':2,'DISSOLVE':False,'OUTPUT':'TEMPORARY_OUTPUT'}
    result = processing.run("native:buffer", params)

But it runs on the whole dataset.

  • Also tried # Select the features input_vlayer.select(i) input_vlayer = QgsProcessingFeatureSourceDefinition(input_vlayer.id(), True) # Set input params – GeorgeC Feb 27 at 11:00
3

Use extract by location instead of select and you should be good with the modeller.

  • The following worked -had to save to disk... Buffer_result = processing.run("native:buffer", {'INPUT':QgsProcessingFeatureSourceDefinition(layer.source(), True),'DISTANCE':buffer,'SEGMENTS':5,'END_CAP_STYLE':0,'JOIN_STYLE':0,'MITER_LIMIT':2,'DISSOLVE':False,'OUTPUT':'D:/buffer.tab'}) iLayer=QgsVectorLayer(Buffer_result['OUTPUT'],'Buffer','ogr') QgsProject.instance().addMapLayer(iLayer) – GeorgeC Mar 7 at 12:23
  • Intersect_result = processing.run("native:extractbylocation", { 'INPUT' : 'C:/resources/rivers.shp', 'INTERSECT' : 'D:/buffer.tab', 'OUTPUT' : 'D:/intersect.tab', 'PREDICATE' : [0] }) iLayer=QgsVectorLayer(Intersect_result['OUTPUT'],'Intersect Result','ogr') QgsProject.instance().addMapLayer(iLayer) – GeorgeC Mar 7 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.