Kamis, 31 Juli 2014

View Neighbor Dengan Mapbasic

Post yg ini sih intinya mw ngebahas gmn caranya (step2 dan mapbasic code nya) utk menampilkan neighbor baik itu bothway, oneway incoming, dan oneway outgoing, serta undefined neighbor dari suatu cell seperti yg ada di blog saya yg ini. Intinya sih collect data dari table Nbr, trus dibikin deh garis2 relasinya.

Step2nya yg saya ngerti dan saya pke sih gini :
  1. Join table data cell (Data_3G_Cell) dgn Nbr 3G 3G (Nbr_3G3G). Join dilakukan 2x, pertama utk mendapatkan outgoing data (Source Nbr adalah selected object) dan disimpan sementara di qRel1, lalu yg kedua utk mendapatkan incoming data (Target Nbr adalah selected object) dan disimpan sementara di qRel2. Kedua hasil datanya disimpan di table lain, kita kasi nama aja tmpRel.
  2. Looping qRel1 juga qRel2 utk proses pembuatan object antenna dan garis neighbor nya, sesuai dengan style yg sudah kita define.
  3. Create table tmpObj utk object antenna sesuai dgn object yg sudah di compile di Step 2 dan update table tmpRel utk data InOut_Att ambil dari NCell data (SHO_NCell).
  4. Jika Show Undefined = True, maka harus dicari dari table SHO_NCell yg attempt nya tinggi (melebihi threshold) tp tidak ada di tmpRel. Datanya kemudian ditaro di table tmpRel juga.
  5. Final proses penggambaran object antenna dan relasi.
Puyeng yak baca step2 di atas klo pke bahasa sendiri? huehehe.. Mungkin lebih bs ngerti klo liat mapbasic code nya langsung.

Step 1 :
'Outgoing from selected Object
select Source,Target,SHO_Att,RNC_CellID,Longitude,Latitude,Azimuth,"I=xxxxxxxxxxxxx; O=xxxxxxxxxxxxx" "InOut_Att",Data_3G_Cell.Obj "antObj" 
from tmpNbr_3G3G,Data_3G_Cell 
where tmpNbr_3G3G.Source=selObject     'selObject = RNC_CellID object yg diselect dari table Data_3G_Cell
and tmpNbr_3G3G.Target=Data_3G_Cell.RNC_CellID
and Data_3G_Cell.Carrier=sSelectedCarrier     'sSelectedCarrier = carrier dari selObject
into qRel1 noselect

Commit Table qRel1 As myAppDir + "Table\tmpRel.TAB" TYPE NATIVE Charset "WindowsLatin1"
Open Table myAppDir + "Table\tmpRel.TAB" Interactive
sTableRel_tmp = PathToTableName$(myAppDir + "Table\tmpRel.TAB")

'Incoming to selected Object
select Source,Target,SHO_Att,RNC_CellID,Longitude,Latitude,Azimuth,"I=xxxxxxxxxxxxx; O=xxxxxxxxxxxxx" "InOut_Att",Data_3G_Cell.Obj "antObj" 
from tmpNbr_3G3G,Data_3G_Cell 
where tmpNbr_3G3G.Target=selObject     'selObject = RNC_CellID object yg diselect dari table Data_3G_Cell
and tmpNbr_3G3G.Source=Data_3G_Cell.RNC_CellID 
and Data_3G_Cell.Carrier=sSelectedCarrier     'sSelectedCarrier = carrier dari selObject
into qRel2 noselect

Insert Into sTableRel_tmp ( COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8) Select COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8 From qRel2
Commit table sTableRel_tmp

Step 2 :
do while not EOT(qRel1)
inputAnt(iLoop)=qRel1.antObj
ant=inputAnt(iLoop)
sourceId=qRel1.Source
targetId=qRel1.Target
tx=centroidx(ant)
ty=centroidy(ant)

