Wednesday, June 28, 2017

Mask a LAS file using PDAL and QGIS

The Point Data Abstraction Library (PDAL) comes with a useful function to mask or crop out a LiDAR LAS file with one or more polygons. The example screenshot below shows a point cloud overlaid with a red polygon in the upper right corner, which outlines the desired area of the point cloud to be cropped.

The cropping can be done using PDAL's crop filter but it requires the cropping polygon to be specified in the Well Known Text (WKT) string format. This is a bit of pain but can be overcome using a few methods, one of which is shown below using QGIS and the Plain Geometry Editor plugin.

Define the cropping polygon
  1. In QGIS, draw a new polygon e.g. mask, as shown below.



    Note: The mask should be created in the same coordinate system as the LAS file
  2. Click the Plain Geometry Editor icon in the toolbar (red circle above). Click on the clipping polygon.

    The Plain Geometry Editor dialog box appears.


    Note: Install the Plain Geometry Editor plugin if the icon is not available.
  3. In the text field, select and copy all the polygon WKT text string into the Windows clipboard.  
Create a PDAL processing pipeline JSON file
  1. In a text editor, type in something similar to the example below.
  2. From the Windows Clipboard, paste the WKT string from the previous section to the "polygon" attribute and surround it with double quote '"' characters.
  3. Save the JSON file e.g. process.json.
{
  "pipeline":[
    "autzen.laz",
    {
      "type":"filters.crop",
      "polygon": "Polygon ((638500.66904077248182148 853359.34703735215589404, 638869.71793351718224585 853365.15883093187585473, 638881.34152069012634456 853208.24040409235749394, 638677.92874516302254051 853199.52271371346432716, 638878.43562390014994889 852818.85023379256017506, 638733.14078423334285617 852842.09740813483949751, 638611.09311891463585198 852975.76866063219495118, 638416.39803376235067844 853211.14630088687408715, 638500.66904077248182148 853359.34703735215589404))"
    },
    {
      "type":"writers.las",
      "filename":"file-cropped.las"
    }
  ]
}

Note: 
  • The pipeline JSON file stores the processes to be done in sequence in an array bracketed by the '[' and ']' characters. 
  • autzen.laz is the input LAS file for this example
  • filters.crop is the process to apply using the "polygon" attribute.
  • file-cropped.las is the output LAS file. 


Run the cropping process
  1. Open up the OSGeo4W Shell.
  2. At the prompt, type in the pdal pipeline command:

    C:\> pdal pipeline process.json -v 4
    Processing messages appear. The file is cropped.

  3. Optional. Using your preferred LAS Viewer, open up the resultant cropped LAS file.

    The cropped file showing only the cropped area is displayed.


No comments: