3

I tried using the Expression Based Input in the Densify Geometries tool with the following expression:

attribute(  $currentfeature ,'VertNum')

where VertNum is a field in the attribute table that contains the number of vertices I want to add to each feature. But I just get a "NULL" response in the Output Preview, and when I click "OK" the number of vertices is still set to 1.

I've tried with different variable types (Int, Double) without success. Am I using the Expression Based Input tool for its intended purpose here?

3

It seems the algorithm only allows you to enter a single value, not a value that changes. I think this is also the case in the updated version of the tool for QGIS 3.0.


However, you could edit the source code for the algorithm slightly and have it read the values from a specific field. In my case, I am using QGIS 2.18.13 for Win7 64-bit. The file for the algorithm can be found in:

C:/Program Files/QGIS 2.18/apps/qgis/python/plugins/processing/algs/qgis/DensifyGeometries.py

In the processAlgorithm() function, we can see where the vertices are called:

Original script

We can replace

int(vertices)

with

int(attrs[4])

Edited script

where 4 is the field index containing the values (you can check yours by right-clicking your layer and going to Properties > Fields and check the number in the Id column).

Note: Depending on permissions, you may have to move the .py file outside the folder such as to the Desktop, edit and save the file, then insert it back to the same folder.

Restart QGIS then run the tool again on your layer. You can ignore the default vertice value as the script no longer uses this to densify the geometries.

  • 1
    your solution totally worked! For those on the Mac OS system, the file requires that you "show package contents" by right clicking QGIS in the applications folder, then find it here: Contents/Resources/python/plugins/processing/algs/qgis/DensifyGeometries.py – Simon Nov 11 '17 at 0:47
  • @Simon - Nice one! Glad it worked and thanks for mentioning the path for Mac OS :) – Joseph Nov 13 '17 at 9:59

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.