【问题标题】:Floating point round off in libLAS Python APIlibLAS Python API 中的浮点舍入
【发布时间】:2014-04-17 14:33:11
【问题描述】:

我正在尝试使用libLAS Python API 将点数据集写入*.las 文件。但是我遇到了一些浮点值被四舍五入的问题

>>> from liblas import point
>>> pt=point.Point()
>>> pt.x=2.323
>>> pt.x
2.0
>>>

如果我设置pt.raw_x 而不是pt.x,我看不到四舍五入的问题,但没有写入las 文件。

>>> pt.raw_x=2.323
>>> pt.raw_x
2.323

我不确定我错过了什么。我将不胜感激。

【问题讨论】:

    标签: python lidar liblas


    【解决方案1】:

    通过mloskot 的一些指针,我找到了解决问题的方法。为了将来的参考和其他libLAS 新手的利益,我在我写的一个小测试代码下面发布。它使用来自libLAS website 的示例las 文件srs.las,修改z 值并将其写入新的las 文件。

    #!/usr/bin/python
    import os,string,glob,re,gdal,sys
    from liblas import file
    from liblas import header
    from liblas import point
    from datetime import datetime
    
    hout=header.Header()
    
    # Define the las file name
    infile="srs.las"
    
    # Create the output las filename
    inarr=infile.split('.')
    outfil=inarr[0]+"_newnorm.las"
    
    # Open the input las file
    l=file.File(infile,mode='r')
    
    # Get the header information
    hin=l.header
    
    # Now let's copy some of the header information from infile to outfile
    hout.major_version = hin.major_version
    hout.minor_version = hin.minor_version
    hout.guid = hin.guid
    hout.system_id = hin.system_id
    hout.software_id = "libLAS Python API"
    date = datetime(2014,03,17)
    hout.date = date 
    hout.offset = hin.offset
    hout.scale = hin.scale
    hout.compressed = hin.compressed
    hout.count = hin.count
    hout.data_format_id = hin.data_format_id
    hout.dataformat_id = hin.dataformat_id
    hout.data_offset = hin.data_offset
    hout.point_return_count = hin.point_return_count
    hout.srs = hin.srs
    hout.version = hin.version
    hout.min = hin.min
    hout.max = hin.max
    
    print "Number of points: "+str(len(l))
    
    lout=file.File(outfil,mode='w',header=hout)
    for p in l:
        x=float(p.x)
        y=float(p.y)
        z=float(p.z)
    
        # Modify z value
        znorm = z-1
    
        pt=point.Point()
        pt.set_header(hout)
    
        pt.x=float(p.x)
        pt.y=float(p.y)
        pt.z=float(znorm)
    
        pt.intensity = p.intensity
        pt.number_of_returns = pt.number_of_returns
        pt.point_source_id = p.point_source_id
        pt.raw_time = p.raw_time
        pt.return_number = p.return_number
        pt.scan_angle = p.scan_angle
        pt.scan_direction = p.scan_direction
        pt.scan_flags = p.scan_flags
        pt.classification = p.classification
        pt.color = p.color
        pt.flightline_edge = p.flightline_edge
    
        print "Writing  to output las file"
        lout.write(pt)
    
    l.close()
    lout.close()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-17
      • 2022-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多