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.

asked Feb 27, 2019 at 8:47
1
  • Also tried # Select the features input_vlayer.select(i) input_vlayer = QgsProcessingFeatureSourceDefinition(input_vlayer.id(), True) # Set input params Commented Feb 27, 2019 at 11:00

1 Answer 1

3

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

answered Feb 27, 2019 at 9:33
2
  • 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) Commented Mar 7, 2019 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) Commented Mar 7, 2019 at 12:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.