这是我写的一个mapbasic软件的一段代码,希望对大家有所帮助。这段代码并没有在mapinfo中画线,但是知道了两个端点,我我相信大家都知道该怎么做了:)
'*****************************************************************************
'Program Name: Export TEMS .Cel File
'Author: Liu Hui
'Date: 18/03/2004
'Description:The sub program will export some specifically information into
' a text file.
'
'
'*****************************************************************************
include "mapbasic.def"
Global x2,y2 as float
Global x1,y1 as float
Global angle,length as float
declare sub getendpoint
Declare sub main
'The sub program will create a tool bar in mapinfo window
'
'Sub CreateToolBar
'end sub
sub main
dim i as integer
dim sec as string
dim s as string
dim NumTbls as integer
dim fnei,ffre as logical
dim flagnei,flagfre as logical
NumTbls=Numtables()
fnei=false
ffre=false
'Check whether not the "neighbor" table and "Frequency" table exist
for i=1 to NumTbls
if tableinfo(i,TAB_INFO_NAME)="Frequency" then 'ffre=true if "frequency" table exist
ffre=true
end if
if tableinfo(i,Tab_info_name)="neighbor" then 'fnei=true if "Neighbor" table exist
fnei=true
end if
next
if not fnei then
flagnei=Ask("Neighbor table not exist,you want to export any way?","Yes","No")
if not flagnei then
exit sub
end if
end if
if not ffre then
flagfre=Ask("Frequency table not exist,you want to export any way?","Yes","No")
if not flagfre then
exit sub
end if
end if
i=1
fetch rec 20 from setup
length=setup.pathorvalue
Open File "c:\temp.cel" for output as #1 '输出这这里你也可以用mapbasic中的savefile函数指定一个路径作为输出
length=(length/100)/2
fetch rec 1 from frequency
do while not eot(frequency)
fetch rec i from frequency
x1=frequency.Easting '读取精度
y1=frequency.Northing '读取纬度
sec=frequency.sectorid '专用项
angle=frequency.antalign '方向角
call getendpoint '呼叫getendpoint函数算出线的另一端点
s=Sec & " " & Str$(X2) & " " & Str$(y2)
print #1,S '输出数据到文件
i=i+1
loop
close file #1
end sub
Sub GetEndpoint '这是一个很有用的函数,可以根据一个点和一个角度值算出现的另一个端点,并且可以修正不同方向上线长的误差
Dim delta_x, delta_y, midpoint_y, error_margin As Float
dim iterations as smallint
iterations=5 '这是一个长量,表示进行5次误差修正,你也可以改大这个值,这样会更精确一些。
Dim iCounter As Smallint
If angle <= 90 Then '在这里是修正方向角,想知道他的作用?删除这个if试试就知道了
angle = 90 - angle
ElseIf angle <= 450 Then
angle = 450 - angle
End If
If length = 0 Then
x2 = x1
y2 = y1
Exit Sub
End If
delta_y = (length * Sin( angle * DEG_2_RAD )) / 69.093
y2 = y1 + delta_y
midpoint_y = (y1 + y2) / 2
delta_x = (length * Cos(angle * DEG_2_RAD)) / (69.093 * Cos(midpoint_y * DEG_2_RAD))
x2 = x1 + delta_x
iCounter = 1
Do While iCounter <= Abs(iterations)
error_margin = (Distance(x1, y1, x2, y2, "mi" )- length) / length
delta_x = delta_x * (1 - error_margin)
delta_y = delta_y * (1 - error_margin)
x2 = x1 + delta_x
y2 = y1 + delta_y
iCounter = iCounter + 1
Loop
End Sub