Spatial Processing Utilities

Utility functions for assisting with Spatial Processing in Pylidar.

class pylidar.toolbox.spatial.ImageWriter(filename, numBands=1, gdalDataType=None, driverName=<Mock name='mock.applier.DEFAULTDRIVERNAME' id='139784340187152'>, driverOptions=<Mock name='mock.applier.DEFAULTCREATIONOPTIONS' id='139784340187600'>, tlx=0.0, tly=0.0, binSize=0.0, epsg=None, nullVal=None, ncols=None, nrows=None, calcStats=True)[source]

Class that handles writing out image data with GDAL

close()[source]

Close and flush the dataset, plus calculate stats

createDataset()[source]

Internal method. Assumes self.gdalDataType, self.ncols and self.nrows is set.

setLayer(array, layerNum=1)[source]

Set a layer in the file as a 2d array

exception pylidar.toolbox.spatial.SpatialException[source]

An exception that is raised by this module

pylidar.toolbox.spatial.getBlockCoordArrays(xMin, yMax, nCols, nRows, binSize)[source]

Return a tuple of the world coordinates for every pixel in the current block. Each array has the same shape as the current block. Return value is a tuple:

(xBlock, yBlock)

where the values in xBlock are the X coordinates of the centre of each pixel, and similarly for yBlock.

The coordinates returned are for the pixel centres. This is slightly inconsistent with usual GDAL usage, but more likely to be what one wants.

pylidar.toolbox.spatial.getGridInfoFromData(xdata, ydata, binSize)[source]

Given an array of X coords, an array of Y coords, plus a binSize return a tuple of (xMin, yMax, ncols, nrows) for doing operations on a grid

pylidar.toolbox.spatial.getGridInfoFromHeader(header, binSize, footprint=<Mock name='mock.imageio.UNION' id='139784338863248'>)[source]

Given a Lidar file header (or a list of headers - maximum extent will be calculated) plus a binSize return a tuple of (xMin, yMax, ncols, nrows) for doing operations on a grid Specify lidarprocessor.UNION or lidarprocessor.INTERSECTION to determine how multiple headers are combined.

pylidar.toolbox.spatial.readImageLayer(inFile, layerNum=1)[source]

Read a layer from a GDAL supported dataset and return it as a 2d numpy array along with georeferencing information.

Returns a tuple with (data, xMin, yMax, binSize)

pylidar.toolbox.spatial.readLidarPoints(filename, classification=None, boundingbox=None, colNames=['X', 'Y', 'Z'])[source]

Read the requested columns for the points in the given file (or files if filename is a list), in a memory-efficient manner. Uses pylidar to read only a block of points at a time, and select out just the desired columns. When the input file is a .las file, this saves quite a lot of memory, in comparison to reading in all points at once, since all columns for all points have to be read in at the same time.

Optionally filter by CLASSIFICATION column with a value from the generic.CLASSIFICATION_* constants.

If boundingbox is given, it is a tuple of (xmin, xmax, ymin, ymax) and only points within this box are included.

Return a single recarray with only the selected columns, and only the selected points.

pylidar.toolbox.spatial.selectColumns(data, otherargs)[source]

Called from pylidar’s doProcessing.

Read the next block of lidar points, select out the requested columns. If requested, filter to ground only. If requested, restrict to the given bounding box.

pylidar.toolbox.spatial.xyToRowCol(x, y, xMin, yMax, pixSize)[source]

For the given pixel size and xMin, yMax, convert the given arrays of x and y into arrays of row and column in a regular grid across the tile.

xMin and yMax represent the top/left corner of the top/left pixel of the image

Assumes that the bounds of the grid are to be fixed on integer coordinates.

Return a tuple of arrays
(row, col)