2

I'm running a process that requires me to change the amount of data input depending on the situation. With my current system I need to have a separate model depending on the number of files I need to process. I would like something that's more flexible so I only need one model that can handle different amounts of files.

What I'm trying to do is find any point outside of a buffer around the input layer(s).

Here's what my model currently looks like but it will only process 8 inputs into 'images'. I need it to be able to handle any amount eg 1-8. I have them set as optional but it still errors saying I need data.

enter image description here

  • Are the parameters for each tool the same? I.e. Reproject layer1 has the same CRS settings as Reproject layer6 or Convert points to line(s) 4 has the same field settings as Convert points to line(s) 8 etc? – Joseph Apr 12 '17 at 10:10
  • Yes, the parameters are the same for all. I tried to simplify it further by using a merge function to merge all the files before running them through the other processes but ran into the same issue. All the inputs must be used. – brink Apr 12 '17 at 18:43
1

You could try to convert your model into a script and take advantage of the multiple vector parameter which allows you specify x number of input layers.

The below code hopefully tries to emulate (to some extent) what you're trying to achive. For each input layer:

  1. Runs the qgis:reprojectlayer on the input layer.
  2. Runs the saga:convertpointstoline on the output of Step 1.
  3. Runs the qgis:fixeddistancebufferon the output of Step 2.
  4. Repeat for any other input layers

When that is complete, it then:

  1. Appends the paths of the outputs of Step 3 into a list.
  2. Runs the "qgis:mergevectorlayers" on all layers in the list.
  3. Finally runs the "qgis:difference" tool using the Junction points layer and the merged layer.

Here is the code which you can modify the parameters for each tool to fit your needs such as the CRS or the field names etc. Go to:

Processing Toolbox > Scripts > Tools > Create new script

Enter the code and save it into your /.qgis2/processing/scripts/ directory:

##Example=name
##Images=multiple vector
##Junction_points=vector point
##Missed_points=output vector

layers = Images.split(';')
layers_for_merging = []

for lyr in layers:
    layer = processing.getObjectFromUri(lyr)
    outputs_0 = processing.runalg("qgis:reprojectlayer", layer, 'ESPG:27700', None)
    outputs_1 = processing.runalg("saga:convertpointstolines", outputs_0['OUTPUT'], 'field_1', 'field_2', None)
    outputs_2 = processing.runalg("qgis:fixeddistancebuffer", outputs_1['LINES'], 0.1, 99, False, None)
    layers_for_merging.append(outputs_2['OUTPUT'])

merged_layers = processing.runalg("qgis:mergevectorlayers", ';'.join(layers_for_merging), None)
result = processing.runalg("qgis:difference", Junction_points, merged_layers['OUTPUT'], True, Missed_points)

This is the interface when you run the script:

Example


Example:

Here are some basic point layers:

Example layers

This is now running the script (for the qgis:mergevectorlayers, I replaced None with a path to show how the merged layer looks for testing):

Result

The black stars are the missed points as they lie outside the merged buffer.

1

Thanks Joseph. Unfortunately I couldn't get your code to work. The merged layer output 3 giant ovals but the difference function didn't seem to work. This is with the parameters I need.

##MissedPoints=name
##Images=multiple vector
##Junction_points=vector point
##Merge=output vector
##Missed_points=output vector

layers = Images.split(';')
layers_for_merging = []

for lyr in layers:
    layer = processing.getObjectFromUri(lyr)
    outputs_0 = processing.runalg("qgis:reprojectlayer", layer, 'ESPG:102005', None)
    outputs_1 = processing.runalg("saga:convertpointstolines", outputs_0['OUTPUT'], 'gps_date', 'north', None)
    outputs_2 = processing.runalg("qgis:fixeddistancebuffer", outputs_1['LINES'], 7.0, 5.0, False, None)
    layers_for_merging.append(outputs_2['OUTPUT'])

merged_layers = processing.runalg("qgis:mergevectorlayers", ';'.join(layers_for_merging), Merge)
result = processing.runalg("qgis:difference", Junction_points, merged_layers['OUTPUT'], True, Missed_points)

Here's one I tried by outputting the model to python then editing. It works for a couple files but if I input more than 3 it kills Qgis.

##missed junction points merge 3=name
##images=multiple vector
##junctionpoints=vector
##missedpoints=output vector

outputs_QGISMERGEVECTORLAYERS_1=processing.runalg('qgis:mergevectorlayers', [images],None)
outputs_QGISREPROJECTLAYER_1=processing.runalg('qgis:reprojectlayer', outputs_QGISMERGEVECTORLAYERS_1['OUTPUT'],'EPSG:102005',None)
outputs_SAGACONVERTPOINTSTOLINES_1=processing.runalg('saga:convertpointstolines', outputs_QGISREPROJECTLAYER_1['OUTPUT'],'gps_date','north',None)
outputs_QGISFIXEDDISTANCEBUFFER_1=processing.runalg('qgis:fixeddistancebuffer', outputs_SAGACONVERTPOINTSTOLINES_1['LINES'],7.0,5.0,False,None)
outputs_QGISDIFFERENCE_1=processing.runalg('qgis:difference', junctionpoints,outputs_QGISFIXEDDISTANCEBUFFER_1['OUTPUT'],False,missedpoints)

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.