0
Include "MapBasic.def"

Declare Sub Main

Sub Main()
    Dim ColumnCount as integer
    Dim ColumnName as string
    Dim TableName as string
    Dim SelCol as Alias
    Dim WinID as integer
    Dim TableCount as integer
    Dim TableIndex as integer
    
    WinID = FrontWindow()

    TableCount = NumTables()

    For TableIndex = 1 To TableCount
        TableName = TableInfo(TableIndex, TAB_INFO_NAME)
        Print TableName

        For ColumnCount = 1 To TableInfo(TableIndex, TAB_INFO_NCOLS)
            ColumnName = ColumnInfo(TableIndex, "COL" & ColumnCount, COL_INFO_NAME)
            Print ColumnName

            If ColumnName = "ELEV" Then
                Print "ELEV Found."
                Print TableName & "." & ColumnName
                SelCol = ColumnName
                
                Shade Window WinID TableName With SelCol
                ignore 0
                Ranges
                10000  :  2000  Symbol(108, 16753029, 10, "Wingdings", 0, 0),
                2000   :  10    Symbol(108, 16757529, 10, "Wingdings", 0, 0),
                10     : -30    Symbol(108, 13757529, 10, "Wingdings", 0, 0),
                -30    : -5000  Symbol(108, 19457529, 10, "Wingdings", 0, 0),
                -5000  : -10000 Symbol(108, 19757529, 10, "Wingdings", 0, 0),
                -10000 : -20000 Symbol(108, 19857529, 10, "Wingdings", 0, 0)
                Exit For
            End If
        Next
    Next
End Sub

So I got this mapbasic code that create a Thematic Map for Ranges like this:

MapRange

The problem is that I need a Grid Thematic, specifically for elevation, like this:

MapByElevation

Does anyone know how I could turn this code to a grid based one or has an alternative code that works?

1
  • Do you have access to MapInfo Pro Advanced? If so, have a look at the Raster Interpolation tools on the Raster tab Commented Jun 25 at 8:34

1 Answer 1

0
Include "MapBasic.def"

Declare Sub Main

Sub Main()
    Dim TableIndex as integer
    Dim TableName as string
    Dim ColumnIndex as integer
    Dim ColumnName as string
    Dim WinID as integer
    Dim SelCol as Alias
    Dim TableCount as integer
     Dim ElevTable as String
     Dim TablePath as String
     Dim grdExt As String 
     Dim tabExt As String
     Dim ElevTable1 As String
     Dim ElevTable2 As String
     Dim TableBound As String
     Dim BoundFound As integer
     Dim TabPath As String
     Dim TabslashPos As integer
     grdExt = ".grd"
     tabExt = ".TAB"
     
     Run Menu Command 840
    WinID = FrontWindow()
    TableCount = NumTables()
     BoundFound = 0
    For TableIndex = 1 To TableCount
        TableName = TableInfo(TableIndex, TAB_INFO_NAME)
         If BoundFound = 0 Then
            If InStr(1, TableName, "Boundary") > 0 Or InStr(1, TableName, "Bound") > 0 Then
                TableBound = TableName
                BoundFound = 1
            Else
                TableBound = ""
            End If
         End If

        TabPath = TableInfo(TableName, TAB_INFO_TABFILE)
    
        TabslashPos = InStr(1, TabPath, "\")
    
        Print "TabSlashPos: " & TabSlashPos

        If TabslashPos > 0 Then
            TablePath = Left$(TabPath, TabslashPos)
         Else
            TablePath = TabPath
         End If

        Print "TablePath: " & TablePath

        Print "TableBound: " & TableBound
         
        Print "Processing table: " & TableName
         
        For ColumnIndex = 1 To TableInfo(TableIndex, TAB_INFO_NCOLS)
            ColumnName = ColumnInfo(TableIndex, "COL" & ColumnIndex, COL_INFO_NAME)

            If ColumnName = "ELEV" Then
                  ElevTable = TablePath & "\" & TableName
                  ElevTable1 = ElevTable & "_ELEV" & grdExt
                  Print ElevTable
                  Print ElevTable1
                Print "ELEV column found in table: " & TableName

                Add Map Auto Layer TableName

                Set Map Redraw Off

                Set Map Layer 1 Display Off

                Set Map Redraw On

                Create Grid
                    From TableName
                    With ELEV
                       Into ElevTable1
                       Clipping Table TableBound
                    Inflect 6 At
                        RGB( 51,    0,  102):  -10000
                            RGB(  0,  153,  153):  -5000
                            RGB( 51,  255,  255):  -30
                            RGB(255,  255,  204):   10
                            RGB(255,  153,   51):   2000
                            RGB(255,  128,    0):   10000
                    Cell Min 1000
                    Interpolate
                    With "IDW" Version "100"
                    Using 5
                    "EXPONENT": "2"
                       "GRID BORDER": "0"
                    "MAX POINTS": "25"
                    "MIN POINTS": "1"
                    "SEARCH RADIUS": "100"
                Exit For
            End If
        Next
    Next
    
     Remove Map Layer 1
     ElevTable2 = ElevTable & "_ELEV" & tabExt
     Print ElevTable2
     Open Table ElevTable2
     If InStr(1, TableName, "_ELEV") > 0 Then
         TableName = TableName
     Else
         TableName = TableName & "_ELEV"
     End If
     Add Map Layer TableName position 3
     Create Legend
        From Window WinID
        Show
    Set Map Redraw On
End Sub

Managed to make this code and it works. There might be some complications when creating a 3D map with it but otherwise its fully functional.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.