MapInfo Pro

  • 1.  MapInfo Monday: Using IIf in Label Expressions

    Employee
    Posted 08-02-2021 10:14
    Edited by Peter Møller 08-03-2021 01:47
    Happy #MapInfoMonday,

    Today, I​'ll provide you with a tiny but useful tip to avoid too much clutter in your map by only labelling some of your records.

    In this example, we are looking at a property map and we have added labels with the property number. As you can see in the map below, the map does look a bit cluttered as there are too many labels. How can you limit the number of labels shown, and limit it so that it's the "important" records that get labelled?

    To manage which objects to label, you can use the IIf function to specify a condition the records should meet. The logic here is if the condition is met, the IIf function will return the label string to apply, if not, it will return an empty string which basically won't show the label.

    Here's the expression used:

    In this example, I use the area of the properties as a weight to determine if the label should be visible or not. If the area is larger than 0.25 square km, the label which here is read from the column MATRNR will be shown:

    IIf(Area(Object, "sq km") > 0.25, MATRNR, "")

    Below you can see the resulting map with a lot fewer labels.

    You can use multiple Label Overrides to change the size of the properties as the user changes the zoom, or just have two label overrides: 1 to show all labels when you have zoomed in and another to limit the number of labels to some degree. In the image below, you can see an example where I have added 5 Label Overrides to change the size of the property to match the zoom level.

    This is just one basic example of how you can use the IIf-function to control your labels. You can use this in multiple ways to control what label, you are showing to the user.

    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------


  • 2.  RE: MapInfo Monday: Using IIf in Label Expressions

    Posted 08-09-2021 03:38
    Where is this function documented in the Help?

    ------------------------------
    Mark Duffett
    Department of State Growth
    Rosny Park TAS
    ------------------------------



  • 3.  RE: MapInfo Monday: Using IIf in Label Expressions

    Employee
    Posted 08-09-2021 05:01
    Hi Mark

    The IIf() function is documented in the MapBasic Reference Guide.
    If you have MapInfo Pro v2019.3, you can access the MapBasic Reference Help file via the SQL Window under Help.


    You can also download the MapBasic v2019.3 and get the documentation through this installation.

    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 4.  RE: MapInfo Monday: Using IIf in Label Expressions

    Posted 02-02-2022 07:17
    Hi Peter,

    I tried the IIF function in label expression with the objective, to take the last three characters of a name if label name starts with the letters ZA by using this function  IIF(Left$(hole_id, 2)="ZA", Right$(hole_id, 3), ""). However, it doesn't work for some reason all the labels starting both starting with PB and ZA are still plotted in full. Is there something wrong with my expression?

    Kind Regards,
    Victor

    ------------------------------
    Victor Kakebeeke
    Global Prospecting Limited
    Lichfield
    ------------------------------



  • 5.  RE: MapInfo Monday: Using IIf in Label Expressions

    Employee
    Posted 02-02-2022 09:10
    Hi Victor

    Your expression looks fine and seems also to work for me.

    Using the MapBasic window, or the SQL Window, I tried running these statements to the result from certain value:

    Dim hole_id As string
    hole_id = "ZBABC"
    Print "Result: " + IIF(Left$(hole_id, 2)="ZA", Right$(hole_id, 3), "")
    hole_id = "ZAABC"
    Print "Result: " + IIF(Left$(hole_id, 2)="ZA", Right$(hole_id, 3), "")

    This is the result in the Message window:
    Result:
    Result: ABC

    The logic of the expression says:
    • if the first two letters from column hole_id are equal to "ZA", return the last three letters from the column hole_id
    • In all other cases, return an empty string.
    What values does the column hole_id contain?

    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 6.  RE: MapInfo Monday: Using IIf in Label Expressions

    Posted 02-03-2022 09:41
    Thank you very much Peter.

    I started from fresh restarted everything and the label does indeed work correctly now. Thanks,
    Victor

    ------------------------------
    Victor Kakebeeke
    Global Prospecting Limited
    Lichfield
    ------------------------------