2

I am new to MapBasic and i need to learn to create the cells of a site in MapInfo using the MapBasic.

i Used the below script i found in the Web, and it was for only single site I made automated it to do from xls table, but it still very slow for only 500 record,

and there is other issue, I don't know how to attach the table records for each sector to the plotted object so i can see the site information using the Info tool in MapInfo

and i wanted the sector length and the Pen & brush to be depending on specific record on the table

SUB CreatePie(x as Float,y as Float,Brg as float,Ang as float,Dst as float,aBrush as brush,aPen as Pen)
dim sAng as float
dim eAng as float
dim Cntr as integer
dim NewArc as Object
dim Pnts as integer
dim IncVal as float
dim rTemp as float
dim DMS as float
dim aRow as float
dim cnvt as float 

  Set ProgressBars OFF
  '>>>> SET DISTANCE UNIT TO uDIST > "mi" "km" "m" "ft"
  Set Distance Units "km"
  Set Map Distance Units "km"
    Set Map Area Units "sq km" 





  DO CASE uDist
    CASE "km"
      cnvt=1
    CASE "mi"
      cnvt=1.609344
    case "m"
      cnvt=0.001
    case "ft"
      cnvt=0.000305
  END CASE
  Dst=Dst*cnvt
'note dst+" "+uDist

  '>>>> CREATE A TEMP TABLE TO BUILD OBJECTS <<<<
  Trash=ApplicationDirectory$()+"temp.tab"
  Create Table Temp (id Char(10)) file Trash TYPE NATIVE Charset "WindowsLatin1"
  Create Map For temp CoordSys Earth Projection 1, 0



  if Ang=-1  then ''' OMNI-DIRECTIONAL
    aObj=CreateCircle(x,y,Dst)
    Alter Object aObj Info Obj_Info_Brush , aBrush
    Alter Object aObj Info Obj_Info_Pen , aPen
    insert into Cosmetic1 (Obj) Values (aObj)
    exit sub
  else
    sAng=brg-(Ang/2)
    eAng=Brg+(Ang/2)
  end if

  while sAng<0 
   sAng=sAng+360
  wend
  while sAng>360
    sAng=sAng-360
  wend
  while eAng<0
    eAng=eAng+360
  wend
  while eAng>360
    eAng=eAng-360
  wend
  Pnts=Fix(Ang)


  if Pnts=0 then

    NOTE "CAN NOT HAVE '0' BeamWidth [points]"
    exit sub
  End IF
  IncVal=Ang/Pnts
  rTemp=0
  DMS=sAng

  Call CalcLine(x,y,sAng,Dst)
  insert into Temp (obj) values (aobj)
  Create PLine into Variable NewArc 0
  Alter Object NewArc NODE Add (sx ,sy)
  DMS=DMS+IncVal
  do
    Call CalcLine(x,y,DMS,Dst)
    Alter Object NewArc NODE Add (sx ,sy)
    rTemp=rTemp+IncVal
    DMS=DMS+IncVal
  Loop Until rTemp>=Ang
  insert into Temp (obj) values (NewArc)
  Create Line into variable aObj (x,y) (sx,sy)
  insert into Temp (obj) values (aObj)
  select * from Temp into Sel
  Objects Combine
  fetch last from Temp
  aObj=Temp.obj
  aObj=ConvertToRegion(aObj)
  Alter Object aObj Info Obj_Info_Brush , aBrush
  Alter Object aObj Info Obj_Info_Pen , aPen
  insert into CellLayer (Obj) Values (aObj)
  Drop Table Temp
  Set ProgressBars ON


END SUB

'=====================================================================================================================

SUB CalcLine(cx as float, cy as Float, degree as float, fLength as float)

  define DegDist 111.3216 '' Km a zero lat per lon
  define deg2Rad 0.01745329252
  define rad2deg 57.29577951

dim x, y as Float

  while Degree>360  ''' make bearing 0 to 359.999999999------
    Degree=Degree-360
  wend
  while Degree<0
    Degree=Degree+360
  wend
  if Degree=0 or Degree=360 then
    Y = CY + ( ( (cos(Degree * Deg2Rad) * fLength)  / DegDist ) )
    X = CX
  elseif (Degree > 0) and (Degree < 90) then
    Y = CY + ( ( (cos(Degree * Deg2Rad) * fLength)  / DegDist ) )
    X = CX + ( ( (sin(Degree * Deg2Rad) * fLength)  /(DegDist * cos(cy*Deg2Rad))) )
  elseif (Degree = 90) then
    Y = CY 
    X = CX + ( ( (sin(Degree * Deg2Rad) * fLength)  /(DegDist * cos(cy*Deg2Rad))) )
  elseif (Degree > 90) and (Degree < 180) then
    Y = CY + ( ( (cos(Degree * Deg2Rad) * fLength)  / DegDist ) )
    X = CX + ( ( (sin(Degree * Deg2Rad) * fLength)  /(DegDist * cos(cy*Deg2Rad))) )
  elseif (Degree = 180) then
    Y = CY + ( ( (cos(Degree * Deg2Rad) * fLength)  / DegDist ) )
    X = CX
  elseif (Degree > 180) and (Degree < 270) then
    Y = CY + ( ( (cos(Degree * Deg2Rad) * fLength)  / DegDist ))
    X = CX + ( ( (sin(Degree * Deg2Rad) * fLength)  /(DegDist * cos(cy*Deg2Rad))) )
  elseif (Degree = 270) then
    Y = CY
    X = CX + ( ( (sin(Degree * Deg2Rad) * fLength)  /(DegDist * cos(cy*Deg2Rad))) )
  elseif (Degree > 270) and (Degree < 360) then
    Y = CY + ( ( (cos(Degree * Deg2Rad) * fLength)  / DegDist ) )
    X = CX + ( ( (sin(Degree * Deg2Rad) * fLength)  /(DegDist * cos(cy*Deg2Rad))) )
  end if

  aObj=CreateLine(cx,cy,x,y)
  sx=x
  sy=y
END SUB
===================================================================
  • Could you include more detail on what you want to achieve? Also, include what you have tried already and/or what information you have found regarding this issue. Please use the edit button below your question to update it. – Martin May 26 '14 at 12:51
3

This is not a fully workable solution but it will give you some ideas on how to get your task done using MapBasic.

Initially I assume that you'll have:

  • X
  • Y
  • Angle
  • Opening angle
  • Sector Length

Using these values you can create:

  • Site position

oSite = CreatePoint(X, Y)

  • Site Direction Point

oSite2 = OffSet(oSite, Angle, Sector Length, "m")

  • Site Direction

oDirection = CreateLine(X, Y, CentroidX(oSite2), CentroidY(oSite2))

  • Site Width

RotateAtPoint(oDirection, (Opening Angle)/2, oSite)

RotateAtPoint(oDirection, -1 * (Opening Angle)/2, oSite)

You should now also be able to create actual site coverage by extracting the coordinates from the resultsets above

  • Thank you Peter That helped me and done more than 27,000 record by 17 sec, after it was takes 110 seconds for only 2,000 – RF_Eng Jun 10 '14 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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