How to extract with mapbasic informations (number, value, style) from a thematic map?

391 views
Skip to first unread message

Olivier ATHIMON

unread,
Mar 24, 2009, 7:38:58 AM3/24/09
to mapi...@googlegroups.com
Hi all,

I wish to find in mapbasic how to extract the shade (style, color,...)
from a thematic map... Is it possible?

To make a thematic map, the command is:
"Set Shade [ Window window_id ] { map_layer_id | "table (
theme_layer_id )" } . . . "

To extract a thematic map, i suppose that i must use: layerinfo()...
but i don't know how to determine the number of values used in thematic
map, and for each value the style/color of the objects...

How to find by example the values (extracted from a .WOR) without write
and read a .WOR...:
>
shade 1 with Type values
"AB" Brush (2,16711680,16777215) Pen (1,2,0) ,
"BC" Brush (5,65280,16777215) Pen (1,2,0) ,
"CD" Brush (2,255,16777215) Pen (4,2,16711680) ,
"ESP" Brush (2,16711935,16777215) Pen (1,2,0)
default Brush (1,0,16777215) Pen (1,2,0) # color 1 #
>
How to know in mapbasic that i have 4 values ("AB", "BC", "CD" and
"ESP") in my thematic map?
objectinfo() tell me that i have a thematic but not the number and the
values inside...

And how to know the type of objects and their styles?
I suppose that i must use the function: styleattr()...

For 1st value: object/thematic with value "AB"...
value_pen_width = StyleAttr(object/thematic with value "AB", PEN_WIDTH)
value_pen_color = StyleAttr(object/thematic with value "AB", PEN_COLOR)
...
For 2nd value: object/thematic with value "BC"...
value_pen_width = StyleAttr(object/thematic with value "BC", PEN_WIDTH)
value_pen_color = StyleAttr(object/thematic with value "BC", PEN_COLOR)
...
...

Thanks to help me to find the solution.

Maurice34

unread,
Mar 24, 2009, 8:03:34 AM3/24/09
to MapInfo-L
Hello,
The only way I know: WindowInfo (window_spec , WIN_INFO_CLONEWINDOW /
15) give a string value
Then you have to extract the things you want from this string...
Not very easy :(

Bill Thoen

unread,
Mar 24, 2009, 12:39:03 PM3/24/09
to mapi...@googlegroups.com
Olivier ATHIMON wrote:
> Hi all,
>
> I wish to find in mapbasic how to extract the shade (style, color,...)
> from a thematic map... Is it possible?
> ...
>
You can't get at a thematic layer directly. It would be nice if it was
based on a table with objects and records like normal layers, but it's
not. The solution is as Maurice34 said --use a window clone-- but it's
not that hard. Here's a little routine I wrote a while ago to do this:

' ExtractThematic.mb
Include "MapBasic.def"

Declare Sub Main
Declare Function GetNextRecord(
ByVal sText As String, ' lines of text to parse
n As Integer ) ' updated pointer into the text
As String ' returns the next line of text

Sub Main
Dim i, j As Integer
Dim m,n As Integer
Dim sText, sShadeText As String
Dim sRec As String

CLS
sText = WindowInfo( FrontWindow(), WIN_INFO_CLONEWINDOW )
j = Len( sText )
n = 1
Do While n < j
sRec = GetNextRecord( sText, n )

' look for the start of the shade clause
If Left$(sRec, 5) = "shade" Then
' gather up all the lines in the shade clause
Do While n < j
sShadeText = sShadeText + sRec
sRec = GetNextRecord( sText, n )
' all lines in the shade clause after the first start with a space.
If Left$(sRec,1) <> " " Then
Exit Do
End If
Loop
End If

' if any thematic clause was found, display it and exit the loop
If Len(sShadeText) > 0 Then
Print sShadeText
Exit Do
End If
Loop
End Sub

Function GetNextRecord( ByVal sText As String, n As Integer ) As String
' Read the next record in a body of text
Dim m As Integer
Dim sRec As String

m = InStr( n, sText, ""+Chr$(10))
sRec = Mid$( sText, n, (m-n+1))
n = m+1

GetNextRecord = sRec
End Function

Olivier ATHIMON

unread,
Mar 24, 2009, 3:05:43 PM3/24/09
to mapi...@googlegroups.com
Thanks Bill and Maurice34.

I didn't know the use of WIN_INFO_CLONEWINDOW ... But i have understood the answer of Maurice34.

I wrote my routine and your answer complete is arrived, better than my wishes!!! I can do what i want with this. Thanks very much Bill.

To try it, i have just added a line before "CLS":
Open Window Message

;o)) , and thanks very much.

Bill Thoen a écrit :

Ce message entrant est certifié sans virus connu. Analyse effectuée par AVG - www.avg.fr Version: 8.0.238 / Base de données virale: 270.11.25/2019 - Date: 03/23/09 18:51:00

IvanB

unread,
Apr 2, 2009, 2:59:15 AM4/2/09
to MapInfo-L
Using WIN_INFO_CLONEWINDOW is dangerous because it take only ~32000
characters(max string size). If you have big shade part, it will be
cutted. i.e. you need use Save Workspace.
Reply all
Reply to author
Forward
0 new messages