MapInfo Pro

 View Only
  • 1.  Using a variable with layer filter

    Posted 10-18-2024 05:33
    Edited by Peter Møller 10-24-2024 01:39

    Hi,

    I am trying to write a MapBasic program that utilizes the layer filter functionality based on user input. For simplification, my code is roughly trying to work as follows:

    Dim Reg as String
     
    Reg = Input("Region Picker", "_Zoom to:", "Region name", "String")
    Select obj from REGIONS where Name = Reg
     
    Set Map Window 3297 Zoom Entire Selection
     
    Set Map Window 3297 Layer REGIONS Filter where Name = Reg
    Set Map Window 3297 Layer REGIONS Filter on

     

    The trouble is, the filter expression doesn't like me using the variable Reg (though it is perfectly happy if I use for example, "Essex" instead. I'm sure there is a way I can work around this but I can't for the life of me remember how. 

    Any help would be welcome!



    ------------------------------
    Ryan Cook
    ORH LTD
    ------------------------------



  • 2.  RE: Using a variable with layer filter

    Posted 10-20-2024 18:19
    Edited by Peter Møller 10-24-2024 01:40

    Hi Ryan,

    You probably have to use Set Command:

    Dim sCmd As String

    sCmd = "Set Map Window 3297 Layer REGIONS Filter where Name = """ + Reg + """"

    Run Command sCmd



    ------------------------------
    James Nolet
    GIS Manager
    Caf Consulting
    Mentone office, VIC, Australia
    ------------------------------



  • 3.  RE: Using a variable with layer filter

    Posted 10-23-2024 09:24
    Edited by Peter Møller 10-24-2024 01:44

    Yes, thanks James. For the record, I ended up doing something similar but with a thematic:

    Dim Reg, sStatement as String

    Dim nWIn, cnt, nFirstMID, nSecondMID, nThirdMID, nFourthMID As Integer
     
    cnt=0
     
    For nWin = 1 To NumWindows()
      If WindowInfo(WindowID(nWin), WIN_INFO_TYPE) = WIN_MAPPER Then
        cnt=cnt+1
        If cnt=1 then NFirstMID = WindowID(nWin) End If
        If cnt=2 then nSecondMID = WindowID(nWin) End If
        If cnt=3 then nThirdMID = WindowID(nWin) End If
        If cnt=4 then nFourthMID = WindowID(nWin) End If
      End If
    Next
     
     
    Print "Recentering all layout frames to " + Reg + "..."
    Print "0 of 4..."
    Set Map Window NFirstMID Zoom Entire Selection
    sStatement = "Set Shade Window " + NfirstMID
       + " " + """NF4_StationGrounds(1)""" + " with StationGround = " + Chr$(34) + Reg + Chr$(34)
       + " values 0 Brush (2,7171184,16777215) Pen (2,2,16777215) ,1 Brush (1,16771280,16777215) Pen (2,2,16777215) default Brush (1,0,16777215) Pen (1,2,0)"
    Run Command sStatement

    etc

    This was written for a specific project in mind where the workspace always included 4 layouts. I'd like to create a more generic one which could be used with any workspace of any number of layouts. I believe I could use an array variable but I'm not sure how to go about using it...



    ------------------------------
    Ryan Cook
    ORH LTD
    ------------------------------