Re: [Qgis-user] Problem using Model Inputs variable in an Select by expression in the model Designer

2021-08-23 Thread Nicolas Cadieux
Thanks Nyall,
I figured it was that because I could place the string “Length” in a column.  I 
thought it would work in the field calculator with something like ‘“‘ || 
@thelenghtstring || ‘“‘ but obviously, it does not. 
Thank ps for the precision.

Nicolas Cadieux
https://gitlab.com/njacadieux

> Le 23 août 2021 à 19:02, Nyall Dawson  a écrit :
> 
> On Tue, 24 Aug 2021 at 03:53, Charles Dixon-Paver  
> wrote:
>> 
>> Honestly I have no idea 
>> 
>> I mean, of course what is happening is QGIS is needing to identify a field 
>> from a text string, and it's even possible that with some convoluted chain 
>> of escape characters or funky regex the process could correct itself and 
>> "just work".
>> 
>> In all likelihood you could have just stumbled onto some obscure bug in the 
>> underlying processing API where the context of that field object get's 
>> dropped or orphaned when  trying to access it.
> 
> There's no bug here -- the variable value is just a pure text string,
> and the expression engine can't automatically guess that you actually
> want the value of the field with that name, and not just the name
> string itself. Hence the need for the attribute function, which allows
> you to retrieve a feature's fields via a text string containing the
> field name.
> 
> Nyall
> 
> 
>> 
>> My assumption is that using attribute() just compensates for whatever is 
>> going on under the hood by reinstantiating the context behind the field 
>> object, or at the very least provides a robust interface for referencing it 
>> ¯\_(ツ)_/¯
>> 
>> I would definitely call it a work around though
>> 
>>> On Mon, 23 Aug 2021 at 18:52, Nicolas Cadieux  
>>> wrote:
>>> 
>>> Hi,
>>> 
>>> if(attribute(to_string( @NamelengthField )) != "LENGTH2", TRUE, FALSE )
>>> 
>>> ("LENGHT2" is an existing field and @NamelengthField was a model input 
>>> string.)
>>> 
>>> This worked  for me!   If you have the time, please explain why I needed 
>>> the attribute() function for this to work.  I looked in the documentation 
>>> and did not find it very clear.
>>> 
>>> Thanks a million you saved my butt!
>>> 
>>> Nicolas
>>> 
>>> 
 On 2021-07-20 5:53 a.m., Charles Dixon-Paver wrote:
>>> 
>>> Hi Nicholas,
>>> 
>>> I haven't had time to dig into this extensively or encountered this 
>>> particular issue, but I would suggest trying to "force" the expression to 
>>> retrieve the correct info regardless of context using something like this:
>>> 
>>> with_variable('Length2',  to_string(@NamelengthField) || '2', 
>>> if(attribute(to_string(@NamelengthField)) != attribute(@Length2), TRUE, 
>>> FALSE))
>>> 
>>> That's probably an extreme example but hopefully it illustrates my point. 
>>> If you want to share a sample dataset/ model I can try to have a look at 
>>> how to resolve it.
>>> 
>>> Regards
>>> 
>>> On Tue, 20 Jul 2021 at 10:46, Richard McDonnell  
>>> wrote:
 
 Nicolas,
 
 I have not looked at this in too much detail, but at a quick glance, could 
 it not be the fact that you should be using the newly created fields? As 
 in instead of @NamelengthField != @NamelengthField || '2', should it not 
 be more like your previous example Length != Length2
 
 
 
 Regards,
 
 
 
 Richard
 
 
 
 
 
 
 ——
 Richard McDonnell MSc GIS, FME Certified Professional
 FRM Data Management
 
 ——
 Oifig na nOibreacha Poiblí
 Office of Public Works
 
 Sráid Jonathan Swift, Baile Átha Troim, Co na Mí, C15 NX36
 Jonathan Swift Street, Trim, Co Meath, C15 NX36
 ——
 M +353 87 688 5964 T +353 46 942 2409
 https://gov.ie/opw
 
 ——
 To send me files larger than 30MB, please use the link below 
 https://filetransfer.opw.ie/filedrop/richard.mcdonn...@opw.ie
 
 Email Disclaimer: 
 https://www.gov.ie/en/organisation-information/439daf-email-disclaimer/
 
 From: Qgis-user  On Behalf Of Nicolas 
 Cadieux
 Sent: 20 July 2021 09:27
 To: Qgis Users List 
 Subject: Re: [Qgis-user] Problem using Model Inputs variable in an Select 
 by expression in the model Designer
 
 
 
 Hi,
 
 Does anyone have an idea?
 
 Nicolas Cadieux
 
 https://gitlab.com/njacadieux
 
 
 
 Le 8 juill. 2021 à 01:17, Nicolas Cadieux  a 
 écrit :
 
 
 
 Hi,
 
 I am creating a model that fixes Network files before they are used in the 
 QGIS Network analysis (Shortest path) tools.
 
 This is my work flow:
 
 Create a "Length" field (value) and calculate $length in the field 
 calculator
 Split the Multipart lines into Singlepart lines
 Create a "Length2" field (value) and calculate $length in the field 
 calculator
 Select by expression Length != Length2.  This basically gives me a 
 selection of line that have been modified by the Multipart to Singlepart 
 algorithm. (I get 8 results)

