PDAL – Write Multiple .las Files from Polygon Clipping Using PDAL

cliplidarpdalpolygonpython

I am using PDAL (through Python) to crop multiple polygons from a point cloud and store them as separate files. For efficiency reasons I would like to define this in a single pipeline. However, using the approach shown below, PDAL only seems to store the data related to the last defined polygon. Is it possible to write multiple files with a single pipeline?

pipeline_definition = {
    'pipeline': [
        {
            'type': 'readers.las',
            'filename': input_file,
            'tag': 'read'
        },
        {
            'type': 'filters.crop',
            'polygon': poly1.wkt,
            'inputs': ['read'],
            'tag': 'poly1'
        },
        {
            'type': 'filters.crop',
            'polygon': poly2.wkt,
            'inputs': ['read'],
            'tag': 'poly2'
        },
        {
            'type': 'writers.las',
            'filename': 'branching_1.las',
            'inputs': ['poly1']
        },
        {
            'type': 'writers.las',
            'filename': 'branching_2.las',
            'inputs': ['poly2']
        }
    ]
}

pipeline = pdal.Pipeline(json.dumps(pipeline_definition))
pipeline.validate()
pipeline.execute()

Best Answer

This kind of pipeline isn't supported at the moment, but we do have a ticket discussing how to do so.

There's another way that might be relevant to you. You can use the combination of filters.assign and filters.groupby to grab you polygons from an OGR-readable data source. Presumably you're having to do that to get your WKT anyway, so maybe this will make things simpler for you.

{
  "pipeline":[
    {
        "type":"readers.las",
        "filename":"input.las"
    },
    {
      "type":"filters.overlay",
      "dimension":"Classification",
      "datasource":"attributes.shp",
      "layer":"attributes",
      "column":"CLS"    
    },
    {
      "type":"filters.groupby",
      "dimension":"Classification"
    },
    {
      "type":"writers.las",
      "filename":"#out.las",
      "forward":"all"
    }
  ]
}