select count(*) from sTableRel_tmp where Source=targetId and Target=sourceId into qBoth noselect
if qBoth.Count > 0 then 'bothway
Create Line into Variable rel (sx,sy) (tx,ty) Pen pPenTargetBoth
antColor=bBrushTargetBoth
else 'outgoing one way
Create Line into Variable rel (sx,sy) (tx,ty) Pen pPenTargetOut
antColor=bBrushTargetOut
end if

close table qBoth
Alter Object inputAnt(iLoop) Info OBJ_INFO_BRUSH, antColor
tmpSourceCell(iLoop)=sourceId
tmpTargetCell(iLoop)=targetId
inputRel(iLoop)=rel
iSelTotalNbr=iSelTotalNbr+1
iLoop=iLoop+1
fetch next from qRel1
loop

do while not EOT(qRel2)
inputAnt(iLoop)=qRel2.antObj
ant=inputAnt(iLoop)
sourceId=qRel2.Source
targetId=qRel2.Target
tx=centroidx(ant)
ty=centroidy(ant)

select count(*) from sTableRel_tmp where Source=targetId and Target=sourceId into qBoth noselect
if qBoth.Count = 0 then
Create Line into Variable rel (sx,sy) (tx,ty) Pen pPenTargetInc
antColor=bBrushTargetInc
Alter Object inputAnt(iLoop) Info OBJ_INFO_BRUSH, antColor
tmpSourceCell(iLoop)=targetId
tmpTargetCell(iLoop)=sourceId
inputRel(iLoop)=rel
iLoop=iLoop+1
end if

close table qBoth
fetch next from qRel2
loop

Step 3 dan 4 :
Create Table tmpObj
(RNC_CellID Char(12))
File myAppDir + "Table\tmpObj.TAB"
Create Map For tmpObj CoordSys Earth
Add Map Window FrontWindow()  Auto Layer tmpObj 

Update sTableRel_tmp Set Obj = CreatePoint(0,0)
Commit table sTableRel_tmp

Set Map Window FrontWindow()  Layer tmpObj Display Off
Set Map Window FrontWindow()  Layer sTableRel_tmp Display Off

for i=1 to (iLoop-1)
insert into tmpObj (RNC_CellID, Obj) values (tmpTargetCell(i),inputAnt(i))

if i > 1 then
select * from sTableRel_tmp where Source=tmpSourceCell(i) and Target=tmpTargetCell(i) into qUpdate noselect
If  TableInfo(qUpdate,8) = 0 Then
close table qUpdate
select * from sTableRel_tmp where Source=tmpTargetCell(i) and Target=tmpSourceCell(i) into qUpdate noselect
end if

update qUpdate set Obj=inputRel(i)
close table qUpdate
end if
next

Commit table sTableRel_tmp
Commit table tmpObj
select * from SHO_NCell where Source=selObject into qNCell1 noselect
select * from SHO_NCell where Target=selObject into qNCell2 noselect

Commit Table qNCell1 As myAppDir + "Table\tmpNCell.TAB" TYPE NATIVE Charset "WindowsLatin1"
Open Table myAppDir + "Table\tmpNCell.TAB" Interactive
sTableNCell_tmp = PathToTableName$(myAppDir + "Table\tmpNCell.TAB")
Insert Into sTableNCell_tmp ( COL1, COL2, COL3) Select COL1, COL2, COL3 From qNCell2
Commit table sTableNCell_tmp

if iShowUndefined=1 then
'alter table add ismatched column
alter table sTableNCell_tmp (add isMatched integer)
commit table sTableNCell_tmp
update sTableNCell_tmp set isMatched=0
commit table sTableNCell_tmp

select * from tmpNCell,tmpRel where tmpNCell.Source=tmpRel.Source and tmpNCell.Target=tmpRel.Target into qUpdate noselect
update qUpdate set isMatched=1
commit table sTableNCell_tmp
close table qUpdate

select * from tmpNCell,tmpRel where tmpNCell.Source=tmpRel.Target and tmpNCell.Target=tmpRel.Source into qUpdate noselect
update qUpdate set isMatched=1
commit table sTableNCell_tmp
close table qUpdate

