1

I am using geometry generator symbol layer type and some expressions that makes the result a line that is shorter then the original line.

The expression works and looks like this:

make_line(line_interpolate_point($geometry,10),line_interpolate_point($geometry,35))

However I would like to make my own function that makes it easier to do this operation. Inside the function I am trying to use the make_line expression but this results in an error in the expressions panel when using the function.

My function looks like this:

from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom')
def smallerline(geometry,value1, feature, parent):
tmpline = make_line(line_interpolate_point(geometry,value1),line_interpolate_point(geometry,value1))

return tmpline

I'm using the function in the expression tab but there's an eval error that says "Eval Error: global name 'make_line' is not defined"

1 Answer 1

2

You are mixing up expression syntax and python syntax.

The function you write is in python. Python does not understand the expression syntax.

You need to find a matching function in the pyqgis API to make the line shorter.

Looking at the sourcecode of the interpolate expression function it uses lineGeom.interpolate(distance)

make_line creates a new line (lineString = QgsLineString()) and then loops over the vertices and calls lineString.addVertex( vertex ).

Puttin the pieces together is left as an exercise for the reader.

Your Answer

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

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