Re: [Qgis-user] Problem using Model Inputs variable in an Select by expression in the model Designer

2021-08-23 Thread Nyall Dawson
On Tue, 24 Aug 2021 at 03:53, Charles Dixon-Paver  wrote:
>
> Honestly I have no idea 
>
> I mean, of course what is happening is QGIS is needing to identify a field 
> from a text string, and it's even possible that with some convoluted chain of 
> escape characters or funky regex the process could correct itself and "just 
> work".
>
> In all likelihood you could have just stumbled onto some obscure bug in the 
> underlying processing API where the context of that field object get's 
> dropped or orphaned when  trying to access it.

There's no bug here -- the variable value is just a pure text string,
and the expression engine can't automatically guess that you actually
want the value of the field with that name, and not just the name
string itself. Hence the need for the attribute function, which allows
you to retrieve a feature's fields via a text string containing the
field name.

Nyall


>
> My assumption is that using attribute() just compensates for whatever is 
> going on under the hood by reinstantiating the context behind the field 
> object, or at the very least provides a robust interface for referencing it 
> ¯\_(ツ)_/¯
>
> I would definitely call it a work around though
>
> On Mon, 23 Aug 2021 at 18:52, Nicolas Cadieux  
> wrote:
>>
>> Hi,
>>
>> if(attribute(to_string( @NamelengthField )) != "LENGTH2", TRUE, FALSE )
>>
>> ("LENGHT2" is an existing field and @NamelengthField was a model input 
>> string.)
>>
>> This worked  for me!   If you have the time, please explain why I needed the 
>> attribute() function for this to work.  I looked in the documentation and 
>> did not find it very clear.
>>
>> Thanks a million you saved my butt!
>>
>> Nicolas
>>
>>
>> On 2021-07-20 5:53 a.m., Charles Dixon-Paver wrote:
>>
>> Hi Nicholas,
>>
>> I haven't had time to dig into this extensively or encountered this 
>> particular issue, but I would suggest trying to "force" the expression to 
>> retrieve the correct info regardless of context using something like this:
>>
>> with_variable('Length2',  to_string(@NamelengthField) || '2', 
>> if(attribute(to_string(@NamelengthField)) != attribute(@Length2), TRUE, 
>> FALSE))
>>
>> That's probably an extreme example but hopefully it illustrates my point. If 
>> you want to share a sample dataset/ model I can try to have a look at how to 
>> resolve it.
>>
>> Regards
>>
>> On Tue, 20 Jul 2021 at 10:46, Richard McDonnell  
>> wrote:
>>>
>>> Nicolas,
>>>
>>> I have not looked at this in too much detail, but at a quick glance, could 
>>> it not be the fact that you should be using the newly created fields? As in 
>>> instead of @NamelengthField != @NamelengthField || '2', should it not be 
>>> more like your previous example Length != Length2
>>>
>>>
>>>
>>> Regards,
>>>
>>>
>>>
>>> Richard
>>>
>>>
>>>
>>>
>>>
>>>
>>> ——
>>> Richard McDonnell MSc GIS, FME Certified Professional
>>> FRM Data Management
>>>
>>> ——
>>> Oifig na nOibreacha Poiblí
>>> Office of Public Works
>>>
>>> Sráid Jonathan Swift, Baile Átha Troim, Co na Mí, C15 NX36
>>> Jonathan Swift Street, Trim, Co Meath, C15 NX36
>>> ——
>>> M +353 87 688 5964 T +353 46 942 2409
>>> https://gov.ie/opw
>>>
>>> ——
>>> To send me files larger than 30MB, please use the link below 
>>> https://filetransfer.opw.ie/filedrop/richard.mcdonn...@opw.ie
>>>
>>> Email Disclaimer: 
>>> https://www.gov.ie/en/organisation-information/439daf-email-disclaimer/
>>>
>>> From: Qgis-user  On Behalf Of Nicolas 
>>> Cadieux
>>> Sent: 20 July 2021 09:27
>>> To: Qgis Users List 
>>> Subject: Re: [Qgis-user] Problem using Model Inputs variable in an Select 
>>> by expression in the model Designer
>>>
>>>
>>>
>>> Hi,
>>>
>>> Does anyone have an idea?
>>>
>>> Nicolas Cadieux
>>>
>>> https://gitlab.com/njacadieux
>>>
>>>
>>>
>>> Le 8 juill. 2021 à 01:17, Nicolas Cadieux  a 
>>> écrit :
>>>
>>> 
>>>
>>> Hi,
>>>
>>> I am creating a model that fixes Network files before they are used in the 
>>> QGIS Network analysis (Shortest path) tools.
>>>
>>> This is my work flow:
>>>
>>> Create a "Length" field (value) and calculate $length in the field 
>>> calculator
>>> Split the Multipart lines into Singlepart lines
>>> Create a "Length2" field (value) and calculate $length in the field 
>>> calculator
>>> Select by expression Length != Length2.  This basically gives me a 
>>> selection of line that have been modified by the Multipart to Singlepart 
>>> algorithm. (I get 8 results)
>>>
>>> This works well
>>>
>>> The problem is when I create and Input String to let the user create a 
>>> "Length" field.  This become a variable called @NamelengthField. My work 
>>> flow become:
>>>
>>> User input "Length" in the Model input. (@NamelengthField)
>>> Create a "Length" field using  @NamelengthField (as pre-calculated value) 
>>> and calculate $length in the field calculator: This is OK
>>> Split the Multipart lines into Singlepart lines: This is OK
>>> Create a "Length2" field using  @NamelengthField ||'2'  (as pre-calculated 
>>> value) and calculate 

