Use Expression: If Statement for adding feature label text

Use Expression: If Statement for adding feature label text

townest
Advocate Advocate
5,023 Views
12 Replies
Message 1 of 13

Use Expression: If Statement for adding feature label text

townest
Advocate
Advocate

Hi All,

I'm struggling to write an expression that labels features that are NOT NULL.  If the field is populated then I want the label.  If it is NULL or Blank then no label.

 

Here's what I have so far:

 If ('  "tblParcel|ParcelNum" NULL ', ' true ', ' false ' ) 

which oddly returns "text" as the label.

 

The tblParcel|ParcelNum" is a joined property.  I'll substitute the 'true' and 'false' with my desired text once I get it working.

 

Thank you.

 

Tyler

 

0 Likes
Accepted solutions (1)
5,024 Views
12 Replies
Replies (12)
Message 2 of 13

townest
Advocate
Advocate

Now that I've played with it a bit longer I'm finding even a simple concat is not working with joined properties (eg ODBC connected table, joined to layer which could look like tblparcel|parcelnum)?  The expression starts as valid but as soon as I close the 'create expression' dialogue the entire expression is wrapped in quotes and 'text' is returned to all labels.  

 

 

Any ideas on how to deal with joined properties?

 

Thank you.

 

Tyler

0 Likes
Message 3 of 13

kajar
Advocate
Advocate

When you want to lebel features which are not null then use conversion function:

NullValue([Property],['VALUE MISSING'])

Property - text property you want to show as label 

'VALUE MISSING'- value added for features when property IS NULL.

When you want not to show anything when feature property IS NULL then just use [''] instead ['VALUE MISSING']

Kajar

0 Likes
Message 4 of 13

ChicagoLooper
Mentor
Mentor

You can do it by using a Thematic Rule. Trying to add an expression to a 'Feature Label' will not produce the desired results. (Note: There may be other ways to do this. This is one such way.)

 

From the Style Editor, you will create a 'theme' which will consist of two groups: (1)Not Null and (2)Null. You will label one group but not the other. This is how. Just follow the captions at the bottom if each image. 

1-Open the style editor, click the ellipsis.1-Open the style editor, click the ellipsis.2-My 'Property' is thickness, denoted thick (your property may vary). Most times thick has a 'value' while other times, thick is BLANK.2-My 'Property' is thickness, denoted thick (your property may vary). Most times thick has a 'value' while other times, thick is BLANK.3-The 'Operator'  =  Is Not Null.3-The 'Operator' = Is Not Null.4-When there are 'thick' values, the expression will look like this. To confirm, click VALIDATE.4-When there are 'thick' values, the expression will look like this. To confirm, click VALIDATE.

5-This is first part of the theme. These entities will get labels, the second part will be label-less.5-This is first part of the theme. These entities will get labels, the second part will be label-less.6-Click DUPLICATE to create a second entry. Click the ellipsis on the duplicate.6-Click DUPLICATE to create a second entry. Click the ellipsis on the duplicate.7-The Property is still 'thick.' This time, the 'Operator' = Is Null.7-The Property is still 'thick.' This time, the 'Operator' = Is Null.8-When 'thick' value is null, the expression will look like this. To confirm, click VALIDATE.8-When 'thick' value is null, the expression will look like this. To confirm, click VALIDATE.9-The style editor now looks like this.9-The style editor now looks like this.10-If thick is 'Not Null' then you will make labels. You will NOT makes lables if Null.10-If thick is 'Not Null' then you will make labels. You will NOT makes lables if Null.11-This is final result. You can even 'stylize' not null to be a different color.11-This is final result. You can even 'stylize' not null to be a different color.

Chicagolooper

EESignature

0 Likes
Message 5 of 13

kajar
Advocate
Advocate

NullValue make same thing 🙂

0 Likes
Message 6 of 13

parkr4st
Advisor
Advisor

as will

 

Concat ( Property, '')   such as      Concat (  MapLot , '') 

0 Likes
Message 7 of 13

townest
Advocate
Advocate

Lots of great suggestions, but I'm well aware of how if statements and concat works. 

 

The key word in the question is 'joined' properties.  Map3d fails (so far) when joined properties are used in concert with expression functions (eg. Concat, If).  Please, someone try using 'joined' properties in functions and report back.  Joins are extremely powerful, so missing this functionality would be disappointing.

 

Note: My layer join is working just fine to both xlsx and accdb ODBC data connection.  The join has been tested on xlsx and accdb with same results.  Non-function single expressions with joined properties work just fine (eg. "tblParcel|ParcelNum", the parcel number is labeled just fine from a joined xlsx ODBC data connection).  

0 Likes
Message 8 of 13

parkr4st
Advisor
Advisor

It should not matter if the data is joined.  can you post a record with the joined data so we can see what it looks like?

 

dave

0 Likes
Message 9 of 13

townest
Advocate
Advocate

I couldn't agree more.  It shouldn't matter, and I'm hoping it doesn't.  See attached.  Thanks for taking a look.

0 Likes
Message 10 of 13

O_Eckmann
Mentor
Mentor
Accepted solution

Hi,

 

Native field are written directly, but joined filed are written with double quote. So when you transform condition into text with single quote around, AutoCAD MAP is not able to recognize joined field. I've tested with 2015 and 2019 with same error. I confirm it seems to be a bug : joined field doesn't seem to be usable inside expression.

 

Olivier

Olivier Eckmann

EESignature

0 Likes
Message 11 of 13

parkr4st
Advisor
Advisor

finish preparing the data

save the sdf to a new sdf

with mapimport and mapexport the field names can be changed to simple titles which will label easily

Work with the new sdf when adding objects to the data set

 

dave

0 Likes
Message 12 of 13

townest
Advocate
Advocate

Major bummer.

0 Likes
Message 13 of 13

cadley
Community Visitor
Community Visitor

Just wanted to drop a note that you are a lifesaver, thanks!

0 Likes