我在Python中使用liblas来读取,操作和编写特殊的点格式*.las
。我有一个字符串
s = "309437.95 6959999.84 118.98 16 1 1 0 0 1 0 112.992 5.9881"
第一个是X
,第二个是Y
,第三个元素是Z
等。
使用Liblas,我创建一个空的liblas.point.Point
对象
>>> pt = liblas.point.Point()
>>> pt
<liblas.point.Point object at 0x0000000005194470>
之后,我需要填充此对象,因为它是空的。
>>> pt.x, pt.y,pt.z
(0.0, 0.0, 0.0)
可能正在使用
>>> pt.get_x
<bound method Point.get_x of <liblas.point.Point object at 0x0000000005194470>>
我想感谢所有的帮助和建议,我真的需要解决这一步。
来自Martijn Pieters的建议
s = "%s %s %s" % (s, value, nh)
>>> s
'309437.95 6959999.84 118.98 16 1 1 0 0 1 0 112.992 5.9881'
# create a liblas.point.Point
pt = liblas.point.Point()
pt.x = float(s.split()[0])
pt.y = float(s.split()[1])
pt.z = = float(s.split()[11]) # the new Z value
pt.intensity = = int(s.split()[3])
pt.return_number= int(s.split()[4])
pt.number_of_returns = int(s.split()[5])
pt.scan_direction = int(s.split()[6])
pt.flightline_edge = int(s.split()[7])
pt.classification = int(s.split()[8])
pt.scan_angle = int(s.split()[9])
答案 0 :(得分:1)
Point对象上有raw_x
,raw_y
和raw_z
属性;只需设置:
pt.raw_x = 309437.95
pt.raw_y = 6959999.84
pt.raw_z = 118.98
还有x
,y
和z
属性;从源代码中不能立即清楚这两种类型之间的区别是什么:
pt.x = 309437.95
pt.y = 6959999.84
pt.z = 118.98
但是库可以直接从.las文件中为你生成这些对象,不是吗?您之前遇到过麻烦的File
类肯定会返回这些对象。
自从您更新以显示一些代码后,这里有一个更具可读性的版本:
pt = liblas.point.Point()
s = map(float, s.split())
pt.x, pt.y, pt.z = s[0], s[1], s[11]
pt.intensity, pt.return_number = s[3], s[4]
pt.number_of_returns, pt.scan_direction = s[5], s[6]
pt.flightline_edge, pt.classification = s[7], s[8]
pt.scan_angle = s[9]