Re: [Qgis-user] Problem using Model Inputs variable in an Select by expression in the model Designer

2021-08-23 Thread Alexandre Neto
There's some missing spaces in the expression, but I think you got it.

A segunda, 23/08/2021, 23:07, Alexandre Neto 
escreveu:

> I am a bit late, and Charles already provided a working solution, but
> don't forget the extremely useful function eval.
>
> The function as is will compare fieldname to fieldname (returning true)
> and then try to concatenate the string '2' to it...
>
> @NamelengthField != @NamelengthField || '2'
>
>
> Try this:
>
> @NamelengthField || '!=' || @NamelengthField || '2'
>
> It will return the expression you need.
>
> 'length != length2'
>
>  Now, just wrap it on eval() to calculate it.
>
> eval(@NamelengthField || '!=' || @NamelengthField || '2')
>
> Best regards
>
> Alexandre Neto
> User support
> www.qcooperative.net
>
>
>
>
>
>
>
>
>
>
>
> A segunda, 23/08/2021, 18:53, Charles Dixon-Paver 
> escreveu:
>
>> Honestly I have no idea 
>>
>> I mean, of course what is happening is QGIS is needing to identify a
>> field from a text string, and it's even possible that with some convoluted
>> chain of escape characters or funky regex the process could correct itself
>> and "just work".
>>
>> In all likelihood you could have just stumbled onto some obscure bug in
>> the underlying processing API where the context of that field object get's
>> dropped or orphaned when  trying to access it.
>>
>> My assumption is that using attribute() just compensates for whatever is
>> going on under the hood by reinstantiating the context behind the field
>> object, or at the very least provides a robust interface for referencing it
>> ¯\_(ツ)_/¯
>>
>> I would definitely call it a work around though
>>
>> On Mon, 23 Aug 2021 at 18:52, Nicolas Cadieux <
>> njacadieux.git...@gmail.com> wrote:
>>
>>> Hi,
>>>
>>> if(attribute(to_string( @NamelengthField )) != "LENGTH2", TRUE, FALSE )
>>>
>>> ("LENGHT2" is an existing field and @NamelengthField was a model input
>>> string.)
>>>
>>> This worked  for me!   If you have the time, please explain why I needed
>>> the *attribute()* function for this to work.  I looked in the
>>> documentation and did not find it very clear.
>>>
>>> Thanks a million you saved my butt!
>>>
>>> Nicolas
>>>
>>>
>>> On 2021-07-20 5:53 a.m., Charles Dixon-Paver wrote:
>>>
>>> Hi Nicholas,
>>>
>>> I haven't had time to dig into this extensively or encountered this
>>> particular issue, but I would suggest trying to "force" the expression to
>>> retrieve the correct info regardless of context using something like this:
>>>
>>> with_variable('Length2',  to_string(@NamelengthField) || '2',
>>> if(attribute(to_string(@NamelengthField)) != attribute(@Length2), TRUE,
>>> FALSE))
>>>
>>> That's probably an extreme example but hopefully it illustrates my
>>> point. If you want to share a sample dataset/ model I can try to have a
>>> look at how to resolve it.
>>>
>>> Regards
>>>
>>> On Tue, 20 Jul 2021 at 10:46, Richard McDonnell <
>>> richard.mcdonn...@opw.ie> wrote:
>>>
 Nicolas,

 I have not looked at this in too much detail, but at a quick glance,
 could it not be the fact that you should be using the newly created fields?
 As in instead of *@NamelengthField != @NamelengthField || '2'*, should
 it not be more like your previous example *Length != Length2*



 Regards,



 Richard





 ——
 Richard McDonnell MSc GIS, FME Certified Professional
 *FRM Data Management*

 ——
 Oifig na nOibreacha Poiblí
 Office of Public Works

 Sráid Jonathan Swift, Baile Átha Troim, Co na Mí, C15 NX36
 Jonathan Swift Street, Trim, Co Meath, C15 NX36
 ——
 M +353 87 688 5964 T +353 46 942 2409
 https://gov.ie/opw

 ——
 To send me files larger than 30MB, please use the link below
 https://filetransfer.opw.ie/filedrop/richard.mcdonn...@opw.ie

 Email Disclaimer:
 https://www.gov.ie/en/organisation-information/439daf-email-disclaimer/

 *From:* Qgis-user  *On Behalf Of 
 *Nicolas
 Cadieux
 *Sent:* 20 July 2021 09:27
 *To:* Qgis Users List 
 *Subject:* Re: [Qgis-user] Problem using Model Inputs variable in an
 Select by expression in the model Designer



 Hi,

 Does anyone have an idea?

 Nicolas Cadieux

 https://gitlab.com/njacadieux



 Le 8 juill. 2021 à 01:17, Nicolas Cadieux 
 a écrit :

 

 Hi,

 I am creating a model that fixes Network files before they are used in
 the QGIS Network analysis (Shortest path) tools.

 This is my work flow:

