MapBasic code needed to automate creating thematic maps

576 views
Skip to first unread message

Kalpakjian

unread,
Feb 11, 2008, 3:04:15 PM2/11/08
to MapInfo-L
Hi,

I'm looking for some code or help to automate creating thematic maps
in MapBasic.

I'm currently creating a thematic map in MapInfo and then copying and
pasting the resultant code from the MapInfo MapBasic window into my
MapBasic program, then using the "shade" command to run it.

Ideally, I would like to be able shade various names or values on an
as needed basis, and not have the values hard coded. This is mainly,
because the data is constantly changing, and would mean that there
would be less need to update the program.

I'm very new to this, so any help would be appreciated.

Many thanks

Kal

Rob Schneider - Aurchem Exploration

unread,
Feb 11, 2008, 3:48:51 PM2/11/08
to mapi...@googlegroups.com
Here is some code that I use to identify the type of theme breaks needed
(fixed vs percentile) by user input dialogue, then call an ini for the
appropriate breaks, then build a theme statement that I run with the Run
Command.

Many kudos to Russell Lawley's qik_percents.mbx on which most of this
code is based.

HTH,
Rob

'*************************************************************
'THEME DIALOG AND SETUP
'*************************************************************
SUB stdTheme
'OnError GoTo ThemeError
sIniFile = ApplicationDirectory$() + "aurchem.ini"
winID = FrontWindow()
winType = WindowInfo(winID,WIN_INFO_TYPE)
if winID = 0 then
note "Open a MAP window first"
exit sub
end if
If (wintype <> WIN_MAPPER) Then
note "Select an open MAP window first"
exit sub
end if
sTableList = MakeTabsList$(3)
sTableName = ""
sColumnlist = ""
Dialog Title "APPLY AURCHEM THEME" Calling fillColumnListBox
Control GroupBox Title "Range Type:" Position 5,5 Width 100 Height 38
Control RadioGroup Title "Fixed (Rock);Percentile (Geochem)" Value 1
Into nSampleType ID 100 Position 12,16 Width 80 Calling fillColumnListBox
Control GroupBox Title "Colour Ranges For:" Position 5,50 Width 220
Height 80
Control StaticText Title "Table:" Position 10,62
Control StaticText Title "Column:" Position 120,62
Control ListBox Position 10,72 Width 100 Height 50 Title From
Variable sTablelist Value 1 ID 101 Calling fillColumnListBox
Control ListBox Position 120,72 Width 100 Height 50 Title From
Variable sColumnList Value 1 ID 102 Calling selectColumn
Control OKButton
Control CancelButton
If CommandInfo(CMD_INFO_DLG_OK) Then
' Spacer
Else
Exit Sub
End if
' Calculate Range Breaks
If nSampleType = 1 Then
sDefaultSymbol = GetIni("Main", "fixedsymbol", "34", sIniFile)
Select aDataCol From sTableName Into percenttemp Order By
aDataCol
nRows = Tableinfo("percenttemp",tab_info_nrows)
Fetch first From percenttemp
nValueMin = percenttemp.col1
Fetch last From percenttemp
nValueMax = percenttemp.col1
nBreak(1)= nValueMin
nBreak(9)= nValueMax
sBreak = GetIni("Main", "fixedbreak", "1,10,20,30,40,50,60",
sIniFile)
nStep = 8
For counter = 2 to nStep
nBreak(counter) = GetListItem$(sBreak,counter-1,",")
Next
Else
sDefaultSymbol = GetIni("Main", "percentsymbol", "34", sIniFile)
Select aDataCol From sTableName Into percenttemp Order By
aDataCol
nRows = Tableinfo("percenttemp",tab_info_nrows)
Fetch first From percenttemp
nValueMin = percenttemp.col1
Fetch last From percenttemp
nValueMax = percenttemp.col1
nBreak(1)= nValueMin
nBreak(9)= nValueMax
sBreak = GetIni("Main", "percentbreak",
"90,95,96,97,98,99,99.5", sIniFile)
nStep = 8
FOR counter = 2 TO nStep
nStepVal = GetListItem$(sBreak,counter-1,",")
nRowNum = round(nStepVal*nRows/100,1)
Fetch rec(nRowNum) FROM percenttemp
nBreak(counter) = percenttemp.col1
Next
End If
' Build Thematic Command
sSymbol(1) = " Symbol (49,12632256,12) ,"
sSymbol(2) = " Symbol ("+sDefaultSymbol+",16752895,8) ,"
sSymbol(3) = " Symbol ("+sDefaultSymbol+",9445631,8) ,"
sSymbol(4) = " Symbol ("+sDefaultSymbol+",255,8) ,"
sSymbol(5) = " Symbol ("+sDefaultSymbol+",65280,12) ,"
sSymbol(6) = " Symbol ("+sDefaultSymbol+",16776960,12) ,"
sSymbol(7) = " Symbol ("+sDefaultSymbol+",16744448,12) ,"
sSymbol(8) = " Symbol ("+sDefaultSymbol+",16711680,12)"
sStatementStart = "shade window " + winID + " " + sTableName + "
with " + sDataCol + " ranges apply all use all Symbol (49,12632256,12) "
sStatementMid = ""
sStatementEnd = " default Brush (2,8421504,16777215) # use 2 round
1 inflect off Symbol (0,0,0) at 5 by 0 color 1 #"
For counter = 1 to nStep
sStatementMid = sStatementMid + nBreak(counter) + ": " +
nBreak(counter +1) + sSymbol(counter)
Next
sStatement = sStatementStart + sStatementMid + sStatementEnd
'Print sStatement
Run Command sStatement
If nSampleType = 1 Then
Set Legend window WinID layer prev display on shades off symbols on
lines off count off title "Samples - Rock (Au ppm)" Font ("Arial",0,9,0)
subtitle "Samples - Downhole Intersections (AU ppm)" Font
("Arial",0,9,0) ascending off ranges Font ("Arial",0,8,0) auto display
off ,auto display on ,auto display on ,auto display on ,auto display on
,auto display on ,auto display on ,auto display on ,auto display on
Else
Set legend window WinID layer prev display on shades off symbols on
lines off count off title "Samples - Soil (AU ppm)" Font ("Arial",0,9,0)
subtitle "Pecentiles (90,95,96,97,98,99,99.5)" Font ("Arial",0,8,0)
ascending off ranges Font ("Arial",0,8,0) auto display off ,auto display
on ,auto display on ,auto display on ,auto display on ,auto display on
,auto display on ,auto display on ,auto display on
End If
Open Window Legend
Run Menu Command M_Query_Unselect
Close Table percenttemp
EXIT Sub
ThemeError:
Note "Something bad happened"
END SUB
'*************************************************************

> .
>
>

Reply all
Reply to author
Forward
0 new messages