las

Driver for .las files. Uses lastools (https://github.com/LAStools/LAStools).

Read Driver Options

These are contained in the READSUPPORTEDOPTIONS module level variable.

Name Use
BUILD_PULSES a boolean. If set to true (the default) pylidar attempts to build pulses assuming that data is in time sequential order. If false, a ‘fake’ pulse is created for each point.
BIN_SIZE A number. For files with a spatial index present this is the bin size that the File be presented at. Las indexes can use any arbitary bin size it seems, but works to specific ones which can be set with this option for this file. An error will be raised if a spatial read is attempted and this hasn’t been set.
PULSE_INDEX Either FIRST_RETURN or LAST_RETURN Dictates which point will be used to set the X_IDX and Y_IDX pulse fields

Write Driver Options

These are contained in the WRITESUPPORTEDOPTIONS module level variable.

Name Use
FORMAT_VERSION LAS point format. Defaults to 1. Not sure what it means.
RECORD_LENGTH LAS record length. Defaults to 28. Not sure what it means.
WAVEFORM_DESCR Data returned from getWavePacketDescriptions() which does an initial run through the data to get the unique waveform info for writing to the LAS header. No output waveforms are written if this is not provided.

Note that for writing, the extension currently controls the format witten:

Extension Format
.las LAS
.laz LAZ (compressed las)
.bin terrasolid
.qi QFIT
.wrl VRML
other ASCII
pylidar.lidarformats.las.DEFAULT_HEADER = {'FILE_CREATION_DAY': 193, 'FILE_CREATION_YEAR': 2022, 'GENERATING_SOFTWARE': 'PyLidar 0.4.4'}

for new files

pylidar.lidarformats.las.FIRST_RETURN = None

for indexing pulses

pylidar.lidarformats.las.HEADER_TRANSLATION_DICT = {1: 'NUMBER_OF_POINT_RECORDS'}

Non standard header names

pylidar.lidarformats.las.LAST_RETURN = None

for indexing pulses

pylidar.lidarformats.las.LAS_SIMPLEGRID_COUNT_DTYPE

alias of numpy.uint32

pylidar.lidarformats.las.LAS_SIMPLEGRID_INDEX_DTYPE

alias of numpy.uint64

pylidar.lidarformats.las.LAS_WAVEFORM_TABLE_FIELDS = []

for building waveforms - need to build unique table of these

class pylidar.lidarformats.las.LasFile(fname, mode, controls, userClass)[source]

Reader/Writer for .las files.

close()[source]

Write any updated spatial index and close any file handles.

static getDriverName()[source]
getHeader()[source]

Return the Las header as a dictionary.

static getHeaderTranslationDict()[source]

Return dictionary with non-standard header names

getHeaderValue(name)[source]

Just extract the one value and return it

getNativeDataType(colName, arrayType)[source]

Return the native dtype (numpy.int16 etc)that a column is stored as internally after scaling is applied. Provided so scaling can be adjusted when translating between formats.

arrayType is one of the lidarprocessor.ARRAY_TYPE_* constants

getPixelGrid()[source]

Return the PixelGridDefn for this file

getScaling(colName, arrayType)[source]

Returns the scaling (gain, offset) for the given column name reads from our cache since only written to file on close

Raises generic.LiDARArrayColumnError if no scaling (yet) set for this column.

getScalingColumns(arrayType)[source]

Return the list of columns that need scaling. Only valid on write

getTotalNumberPulses()[source]

If BUILD_PULSES == False then the number of pulses will equal the number of points and we can return that. Otherwise we have no idea how many so we raise an exception to flag that.

static getWktFromEPSG(epsg)[source]

Gets the WKT from a given EPSG via GDAL.

hasSpatialIndex()[source]

Returns True if the las file has an associated spatial index.

readData(extent=None)[source]

Internal method. Just reads into the self.last* fields

readPointsByPulse(colNames=None)[source]

Read a 2d structured masked array containing the points for each pulse.

readPointsForExtent(colNames=None)[source]

Read all the points within the given extent as 1d structured array. The names of the fields in this array will be defined by the driver.

colNames can be a name or list of column names to return. By default all columns are returned.

readPointsForExtentByBins(extent=None, colNames=None, indexByPulse=False, returnPulseIndex=False)[source]

Read all the points within the given extent as a 3d structured masked array to match the block/bins being used.

The extent/binning for the read data can be overriden by passing in a Extent instance.

colNames can be a name or list of column names to return. By default all columns are returned.

Pass indexByPulse=True to bin the points by the locations of the pulses
instead of the points.
Pass returnPulseIndex=True to also return a masked 3d array of
the indices into the 1d pulse array (as returned by readPulsesForExtent())
readPointsForRange(colNames=None)[source]

Reads the points for the current range. Returns a 1d array.

Returns an empty array if range is outside of the current file.

colNames can be a list of column names to return. By default all columns are returned.

readPulsesForExtent(colNames=None)[source]

Read all the pulses within the given extent as 1d structured array. The names of the fields in this array will be defined by the driver.

colNames can be a name or list of column names to return. By default all columns are returned.

readPulsesForExtentByBins(extent=None, colNames=None)[source]

Read all the pulses within the given extent as a 3d structured masked array to match the block/bins being used.

The extent/binning for the read data can be overriden by passing in a Extent instance.

colNames can be a name or list of column names to return. By default all columns are returned.

readPulsesForRange(colNames=None)[source]

Reads the pulses for the current range. Returns a 1d array.

Returns an empty array if range is outside of the current file.

colNames can be a list of column names to return. By default all columns are returned.

readReceived()[source]

Read the received waveform for all pulses returns a 2d masked array

readTransmitted()[source]

las (AFAIK) doesn’t support transmitted

readWaveformInfo()[source]

2d structured masked array containing information about the waveforms.

setExtent(extent)[source]

Set the extent for reading for the ForExtent() functions.

setHeader(newHeaderDict)[source]

Update our cached dictionary

setHeaderValue(name, value)[source]

Just update one value in the header

setNativeDataType(colName, arrayType, dtype)[source]

Set the native dtype (numpy.int16 etc)that a column is stored as internally after scaling (if any) is applied.

arrayType is one of the lidarprocessor.ARRAY_TYPE_* constants

generic.LiDARArrayColumnError is raised if this cannot be set for the format.

The default behaviour is to create new columns in the correct type for the format, or if they are optional, in the same type as the input array.

setPixelGrid(pixGrid)[source]

Set the PixelGridDefn for the reading or writing. We don’t need to do much here apart from record the EPSG since LAS doesn’t use a grid.

setPulseRange(pulseRange)[source]

Sets the PulseRange object to use for non spatial reads/writes.

setScaling(colName, arrayType, gain, offset)[source]

Set the scaling for the given column name. Currently scaling is only supported for X, Y and Z columns for points, or optional fields.

writeData(pulses=None, points=None, transmitted=None, received=None, waveformInfo=None)[source]

This driver does not support writing so ignore if reading, throw and error otherwise.

class pylidar.lidarformats.las.LasFileInfo(fname)[source]

Class that gets information about a .las file and makes it available as fields.

static getDriverName()[source]
static getHeaderTranslationDict()[source]

Return dictionary with non-standard header names

pylidar.lidarformats.las.READSUPPORTEDOPTIONS = None

driver options

pylidar.lidarformats.las.WRITESUPPORTEDOPTIONS = None

driver options

pylidar.lidarformats.las.gatherWavePackets(data, otherArgs)[source]

Called from lidarprocessor, is the function that does the identification of unique waveform length and gain and offset.

pylidar.lidarformats.las.getWavePacketDescriptions(fname)[source]

When writing a LAS file, it is necessary to write information to a table in the header that really belongs to the waveforms. This function reads the waveform info from the input file (in any format) and gathers the unique information from it so it can be passed to as the WAVEFORM_DESCR LAS driver option.

Note: LAS only supports received waveforms.

pylidar.lidarformats.las.isLasFile(fname)[source]

Helper function that looks at the start of the file to determine if it is a las file or not