File

The File class is the core laspy tool. It provides access to point records and dimensions via the laspy.base.reader and laspy.base.writer classes, and holds a reference to a laspy.header.HeaderManager instance to provide header reading and modifying capability. It is also iterable and sliceable.

Dimensions:

In addition to grabbing whole point records, it is possible to obtain and set individual dimensions as well. The dimensions available to a particular file depend on the point format, a summary of which is available via the File.point_format.xml() method. Dimensions might be used as follows:

# Flip the X and Y Dimensions
>>> FileObject = file.File("./path_to_file", mode = "rw")
>>> X = FileObject.X
>>> Y = FileObject.Y
>>> FileObject.X = Y
>>> FileObject.Y = X
>>> FileObject.close()

# Print out a list of available point dimensions:
>>> for dim in FileObject.point_format:
>>>     print(i.name)
# Alternately, grab descriptive xml:
>>> FileObject.point_format.xml()
class laspy.file.File(filename, header=None, vlrs=False, mode='r', in_srs=None, out_srs=None, evlrs=False)[source]

Base file object in laspy. Provides access to most laspy functionality, and holds references to the HeaderManager, Reader, and potentially Writer objects.

__init__(filename, header=None, vlrs=False, mode='r', in_srs=None, out_srs=None, evlrs=False)[source]

Instantiate a file object to represent an LAS file.

Parameters:
  • filename – The filename to open
  • header (a laspy.header.Header instance) – A header open the file with. Not required in modes “r” and “rw”
  • mode (string) – “r” for read, “rw” for modify/update, “w” for write, and “w+” for append (not implemented)
  • in_srs (a laspy.SRS instance) – Input SRS to override the existing file’s SRS with (not implemented)
  • out_srs (a laspy.SRS instance (not implemented)) – Output SRS to reproject points on-the-fly to as they are read/written. (not implemented)

Note

To open a file in write mode, you must provide a laspy.header.Header instance which will be immediately written to the file. If you provide a header instance in read mode, the values of that header will be used in place of those in the actual file.

Note

If a file is open for write, it cannot be opened for read and vice versa.

>>> from laspy import file
>>> f = file.File('file.las', mode='r')
>>> for p in f:
...     print 'X,Y,Z: ', p.x, p.y, p.z
>>> h = f.header
>>> f2 = file.File('file2.las', mode = "w", header=h)
>>> points = f.points
>>> f2.points = points
>>> f2.close()
__iter__()[source]

Iterator support (read mode only)

>>> points = []
>>> for i in f:
...   points.append(i)
...   print i 
<laspy.base.Point object at ...>
__getitem__(index)[source]

Index and slicing support

>>> out = f[0:3]
[<laspy.base.Point object at ...>,
<laspy.base.Point object at ...>,
<laspy.base.Point object at ...>]
__len__()[source]

Returns the number of points in the file according to the header

close(ignore_header_changes=False, minmax_mode='scaled')[source]

Closes the LAS file

header

The file’s laspy.header.Header

Note

The header class supports .xml and .etree methods.

Note

If the file is in append mode, the header will be overwritten in the file. Setting the header for the file when it is in read mode has no effect. If you wish to override existing header information with your own at read time, you must instantiate a new laspy.file.File instance.

open()[source]

Open the file for processing, called by __init__

points

The point data from the file. Get or set the points as either a valid numpy array, or a list/array of laspy.base.Point instances. In write mode, the number of point records is set the first time a dimension or point array is supplied to the file.

point_format

The point format of the file, stored as a laspy.util.Format instance. Supports .xml and .etree methods.

reader

The file’s laspy.base.Reader object.

writer

The file’s laspy.base.Writer object, if applicable.

Previous topic

API Documentation

Next topic

Header