【发布时间】:2012-03-16 20:00:41
【问题描述】:
我想将特定的 ascii 文件转换为 csv。
这个 ascii 文件有自己的规范,我在相关片段下面发布。
A 行以代码 66TP 开头:
66TP 1003 54.437269600149717.012388003107655.5139691177756 :10.008677993245250.01231534739191
B行以C6NM开头:
C6NM0821.565823793411260.900167346000671.2812114953994820.81007696688170033 1679475490.0000000001679475527.0000000001
正如您在上面看到的,各个值没有分开,但它们的区别是
按行中的位置和长度。
A线规格:
1 Position Length Data format Description of field
2 1 2 Type code Record type code = 66
3 3 2 Derivation Derivation code
4 5 16 Name Point name
5 21 16 Latitude Latitude
6 37 16 Longitude Longitude
7 53 16 Distance WGS84 ellipsoidal height at APC
8 69 16 Text 16 Feature code
9 85 1 GPS Method Measurement method
10 86 1 Classification Classification of the point
11 87 16 Distance Horizontal precision
12 103 16 Distance Vertical precision
B线规格:
1 Position Length Data format Description of field
2 1 2 Type code Record type code = C6
3 3 2 Derivation Derivation code
4 5 2 Integer 2 Minimum number of satellites
5 7 1 Boolean Relative DOPs
6 8 16 Scalar PDOP (maximum)
7 24 16 Scalar HDOP (maximum)
8 40 16 Scalar VDOP (maximum)
9 56 16 Scalar RMS
10 72 4 Integer 4 Number of GPS positions used
11 76 16 Distance Horizontal standard deviation
12 92 16 Distance Vertical standard deviation
13 108 4 Integer 4 Start GPS week
14 112 16 Scalar Start GPS time in seconds to 3dp
15 128 4 Integer 4 End GPS Week
16 132 16 Scalar End GPS time in seconds to 3dp
17 148 1 Monitor Status
我想要的输出是合并两行,就像:
1003,54.4372696001497,17.0123880031076,55.5139691177756,0.009,0.012,8,1.6,0.9,1.28,20.8,033,1679,475490.0,1679,475527.0
这是输入文件,我在其中用方括号标记了各个值:
66TP [1003] [54.4372696001497][17.0123880031076][55.5139691177756] :1[0.00867799324525][0.01231534739191]
C6NM[082][1.56582379341126][0.90016734600067][1.28121149539948][20.81007696688170][033] [1679][475490.000000000][1679][475527.0000000001]
抱歉发了很长的帖子,但我不知道如何用更短的方式描述它。
我是一个业余的初学者程序员,我想请你给我任何让我开始的提示
处理此类数据。
【问题讨论】:
-
CSV 输出是由您指定的吗? CSV 将做什么?
-
它将被翻译成html表格作为gps调查报告。
-
那为什么不直接输出HTML呢?
-
因为在此期间我还必须对纬度、经度和高度进行计算,然后将所有内容放在桌面上。由于我不是熟练的程序员,因此检索计算所需的数据并将其转换为 html 对我来说是最简单的方法。
-
那你根本不想输出文本;您只想将数据解析为一些内部数据结构,然后在输出 HTML 之前使用这些数据结构。接受的答案显示了如何做到这一点;你不会得到 csv 输出,而是每行的字符串
list。