mapinfo中如何导出线段起点和终点的经纬度以及长度到文件中
发布网友
发布时间:2023-08-23 20:42
我来回答
共1个回答
热心网友
时间:2024-11-24 19:46
Include "MAPBASIC.DEF"
open window message
Dim sAppPath as String
Dim i,counter As Integer
Dim oLine as Object
Dim geo_length As Float
Dim x1,y1,x2,y2 As Float
sAppPath=ApplicationDirectory$()
Open Table sAppPath+"Untitled.tab" as tab0''''请将文件名修改为你自己的文件名
open file sAppPath+"1.txt" for output as #1 '
i = 0
Fetch First From tab0
Do While Not EOT(tab0)
oLine=ConvertToPline(tab0.obj)
counter = ObjectInfo(oLine, OBJ_INFO_NPNTS)
print "counter:"+counter
geo_length = ObjectLen(oLine, "km")'''''得到线段长度,单位为km,也可以修改为m
x1 = ObjectNodeX(oLine, 1, 1) ' 获取起点经度
x2 = ObjectNodeX(oLine, 1,counter) ' 获取终点经度
y1 = ObjectNodeY(oLine, 1, 1) ' 获取起点纬度
y2 = ObjectNodeY(oLine, 1,counter) ' 获取终点经度
Print #1,geo_length+","+ x1+","+ y1+","+x2+","+ y2 ''''''写入文本1.txt中
i = i + 1
Fetch Next From tab0
loop
close all
请将上面的代码拷贝存为.mb文件后保存在你的.tab文件所在目录,修改一下代码中的文件名,运行后,结果就在同目录下的1.txt中