PyLidar

Introduction

A set of Python modules which makes it easy to write lidar processing code in Python. Based on SPDLib and built on top of RIOS it handles the details of opening and closing files, checking alignment of projection and grid, stepping through the data in small blocks, etc., allowing the programmer to concentrate on the processing involved. It is licensed under GPL 3.

See SPD V4 Format Description for description of the SPD V4 file format. Supported formats are: SPD V3, SPD V4, Riegl RXP, LAS, LVIS, ASCII and Pulsewaves (additional libraries may be required).

See the How to Visualise Arrays page to understand how numpy arrays are used in PyLidar.

Work funded by DSITI and OEH through the Joint Remote Sensing Research Program.

There is a Google Group where users can post questions.

Example

"""
Creates a Raster output file from the minimum 'Z' values of
the points in each bin
"""
import numpy
from numba import jit
from pylidar import lidarprocessor
from pylidar.toolbox import spatial
from pylidar.lidarformats import generic

BINSIZE = 1.0

@jit
def findMinZs(data, outImage, xMin, yMax):
    for i in range(data.shape[0]):
        if data[i]['CLASSIFICATION'] == lidarprocessor.CLASSIFICATION_GROUND:
            row, col = spatial.xyToRowColNumba(data[i]['X'], data[i]['Y'],
                    xMin, yMax, BINSIZE)
            if outImage[row, col] != 0:
                if data[i]['Z'] < outImage[row, col]:
                    outImage[row, col] = data[i]['Z']
            else:
                outImage[row, col] = data[i]['Z']

def processChunk(data, otherArgs):
    data = data.input1.getPoints(colNames=['X', 'Y', 'Z', 'CLASSIFICATION'])
    findMinZs(data, otherArgs.outImage, otherArgs.xMin, otherArgs.yMax)

info = generic.getLidarFileInfo(inFile)
header = info.header

dataFiles = lidarprocessor.DataFiles()
dataFiles.input1 = lidarprocessor.LidarFile(inFile, lidarprocessor.READ)

xMin, yMax, ncols, nrows = spatial.getGridInfoFromHeader(header, BINSIZE)

outImage = numpy.zeros((nrows, ncols))

otherArgs = lidarprocessor.OtherArgs()
otherArgs.outImage = outImage
otherArgs.xMin = xMin
otherArgs.yMax = yMax

lidarprocessor.doProcessing(processChunk, dataFiles, otherArgs=otherArgs)

iw = spatial.ImageWriter(outFile, tlx=xMin, tly=yMax, binSize=BINSIZE)
iw.setLayer(outImage)
iw.close()

See Processor Examples for more information. Command Line Examples has more information on running the command line utilities.

_images/pylidar.jpg

Downloads

Source

Source code is available from BitBucket. RIOS, Numba, Numpy and h5py are required dependencies. Additional formats require environment variables set to the root installation of other libraries before building as detailed in this table:

Type of Files Environment Variable(s) Link to Software
LAS/LAZ LASTOOLS_ROOT lastools
Riegl RIVLIB_ROOT, RIWAVELIB_ROOT RiVLIB RiWaveLIB
ASCII .gz ZLIB_ROOT zlib
PulseWaves PULSEWAVES_ROOT pulsewaves

The related pynninterp module is used for some interpolation operations.

Test Suite

After installation, run pylidar_test to run a number of tests to check that the install is OK. You will need the latest testdata_X.tar.gz file (with the highest ‘X’) from the downloads area. Pass the path to this file to pylidar_test with -i option.

Conda

Conda packages are available under the ‘rios’ channel. Once you have installed Conda, run the following commands on the command line to install pylidar (dependencies are obtained automatically):

conda config --add channels conda-forge
conda config --add channels rios
conda create -n myenv pylidar
source activate myenv # omit 'source' on Windows

The related pynninterp module is used for some interpolation operations and can be installed via Conda also from the ‘rios’ channel:

conda install pynninterp

Testing

Indices and tables