1. Create a "Length" field (value) and calculate $length in the
field calculator
2. Split the Multipart lines into Singlepart lines
3. Create a "Length*2*" field (value) and calculate $length in the
field calculator
4. Select by expression Length != Length2.  This basically gives me
a selection of line that have been modified by the 

Re: [Qgis-user] Problem using Model Inputs variable in an Select by expression in the model Designer

2021-08-23 Thread Alexandre Neto
I am a bit late, and Charles already provided a working solution, but don't
forget the extremely useful function eval.

The function as is will compare fieldname to fieldname (returning true) and
then try to concatenate the string '2' to it...

@NamelengthField != @NamelengthField || '2'


Try this:

@NamelengthField || '!=' || @NamelengthField || '2'

It will return the expression you need.

'length != length2'

 Now, just wrap it on eval() to calculate it.

eval(@NamelengthField || '!=' || @NamelengthField || '2')

Best regards

Alexandre Neto
User support
www.qcooperative.net











A segunda, 23/08/2021, 18:53, Charles Dixon-Paver 
escreveu:

> Honestly I have no idea 
>
> I mean, of course what is happening is QGIS is needing to identify a field
> from a text string, and it's even possible that with some convoluted chain
> of escape characters or funky regex the process could correct itself and
> "just work".
>
> In all likelihood you could have just stumbled onto some obscure bug in
> the underlying processing API where the context of that field object get's
> dropped or orphaned when  trying to access it.
>
> My assumption is that using attribute() just compensates for whatever is
> going on under the hood by reinstantiating the context behind the field
> object, or at the very least provides a robust interface for referencing it
> ¯\_(ツ)_/¯
>
> I would definitely call it a work around though
>
> On Mon, 23 Aug 2021 at 18:52, Nicolas Cadieux 
> wrote:
>
>> Hi,
>>
>> if(attribute(to_string( @NamelengthField )) != "LENGTH2", TRUE, FALSE )
>>
>> ("LENGHT2" is an existing field and @NamelengthField was a model input
>> string.)
>>
>> This worked  for me!   If you have the time, please explain why I needed
>> the *attribute()* function for this to work.  I looked in the
>> documentation and did not find it very clear.
>>
>> Thanks a million you saved my butt!
>>
>> Nicolas
>>
>>
>> On 2021-07-20 5:53 a.m., Charles Dixon-Paver wrote:
>>
>> Hi Nicholas,
>>
>> I haven't had time to dig into this extensively or encountered this
>> particular issue, but I would suggest trying to "force" the expression to
>> retrieve the correct info regardless of context using something like this:
>>
>> with_variable('Length2',  to_string(@NamelengthField) || '2',
>> if(attribute(to_string(@NamelengthField)) != attribute(@Length2), TRUE,
>> FALSE))
>>
>> That's probably an extreme example but hopefully it illustrates my point.
>> If you want to share a sample dataset/ model I can try to have a look at
>> how to resolve it.
>>
>> Regards
>>
>> On Tue, 20 Jul 2021 at 10:46, Richard McDonnell 
>> wrote:
>>
>>> Nicolas,
>>>
>>> I have not looked at this in too much detail, but at a quick glance,
>>> could it not be the fact that you should be using the newly created fields?
>>> As in instead of *@NamelengthField != @NamelengthField || '2'*, should
>>> it not be more like your previous example *Length != Length2*
>>>
>>>
>>>
>>> Regards,
>>>
>>>
>>>
>>> Richard
>>>
>>>
>>>
>>>
>>>
>>> ——
>>> Richard McDonnell MSc GIS, FME Certified Professional
>>> *FRM Data Management*
>>>
>>> ——
>>> Oifig na nOibreacha Poiblí
>>> Office of Public Works
>>>
>>> Sráid Jonathan Swift, Baile Átha Troim, Co na Mí, C15 NX36
>>> Jonathan Swift Street, Trim, Co Meath, C15 NX36
>>> ——
>>> M +353 87 688 5964 T +353 46 942 2409
>>> https://gov.ie/opw
>>>
>>> ——
>>> To send me files larger than 30MB, please use the link below
>>> https://filetransfer.opw.ie/filedrop/richard.mcdonn...@opw.ie
>>>
>>> Email Disclaimer:
>>> https://www.gov.ie/en/organisation-information/439daf-email-disclaimer/
>>>
>>> *From:* Qgis-user  *On Behalf Of *Nicolas
>>> Cadieux
>>> *Sent:* 20 July 2021 09:27
>>> *To:* Qgis Users List 
>>> *Subject:* Re: [Qgis-user] Problem using Model Inputs variable in an
>>> Select by expression in the model Designer
>>>
>>>
>>>
>>> Hi,
>>>
>>> Does anyone have an idea?
>>>
>>> Nicolas Cadieux
>>>
>>> https://gitlab.com/njacadieux
>>>
>>>
>>>
>>> Le 8 juill. 2021 à 01:17, Nicolas Cadieux 
>>> a écrit :
>>>
>>> 
>>>
>>> Hi,
>>>
>>> I am creating a model that fixes Network files before they are used in
>>> the QGIS Network analysis (Shortest path) tools.
>>>
>>> This is my work flow:
>>>
>>>1. Create a "Length" field (value) and calculate $length in the
>>>field calculator
>>>2. Split the Multipart lines into Singlepart lines
>>>3. Create a "Length*2*" field (value) and calculate $length in the
>>>field calculator
>>>4. Select by expression Length != Length2.  This basically gives me
>>>a selection of line that have been modified by the Multipart to 
>>> Singlepart
>>>algorithm. (I get 8 results)
>>>
>>> This works well
>>>
>>> The problem is when I create and Input String to let the user create a
>>> "Length" field.  This become a variable called @NamelengthField. My work
>>> flow become:
>>>
>>>1. User input "Length" in the Model input. (@NamelengthField)
>>>2. Create a "Length" field using  

