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?

Kadir Şahbaz
78.6k57 gold badges260 silver badges407 bronze badges
asked Oct 6, 2021 at 10:55
1
  • If you use OUTPUT instead will that work? Commented Oct 6, 2021 at 13:13

1 Answer 1

8

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

answered Oct 6, 2021 at 13:04
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? Commented Oct 6, 2021 at 13:33
  • @janchytry Do you need the input file name instead of layer name? Commented Oct 6, 2021 at 13:39
  • Not exactly in this case, but often I do. Commented Oct 6, 2021 at 13:41
  • @janchytry I see, I've added how to get file name. Commented Oct 6, 2021 at 13:42
  • Thanks, that's an nice combination of functions I haven't known about. Commented Oct 6, 2021 at 14:52

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.