0

I'm very new to Mapbasic.

I tried to make a short code to draw some BTS in GSM but I can't do thant (over 1 month).

I have a table with these column: Sitename, Lon, Lat, Azi, Beam, Dist.

Can someone help me to correct the code.

Trash=ApplicationDirectory$()+"Sectors.tab"
Create Table Sectors (id Char(10)) file Trash TYPE NATIVE Charset "WindowsLatin1"
Create Map For Sectors CoordSys Earth Projection 1, 0
Map From Sectors
Set Map Layer 1 Editable On 

i=1
Fetch First From Temp
Do While Not EOT (Temp)
  '---Cell 1 ------
  Lon1=Temp.Longitude
  Lat1=Temp.Latitude
  Bearing1=Temp.Azimuth
  Beam1=60
  Dist1=1
  oSite = CreatePoint(Lon1,Lat1)
  oSite2 = OffSet(oSite, Bearing1, Dist1, "m")
  oDirection = CreateLine(Lon1, Lat1, CentroidX(oSite2), CentroidY(oSite2))
  oRotateAtPoint1 = RotateAtPoint (oDirection, (Beam1)/2, oSite)
  oRotateAtPoint2 = RotateAtPoint (oDirection, -1 * (Beam1)/2, oSite)
  'Insert Into Sectors (Obj) Values (oRotateAtPoint1)
  Update Sectors set Obj=oRotateAtPoint1 where rowid = i
  i=i+1
  Fetch Next From Temp
Loop
End If

The result is a white map

  • @Peter If you have time, phease check the code above again. I tried many times but It's not successful. It's still a blank map. Thanks so much. – Thang Jan 22 '15 at 1:30
  • 2
    Welcome to the site. It is best to provide some background into what you have done. Otherwise, posts can come off as "Here's my code--fix it", which is discouraged at GIS Stack Exchange. – Aaron Jan 22 '15 at 1:51
  • @Thang Did you try to zoom to the layer? Also note you are creating very small sectors - only 1 meter in distance. Try to change the Dist1 to 250 – Peter Horsbøll Møller Jan 22 '15 at 7:49
  • @PeterHorsbøllMøller: I have changed the value from 1 to 300, but there is nothing. I don't know what happend for many days, do you need the full code for easyly to check? – Thang Jan 22 '15 at 9:57
  • i have a question please what you mean by "Temp" it's a new table? thank you – mustapha amer Aug 13 '15 at 14:56
1

You are updating records in an empty table. Your table Sectors has no records therefor no records will be affected by your Update Statement.

You need to use the Insert Statement that I can see you already have in your code.

Currrently your code will only insert a single line that shows the one of the sector. In order to create the full sector you need to create a polygon with these coordinates:

Create Region
   Into Variable oSector
   1 
   5
   (Lon1, Lat1)
   (ObjectGeography(oRotateAtPoint1, OBJ_GEO_LINEENDX), ObjectGeography(oRotateAtPoint1, OBJ_GEO_LINEENDY))
   (CentroidX(oSite2), CentroidY(oSite2))
   (ObjectGeography(oRotateAtPoint2, OBJ_GEO_LINEENDX), ObjectGeography(oRotateAtPoint2, OBJ_GEO_LINEENDY))
   (Lon1, Lat1)

And Finally, as I said above, you need to insert this object into the Sector table:

Insert Into Sectors (Obj) Values (oSector)

Here is my full code that is working on my end:

Include "MapBasic.def"

Dim  oSite, oSite2, oDirection, oRotateAtPoint1, oRotateAtPoint2, oSector  As Object,
     Beam1, HalfBeam1, Bearing1, Dist1, Lon1, Lat1 As Float,
     Trash As String

Trash=ApplicationDirectory$()+"Sectors.tab"
Create Table Sectors (id Char(10))
     File Trash
     TYPE NATIVE Charset "WindowsLatin1"
Create Map
     For Sectors
     CoordSys Earth Projection 1, 0
Set CoordSys Table Sectors

Map From Sectors
Set Map Layer 1 Editable On

Fetch First From Temp
Do While Not EOT (Temp)
     '---Cell 1 ------
     Lon1      = Temp.Longitude
     Lat1      = Temp.Latitude
     Bearing1  = Temp.Azimuth

     Beam1     = 60
     HalfBeam1 = Beam1 / 2
     Dist1     = 250

     oSite     = CreatePoint(Lon1,Lat1)
     oSite2    = OffSet(oSite, Bearing1, Dist1, "m")

     oDirection      = CreateLine(Lon1, Lat1, CentroidX(oSite2), CentroidY(oSite2))
     oRotateAtPoint1 = RotateAtPoint(oDirection, HalfBeam1, oSite)
     oRotateAtPoint2 = RotateAtPoint(oDirection, (360 - HalfBeam1), oSite)

     Create Region
        Into Variable oSector
        1
        5
        (Lon1, Lat1)
        (ObjectGeography(oRotateAtPoint1, OBJ_GEO_LINEENDX), ObjectGeography(oRotateAtPoint1, OBJ_GEO_LINEENDY))
        (CentroidX(oSite2), CentroidY(oSite2))
        (ObjectGeography(oRotateAtPoint2, OBJ_GEO_LINEENDX), ObjectGeography(oRotateAtPoint2, OBJ_GEO_LINEENDY))
        (Lon1, Lat1)

     Insert Into Sectors (Obj) Values (oSector)

     Fetch Next From Temp
Loop

Set Map
     Zoom Entire Layer Sectors
  • Great, great Peter. I just change the line "-1..." by (360-...) as what you did. It's OK. The temp table is only contain: long, lat, azimuth, Beam. – Thang Jan 24 '15 at 12:24
  • Great, great Peter. I just change the line "-1..." by (360-...) as what you did. It's OK. The temp table is only contain: long, lat, azimuth, Beam. The forum forbid to say Thank but I really want to do that Peter. A very very small problem is how to change the shape of a sector from triangle to Pie? – Thang Jan 24 '15 at 12:30
  • I think you should create a new question discussing how to create the sectors as a pie – Peter Horsbøll Møller Jan 24 '15 at 19:50
  • Or have a look at this questions: gis.stackexchange.com/questions/121582/… – Peter Horsbøll Møller Jan 27 '15 at 7:23
  • OK Peter, I think the shape of a sector is not important. But I would like you to check the angle. In normal, 0 degree is the same with x asis, 90 degree is same with y asis (anti clockwise). But here 0 degree is same with y asis, 90 degree is same with x asis (clock wise). – Thang Jan 29 '15 at 2:05
1

I compiled and run the mbx but mapinfo gave me a error code "Table Temp not found"

I think you should add into the Temp table first

the same issue if you have the solution give it to me please

  • Great, great Peter – Thang Jan 24 '15 at 12:23

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.