Re: [Qgis-user] Problem using Model Inputs variable in an Select by expression in the model Designer

2021-08-23 Thread Charles Dixon-Paver
Honestly I have no idea 

I mean, of course what is happening is QGIS is needing to identify a field
from a text string, and it's even possible that with some convoluted chain
of escape characters or funky regex the process could correct itself and
"just work".

In all likelihood you could have just stumbled onto some obscure bug in the
underlying processing API where the context of that field object get's
dropped or orphaned when  trying to access it.

My assumption is that using attribute() just compensates for whatever is
going on under the hood by reinstantiating the context behind the field
object, or at the very least provides a robust interface for referencing it
¯\_(ツ)_/¯

I would definitely call it a work around though

On Mon, 23 Aug 2021 at 18:52, Nicolas Cadieux 
wrote:

> Hi,
>
> if(attribute(to_string( @NamelengthField )) != "LENGTH2", TRUE, FALSE )
>
> ("LENGHT2" is an existing field and @NamelengthField was a model input
> string.)
>
> This worked  for me!   If you have the time, please explain why I needed
> the *attribute()* function for this to work.  I looked in the
> documentation and did not find it very clear.
>
> Thanks a million you saved my butt!
>
> Nicolas
>
>
> On 2021-07-20 5:53 a.m., Charles Dixon-Paver wrote:
>
> Hi Nicholas,
>
> I haven't had time to dig into this extensively or encountered this
> particular issue, but I would suggest trying to "force" the expression to
> retrieve the correct info regardless of context using something like this:
>
> with_variable('Length2',  to_string(@NamelengthField) || '2',
> if(attribute(to_string(@NamelengthField)) != attribute(@Length2), TRUE,
> FALSE))
>
> That's probably an extreme example but hopefully it illustrates my point.
> If you want to share a sample dataset/ model I can try to have a look at
> how to resolve it.
>
> Regards
>
> On Tue, 20 Jul 2021 at 10:46, Richard McDonnell 
> wrote:
>
>> Nicolas,
>>
>> I have not looked at this in too much detail, but at a quick glance,
>> could it not be the fact that you should be using the newly created fields?
>> As in instead of *@NamelengthField != @NamelengthField || '2'*, should
>> it not be more like your previous example *Length != Length2*
>>
>>
>>
>> Regards,
>>
>>
>>
>> Richard
>>
>>
>>
>>
>>
>> ——
>> Richard McDonnell MSc GIS, FME Certified Professional
>> *FRM Data Management*
>>
>> ——
>> Oifig na nOibreacha Poiblí
>> Office of Public Works
>>
>> Sráid Jonathan Swift, Baile Átha Troim, Co na Mí, C15 NX36
>> Jonathan Swift Street, Trim, Co Meath, C15 NX36
>> ——
>> M +353 87 688 5964 T +353 46 942 2409
>> https://gov.ie/opw
>>
>> ——
>> To send me files larger than 30MB, please use the link below
>> https://filetransfer.opw.ie/filedrop/richard.mcdonn...@opw.ie
>>
>> Email Disclaimer:
>> https://www.gov.ie/en/organisation-information/439daf-email-disclaimer/
>>
>> *From:* Qgis-user  *On Behalf Of *Nicolas
>> Cadieux
>> *Sent:* 20 July 2021 09:27
>> *To:* Qgis Users List 
>> *Subject:* Re: [Qgis-user] Problem using Model Inputs variable in an
>> Select by expression in the model Designer
>>
>>
>>
>> Hi,
>>
>> Does anyone have an idea?
>>
>> Nicolas Cadieux
>>
>> https://gitlab.com/njacadieux
>>
>>
>>
>> Le 8 juill. 2021 à 01:17, Nicolas Cadieux 
>> a écrit :
>>
>> 
>>
>> Hi,
>>
>> I am creating a model that fixes Network files before they are used in
>> the QGIS Network analysis (Shortest path) tools.
>>
>> This is my work flow:
>>
>>1. Create a "Length" field (value) and calculate $length in the field
>>calculator
>>2. Split the Multipart lines into Singlepart lines
>>3. Create a "Length*2*" field (value) and calculate $length in the
>>field calculator
>>4. Select by expression Length != Length2.  This basically gives me a
>>selection of line that have been modified by the Multipart to Singlepart
>>algorithm. (I get 8 results)
>>
>> This works well
>>
>> The problem is when I create and Input String to let the user create a
>> "Length" field.  This become a variable called @NamelengthField. My work
>> flow become:
>>
>>1. User input "Length" in the Model input. (@NamelengthField)
>>2. Create a "Length" field using  @NamelengthField (as pre-calculated
>>value) and calculate $length in the field calculator: This is OK
>>3. Split the Multipart lines into Singlepart lines: This is OK
>>4. Create a "Length2" field using  @NamelengthField ||'2'  (as
>>pre-calculated value) and calculate $length in the field calculator: This
>>is OK this field (Length2) is created and calculated properly.
>>5. I get stuck  when I try Select by expression using
>>@NamelengthField != @NamelengthField || '2' (as pre-calculated value) (I
>>get all lines back) and the test does not work.
>>
>> I tried stuff like
>>
>> @NamelengthField != (@NamelengthField || '2')
>>
>> '@NamelengthField != @NamelengthField || '2''
>>
>> "@NamelengthField != @NamelengthField || '2'"
>>
>> "@NamelengthField"|| !=|| "@NamelengthField || '2'"
>>
>> 

