Python

PDAL provides Python support in two significant ways. First it embeds Python to allow you to write Python programs that interact with data using filters.python filter. Second, it extends Python by providing an extension that Python programmers can use to leverage PDAL capabilities in their own applications.

Note

PDAL’s Python story always revolves around Numpy support. PDAL’s data is provided to both the filters ands the extension as Numpy arrays.

Versions

PDAL supports both Python 2.7 and Python 3.4+. Continuous Integration tests Python 2.7 on both Linux and Windows. Python 3 is used by a number of developers for adhoc development and testing.

Embed

PDAL allows users to embed Python functions inline with other Pipeline processing operations. The purpose of this capability is to allow users to write small programs that implement interesting actions without requiring a full C++ development activity of building a PDAL stage to implement it. A Python filter is an opportunity to interactively and iteratively prototype a data operation without strong considerations of performance or generality. If something works well enough, maybe one takes on the effort to formalize it, but that isn’t necessary. PDAL’s embed of Python allows you to be as grimy as you need to get the job done.

_images/python-pdal-pipeline.png

Embedding a Python function to take Z values read from a readers.las and then output them to a writers.bpf.

Extend

PDAL provides a Python extension that gives users access to executing pipeline instantiations and capturing the results as Numpy arrays. This mode of operation is useful if you are looking to have PDAL simply act as your data format and processing handler.

Python extension users are expected to construct their own PDAL pipeline using Python’s json library, or whatever other libraries they wish to manipulate JSON. They then feed it into the extension and get back the results as Numpy arrays:

json = """
{
  [
    "1.2-with-color.las",
    {
        "type": "filters.sort",
        "dimension": "X"
    }
  ]
}"""

import pdal
pipeline = pdal.Pipeline(json)
pipeline.validate() # check if our JSON and options were good
pipeline.loglevel = 8 #really noisy
count = pipeline.execute()
arrays = pipeline.arrays
metadata = pipeline.metadata
log = pipeline.log

Installation

The PDAL Python extension requires a working PDAL installation. Unless you choose the Conda installation method, make sure that you a current, working version of PDAL before installing the extension.

Installation Using pip

As administrator, you can install PDAL using pip:

pip install PDAL

Note

To install pip please read here

Installation from Source

The PDAL Python extension is hosted on GitHub. If you have a working PDAL installation and a working Python installation, you can install the extension using the following procedure on Unix. The procedure on Windows is similar

$ git clone https://github.com/PDAL/python pdalextension
$ cd pdalextension
$ python setup.py build
# this should be run as administrator/super user
$ python setup.py install

Install using Conda

The PDAL Python extension can also be installed using the Conda package manager. An advantage of using Conda to install the extension is that Conda will install PDAL. We recommend installing PDAL and the PDAL Python extension in an environment other than the base environment. To install in an existing environment, use the following

conda install -n <environment name> -c conda-forge python-pdal

Use the following command to install PDAL and the PDAL Python extension into a new environment and activate that environment

conda create -n <environment name> -c conda-forge python-pdal
conda activate <environment name>

Note

The official pdal and python-pdal packages reside in the conda-forge channel, which can be added via conda config or manually specified with the -c option, as shown in the examples above.