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
Answer
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
No comments:
Post a Comment