Re: [Qgis-user] Problem using Model Inputs variable in an Select by expression in the model Designer

2021-08-23 Thread Nicolas Cadieux

Hi,

if(attribute(to_string( @NamelengthField )) != "LENGTH2", TRUE, FALSE )

("LENGHT2" is an existing field and @NamelengthField was a model input 
string.)


This worked  for me!   If you have the time, please explain why I needed 
the _attribute()_ function for this to work.  I looked in the 
documentation and did not find it very clear.


Thanks a million you saved my butt!

Nicolas


On 2021-07-20 5:53 a.m., Charles Dixon-Paver wrote:

Hi Nicholas,

I haven't had time to dig into this extensively or encountered this 
particular issue, but I would suggest trying to "force" the expression 
to retrieve the correct info regardless of context using something 
like this:


with_variable('Length2',  to_string(@NamelengthField) || '2', 
if(attribute(to_string(@NamelengthField)) != attribute(@Length2), 
TRUE, FALSE))


That's probably an extreme example but hopefully it illustrates my 
point. If you want to share a sample dataset/ model I can try to have 
a look at how to resolve it.


Regards

On Tue, 20 Jul 2021 at 10:46, Richard McDonnell 
mailto:richard.mcdonn...@opw.ie>> wrote:


Nicolas,

I have not looked at this in too much detail, but at a quick
glance, could it not be the fact that you should be using the
newly created fields? As in instead of *@NamelengthField !=
@NamelengthField || '2'*, should it not be more like your previous
example *Length != Length2*

Regards,

Richard


——
Richard McDonnell MSc GIS, FME Certified Professional
/FRM Data Management/

——
Oifig na nOibreacha Poiblí
Office of Public Works

Sráid Jonathan Swift, Baile Átha Troim, Co na Mí, C15 NX36
Jonathan Swift Street, Trim, Co Meath, C15 NX36
——
M +353 87 688 5964 T +353 46 942 2409
https://gov.ie/opw 

——
To send me files larger than 30MB, please use the link below
https://filetransfer.opw.ie/filedrop/richard.mcdonn...@opw.ie


Email Disclaimer:
https://www.gov.ie/en/organisation-information/439daf-email-disclaimer/



*From:*Qgis-user mailto:qgis-user-boun...@lists.osgeo.org>> *On Behalf Of *Nicolas
Cadieux
*Sent:* 20 July 2021 09:27
*To:* Qgis Users List mailto:qgis-user@lists.osgeo.org>>
*Subject:* Re: [Qgis-user] Problem using Model Inputs variable in
an Select by expression in the model Designer

Hi,

Does anyone have an idea?

Nicolas Cadieux

https://gitlab.com/njacadieux 



Le 8 juill. 2021 à 01:17, Nicolas Cadieux
mailto:njacadieux.git...@gmail.com>> a écrit :



Hi,

I am creating a model that fixes Network files before they are
used in the QGIS Network analysis (Shortest path) tools.

This is my work flow:

 1. Create a "Length" field (value) and calculate $length in
the field calculator
 2. Split the Multipart lines into Singlepart lines
 3. Create a "Length*2*" field (value) and calculate $length
in the field calculator
 4. Select by expression Length != Length2.  This basically
gives me a selection of line that have been modified by
the Multipart to Singlepart algorithm. (I get 8 results)

This works well

The problem is when I create and Input String to let the user
create a "Length" field.  This become a variable called
@NamelengthField. My work flow become:

 1. User input "Length" in the Model input. (@NamelengthField)
 2. Create a "Length" field using @NamelengthField (as
pre-calculated value) and calculate $length in the field
calculator: This is OK
 3. Split the Multipart lines into Singlepart lines: This is OK
 4. Create a "Length2" field using @NamelengthField ||'2'  (as
pre-calculated value) and calculate $length in the field
calculator: This is OK this field (Length2) is created and
calculated properly.
 5. I get stuck  when I try Select by expression using 
@NamelengthField != @NamelengthField || '2' (as
pre-calculated value) (I get all lines back) and the test
does not work.

I tried stuff like

@NamelengthField != (@NamelengthField || '2')

'@NamelengthField != @NamelengthField || '2''

"@NamelengthField != @NamelengthField || '2'"

"@NamelengthField"|| !=|| "@NamelengthField || '2'"

Even simple @NamelengthField = 5.286365157529550 (which should
extract exactly one value).

Any ideas?

Nicolas

QGIS 3.18.2 on Windows 10