if sCarrierTarget3G="" then
select Source,Target,SHO_Att,RNC_CellID,Longitude,Latitude,Azimuth,"I=xxxxxxxxxxxxx; O=xxxxxxxxxxxxx" "InOut_Att",Data_3G_Cell.Obj "antObj" 
from tmpNCell,Data_3G_Cell 
where tmpNCell.Source=selObject
and tmpNCell.Target=Data_3G_Cell.RNC_CellID 
and tmpNCell.SHO_Att > fUndefinedAtt 
and tmpNCell.IsMatched=0 
and Data_3G_Cell.Carrier=sSelectedCarrier 
into qUndefinedObj noselect
else
select Source,Target,SHO_Att,RNC_CellID,Longitude,Latitude,Azimuth,"I=xxxxxxxxxxxxx; O=xxxxxxxxxxxxx" "InOut_Att",Data_3G_Cell.Obj "antObj" 
from tmpNCell,Data_3G_Cell 
where tmpNCell.Source=selObject
and tmpNCell.Target=Data_3G_Cell.RNC_CellID 
and tmpNCell.SHO_Att > fUndefinedAtt 
and tmpNCell.IsMatched=0 
and Data_3G_Cell.Carrier=sCarrierTarget3G 
into qUndefinedObj noselect
end if

Insert Into sTableRel_tmp ( COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8) Select COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8 From qUndefinedObj
commit table sTableRel_tmp

fetch first from qUndefinedObj
do while not EOT(qUndefinedObj)
undefinedAnt=qUndefinedObj.antObj
undefinedSCell=qUndefinedObj.Source
undefinedTCell=qUndefinedObj.Target
Alter Object undefinedAnt Info OBJ_INFO_BRUSH, bBrushUndefined
insert into tmpObj (RNC_CellID, Obj) values (undefinedTCell,undefinedAnt)

tx=centroidx(undefinedAnt)
ty=centroidy(undefinedAnt)
Create Line into Variable rel (sx,sy) (tx,ty) Pen pPenUndefined

select * from sTableRel_tmp where Source=undefinedSCell and Target=undefinedTCell into qUpdate noselect
update qUpdate set Obj=rel
close table qUpdate
fetch next from qUndefinedObj
loop

commit table tmpObj
commit table sTableRel_tmp
Close Table qUndefinedObj
end if

'loop table sTableRel_tmp to update InOut_Att
select * from sTableRel_tmp into qLoopRel noselect
fetch first from qLoopRel
do while not EOT(qLoopRel)
NCellSource=qLoopRel.Source
NCellTarget=qLoopRel.Target

'in
select * from sTableNCell_tmp where Source=NCellTarget and Target=NCellSource into qIN noselect
NCellIn="In=" + qIN.SHO_Att

'out
select * from sTableNCell_tmp where Source=NCellSource and Target=NCellTarget into qOUT noselect
NCellOut="Out=" + qOut.SHO_Att

NCellInOut=NCellIn + " ; " + NCellOut

select * from sTableRel_tmp where Source=NCellSource and Target=NCellTarget into qUpdateRel noselect
update qUpdateRel set InOut_Att=NCellInOut
close table qUpdateRel
fetch next from qLoopRel
loop

commit table sTableRel_tmp

Step 5 :
Set Map Window FrontWindow()  Layer tmpObj Display Graphic
Set Map Window FrontWindow()  Layer sTableRel_tmp Display Graphic

Set Map Window FrontWindow()  Layer sTableRel_tmp Label Font ("Arial",256,9,255,16777215) With InOut_Att
Set Map Window FrontWindow()  Layer sTableRel_tmp Label Auto On

Untuk Nbr 3G ke 2G dan Nbr 2G ke 2G jg sama pke step2 di atas, cuma nama table data cell, Nbr, dan NCell nya aja yg di ganti. Mudah2an abis liat mapbasic code utk view Nbr dari step 1 ampe step 5 di atas ga tambah puyeng yak :))))

1 komentar: