2

I want to batch process with Clip function (also problem with any other). I have several input layers. I would like to autofill the output Clipped parameter with name of the input feature and _clipped suffix, such as in this example:

enter image description here

The Expression String Builder acts oddly when I use @INPUT parameter, there is a name of the input feature along with some weird memory address or something.

enter image description here

Why does this happen with the INPUT layer name? Where do I find the name without the odd suffix?


I found out I can go around this when I tinker with the string a bit like so:

string_to_array(@INPUT,'_')[0]

Then I get:

enter image description here

However, what if the name itself contain underscores?

1
  • If you use OUTPUT instead will that work?
    – John
    Oct 6, 2021 at 13:13

1 Answer 1

6

That weird string is not a memory address, but the layer's id. You can use the following expression to construct INPUTLAYERNAME_clipped string. And no need string_to_array(@INPUT,'_')[0].

layer_property( @INPUT, 'name' ) + '_clipped'

layer_property(@INPUT, 'name') returns the layer name. If you need the layer source file name, use this:

base_file_name( layer_property( @INPUT, 'source' ) ) + '_clipped'

enter image description here

5
  • Thanks! This is a good workaround a partly offers a solution. I wrote it earlier here as a Q&A style but it was deleted by the moderator as apparently a new question... Nevertheless, how comes that you don't get to acquire base file name in the query builder?
    – janchytry
    Oct 6, 2021 at 13:33
  • @janchytry Do you need the input file name instead of layer name? Oct 6, 2021 at 13:39
  • Not exactly in this case, but often I do.
    – janchytry
    Oct 6, 2021 at 13:41
  • @janchytry I see, I've added how to get file name. Oct 6, 2021 at 13:42
  • Thanks, that's an nice combination of functions I haven't known about.
    – janchytry
    Oct 6, 2021 at 14:52

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.