Different Brush color to different region/polygon using MapBasic

509 views
Skip to first unread message

Blitz79!

unread,
May 11, 2012, 5:23:44 PM5/11/12
to mapi...@googlegroups.com
Hi All,

I am Newbie to this group and MapInfo too...i have started using MapInfo for my work involving RF Planning. 
Coming to my requirement to solve one particular problem ===>

Objective: I have created a .TAB of GSM sites with their BSC_ID and Lat,Long. I need to create BSC boundaries for these sites and fill each region/polygon made by boundaries using different Fill color.

Work done: Using Voronoi menu i could create some polygons which look like area bordered by the sites with their adjacent. Then i performed Query to select individual BSC sites and used Combine option to create a single polygon of all the sites by using the option average which leaves the final value of BSC same.

To be done: Now i want to Fill each region with different colour. I tried to run a loop for each entry in the final TAB containing the BSC boundaries. But i am making a mistake in the procedure to update the BRUSH values etc.. So, if anyone has already tried this or knows a solution for this...i would be obliged.

Considerations: The Number of BSC = 80. The headers of the database is BSC_ID (containing numbers 1...80) ; Sitename; Longitude; Latitude.

Thank you in advance.

Ahmet DABANLI

unread,
May 14, 2012, 4:18:22 AM5/14/12
to mapi...@googlegroups.com
Dear Blitz,
for updating you should follow


dim BrshStyles() as string

Declare Sub PrepStyles

dim o as object
dim k,i as integer
dim b_fillstyle as brush
Select * from TABLENAME where obj into sel1 noselect
Call PrepStyles

For k = 1 to tableinfo(sel1,8)
fetch rec k from sel1
o =sel1.obj
i = rnd(1) * (ubound(brshStyles)-1) +1
run command "set style brush make"+brshStyles(i)
b_fillstyle = currentbrush()

alter object o info 2, b_fillstyle
ChangeBrushColor=o
update sel1 set obj = o where rowid = k
Next


sub PrepStyles ' some defined brushes

k = 0
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,10526975,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,11599792,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,11599832,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,11599871,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,11796288,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,12637695,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,13684991,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,13689087,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,13696976,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,13697023,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,14201087,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,14745520,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,15257855,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,15597520,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,16744703,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,16754768,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,16756952,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,16756991,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,16764992,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,16765136,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,16765183,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,16767152,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,16771280,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,16772272,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,16776960,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,16777136,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,16777168,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,7405496,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,9493503,16777215)"
k=k+1 redim BrshStyles(k) BrshStyles(k) = "Brush (2,9502608,16777215)"
end sub


Do you need 80 different colors?
you may need to randomize the colors and
then easy way can be:

Declare Function ChangeBrushColor(byval o as object) as object
update TABLENAME set obj = ChangeBrushColor(obj)

Function ChangeBrushColor(byval o as object) as object
dim r,g,b as integer
dim rgbi as integer
dim b_fillstyle as brush

r = rnd(1) *255
g = rnd(1) *255
b = rnd(1) *255
rgbi = RGB(r,g,b)
b_fillstyle = brush(2,rgbi,16777215)
alter object o info 2, b_fillstyle
ChangeBrushColor=o
End function


best regards
> --
> You received this message because you are subscribed to the
> Google Groups "MapInfo-L" group.To post a message to this group, send
> email to mapi...@googlegroups.com
> To unsubscribe from this group, go to:
> http://groups.google.com/group/mapinfo-l/subscribe?hl=en
> For more options, information and links to MapInfo resources (searching
> archives, feature requests, to visit our Wiki, visit the Welcome page at
> http://groups.google.com/group/mapinfo-l?hl=en



--
Ahmet DABANLI
Message has been deleted

Blitz79!

unread,
May 14, 2012, 5:41:58 AM5/14/12
to mapi...@googlegroups.com
Dear ozancik,

Thank you so much for the quick response..... i found out after sooooooo many trial and errors..... got it the same way you explained....many thanks

The last thing m stuck up with is after doing all this work...there are so  many query tables... now i want to remove them.... just for user friendliness.... any method to do it....

Regards,
Dinesh.


Ahmet DABANLI

unread,
May 14, 2012, 6:55:56 AM5/14/12
to mapi...@googlegroups.com
I've only one query table, "Sel1"
if you dont put into keyword, they you will have maniac no of queries
select ..... into XXXXXX
and use sam XXXX name for temporary ones
:)
best regards
Reply all
Reply to author
Forward
0 new messages