-- 


Nicolas Cadieux

https://gitlab.com/njacadieux  

___

Re: [Qgis-user] Problem using Model Inputs variable in an Select by expression in the model Designer

2021-07-20 Thread Nicolas Cadieux
Hi,

I see where this is going.  Good idea. I will think more like a python 
programmer here.  I will test and report back.  It may take a few days as I 
will simplify the model first and break it down. I might take you up on your 
offer for help and share the model and a test file. 
Thanks!

Nicolas Cadieux
https://gitlab.com/njacadieux

> Le 20 juill. 2021 à 05:53, Charles Dixon-Paver  a écrit :
> 
> to_string
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user


Re: [Qgis-user] Problem using Model Inputs variable in an Select by expression in the model Designer

2021-07-20 Thread Charles Dixon-Paver
Hi Nicholas,

I haven't had time to dig into this extensively or encountered this
particular issue, but I would suggest trying to "force" the expression to
retrieve the correct info regardless of context using something like this:

with_variable('Length2',  to_string(@NamelengthField) || '2',
if(attribute(to_string(@NamelengthField)) != attribute(@Length2), TRUE,
FALSE))

That's probably an extreme example but hopefully it illustrates my point.
If you want to share a sample dataset/ model I can try to have a look at
how to resolve it.

Regards

On Tue, 20 Jul 2021 at 10:46, Richard McDonnell 
wrote:

> Nicolas,
>
> I have not looked at this in too much detail, but at a quick glance, could
> it not be the fact that you should be using the newly created fields? As in
> instead of *@NamelengthField != @NamelengthField || '2'*, should it not
> be more like your previous example *Length != Length2*
>
>
>
> Regards,
>
>
>
> Richard
>
>
>
>
>
> ——
> Richard McDonnell MSc GIS, FME Certified Professional
> *FRM Data Management*
>
> ——
> Oifig na nOibreacha Poiblí
> Office of Public Works
>
> Sráid Jonathan Swift, Baile Átha Troim, Co na Mí, C15 NX36
> Jonathan Swift Street, Trim, Co Meath, C15 NX36
> ——
> M +353 87 688 5964 T +353 46 942 2409
> https://gov.ie/opw
>
> ——
> To send me files larger than 30MB, please use the link below
> https://filetransfer.opw.ie/filedrop/richard.mcdonn...@opw.ie
>
> Email Disclaimer:
> https://www.gov.ie/en/organisation-information/439daf-email-disclaimer/
>
> *From:* Qgis-user  *On Behalf Of *Nicolas
> Cadieux
> *Sent:* 20 July 2021 09:27
> *To:* Qgis Users List 
> *Subject:* Re: [Qgis-user] Problem using Model Inputs variable in an
> Select by expression in the model Designer
>
>
>
> Hi,
>
> Does anyone have an idea?
>
> Nicolas Cadieux
>
> https://gitlab.com/njacadieux
>
>
>
> Le 8 juill. 2021 à 01:17, Nicolas Cadieux  a
> écrit :
>
> 
>
> Hi,
>
> I am creating a model that fixes Network files before they are used in the
> QGIS Network analysis (Shortest path) tools.
>
> This is my work flow:
>
>1. Create a "Length" field (value) and calculate $length in the field
>calculator
>2. Split the Multipart lines into Singlepart lines
>3. Create a "Length*2*" field (value) and calculate $length in the
>field calculator
>4. Select by expression Length != Length2.  This basically gives me a
>selection of line that have been modified by the Multipart to Singlepart
>algorithm. (I get 8 results)
>
> This works well
>
> The problem is when I create and Input String to let the user create a
> "Length" field.  This become a variable called @NamelengthField. My work
> flow become:
>
>1. User input "Length" in the Model input. (@NamelengthField)
>2. Create a "Length" field using  @NamelengthField (as pre-calculated
>value) and calculate $length in the field calculator: This is OK
>3. Split the Multipart lines into Singlepart lines: This is OK
>4. Create a "Length2" field using  @NamelengthField ||'2'  (as
>pre-calculated value) and calculate $length in the field calculator: This
>is OK this field (Length2) is created and calculated properly.
>5. I get stuck  when I try Select by expression using
>@NamelengthField != @NamelengthField || '2' (as pre-calculated value) (I
>get all lines back) and the test does not work.
>
> I tried stuff like
>
> @NamelengthField != (@NamelengthField || '2')
>
> '@NamelengthField != @NamelengthField || '2''
>
> "@NamelengthField != @NamelengthField || '2'"
>
> "@NamelengthField"|| !=|| "@NamelengthField || '2'"
>
> Even simple @NamelengthField = 5.286365157529550 (which should extract
> exactly one value).
>
> Any ideas?
>
> Nicolas
>
> QGIS 3.18.2 on Windows 10
>
>
>
>
>
>
>
> --
>
> Nicolas Cadieux
>
> https://gitlab.com/njacadieux
>
> ___
> Qgis-user mailing list
> Qgis-user@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user


Re: [Qgis-user] Problem using Model Inputs variable in an Select by expression in the model Designer

2021-07-20 Thread Richard McDonnell
Nicolas,
I have not looked at this in too much detail, but at a quick glance, could it 
not be the fact that you should be using the newly created fields? As in 
instead of @NamelengthField != @NamelengthField || '2', should it not be more 
like your previous example Length != Length2

Regards,

Richard



——
Richard McDonnell MSc GIS, FME Certified Professional
FRM Data Management

——
Oifig na nOibreacha Poiblí
Office of Public Works

Sráid Jonathan Swift, Baile Átha Troim, Co na Mí, C15 NX36
Jonathan Swift Street, Trim, Co Meath, C15 NX36
——
M +353 87 688 5964 T +353 46 942 2409
https://gov.ie/opw

——
To send me files larger than 30MB, please use the link below 
https://filetransfer.opw.ie/filedrop/richard.mcdonn...@opw.ie

Email Disclaimer: 
https://www.gov.ie/en/organisation-information/439daf-email-disclaimer/
From: Qgis-user  On Behalf Of Nicolas Cadieux
Sent: 20 July 2021 09:27
To: Qgis Users List 
Subject: Re: [Qgis-user] Problem using Model Inputs variable in an Select by 
expression in the model Designer

Hi,
Does anyone have an idea?
Nicolas Cadieux
https://gitlab.com/njacadieux


Le 8 juill. 2021 à 01:17, Nicolas Cadieux 
mailto:njacadieux.git...@gmail.com>> a écrit :


Hi,

I am creating a model that fixes Network files before they are used in the QGIS 
Network analysis (Shortest path) tools.

This is my work flow:

  1.  Create a "Length" field (value) and calculate $length in the field 
calculator
  2.  Split the Multipart lines into Singlepart lines
  3.  Create a "Length2" field (value) and calculate $length in the field 
calculator
  4.  Select by expression Length != Length2.  This basically gives me a 
selection of line that have been modified by the Multipart to Singlepart 
algorithm. (I get 8 results)

This works well

The problem is when I create and Input String to let the user create a "Length" 
field.  This become a variable called @NamelengthField. My work flow become:

  1.  User input "Length" in the Model input. (@NamelengthField)
  2.  Create a "Length" field using  @NamelengthField (as pre-calculated value) 
and calculate $length in the field calculator: This is OK
  3.  Split the Multipart lines into Singlepart lines: This is OK
  4.  Create a "Length2" field using  @NamelengthField ||'2'  (as 
pre-calculated value) and calculate $length in the field calculator: This is OK 
this field (Length2) is created and calculated properly.
  5.  I get stuck  when I try Select by expression using  @NamelengthField != 
@NamelengthField || '2' (as pre-calculated value) (I get all lines back) and 
the test does not work.

I tried stuff like

@NamelengthField != (@NamelengthField || '2')

'@NamelengthField != @NamelengthField || '2''

"@NamelengthField != @NamelengthField || '2'"

"@NamelengthField"|| !=|| "@NamelengthField || '2'"

Even simple @NamelengthField = 5.286365157529550 (which should extract exactly 
one value).

Any ideas?

Nicolas

QGIS 3.18.2 on Windows 10







--

Nicolas Cadieux

https://gitlab.com/njacadieux
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user


Re: [Qgis-user] Problem using Model Inputs variable in an Select by expression in the model Designer

2021-07-20 Thread Nicolas Cadieux
Hi,
Does anyone have an idea?

Nicolas Cadieux
https://gitlab.com/njacadieux

> Le 8 juill. 2021 à 01:17, Nicolas Cadieux  a 
> écrit :
> 
> 
> Hi,
> 
> I am creating a model that fixes Network files before they are used in the 
> QGIS Network analysis (Shortest path) tools.
> 
> This is my work flow:
> 
> Create a "Length" field (value) and calculate $length in the field calculator
> Split the Multipart lines into Singlepart lines
> Create a "Length2" field (value) and calculate $length in the field calculator
> Select by expression Length != Length2.  This basically gives me a selection 
> of line that have been modified by the Multipart to Singlepart algorithm. (I 
> get 8 results)
> This works well
> 
> The problem is when I create and Input String to let the user create a 
> "Length" field.  This become a variable called @NamelengthField. My work flow 
> become:
> 
> User input "Length" in the Model input. (@NamelengthField)
> Create a "Length" field using  @NamelengthField (as pre-calculated value) and 
> calculate $length in the field calculator: This is OK
> Split the Multipart lines into Singlepart lines: This is OK
> Create a "Length2" field using  @NamelengthField ||'2'  (as pre-calculated 
> value) and calculate $length in the field calculator: This is OK this field 
> (Length2) is created and calculated properly. 
> I get stuck  when I try Select by expression using  @NamelengthField != 
> @NamelengthField || '2' (as pre-calculated value) (I get all lines back) and 
> the test does not work.
> I tried stuff like
> 
> @NamelengthField != (@NamelengthField || '2')
> 
> '@NamelengthField != @NamelengthField || '2''
> 
> "@NamelengthField != @NamelengthField || '2'"
> 
> "@NamelengthField"|| !=|| "@NamelengthField || '2'"
> 
> Even simple @NamelengthField = 5.286365157529550 (which should extract 
> exactly one value).  
> 
> Any ideas?
> 
> Nicolas
> 
> QGIS 3.18.2 on Windows 10 
> 
> 
> 
> 
> 
> 
> 
> -- 
> Nicolas Cadieux
> https://gitlab.com/njacadieux
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user