Rasterizing Attributes

This exercise uses PDAL to generate a raster surface using a fully classified point cloud with PDAL’s writers.gdal.

Exercise

Note

The exercise fetches its data from a Greyhound service that organizes the point cloud collection for the entire country of Denmark. You can view the data online at http://potree.entwine.io/data/denmark.html

Command

Invoke the following command, substituting accordingly, in your OSGeo4W Shell:

PDAL capability to generate rasterized output is provided by the writers.gdal stage. There is no application to drive this stage, and we must use a pipeline.

Pipeline breakdown

Note

This pipeline is available in your workshop materials in the ./exercises/analysis/dtm/dtm.json file. Make sure to edit the filenames to match your paths.

1. Reader

    {
        "type":"readers.greyhound",
        "url":"http://na.greyhound.io/resource/dk-z/read?depthBegin=1&depthEnd=29&bounds=[11045777.34375,-11852109.375,223441.40625,11055492.1875,-11842394.53125,233156.25]&compress=true&scale=0.01&offset=[1295630,7596240,-2280]"
    },
    {

The data is read from a readers.greyhound server that hosts the Denmark data. We’re going to download a small patch of data by the Copenhagen airport that is the “full depth” of the tree.

2. writers.gdal

The writers.gdal writer that bins the point cloud data with classification values.

    {
      "type":"writers.gdal",
      "filename":"denmark-classification.tif",
      "dimension":"Classification",
      "data_type":"uint16_t",
      "output_type":"mean",
      "resolution":30.0
    }

Execution

Issue the pipeline operation to execute the interpolation:

pdal pipeline classification.json
{
  "pipeline":[
    {
        "type":"readers.greyhound",
        "url":"http://na.greyhound.io/resource/dk-z/read?depthBegin=1&depthEnd=29&bounds=[11045777.34375,-11852109.375,223441.40625,11055492.1875,-11842394.53125,233156.25]&compress=true&scale=0.01&offset=[1295630,7596240,-2280]"
    },
    {
      "type":"writers.gdal",
      "filename":"denmark-classification.tif",
      "dimension":"Classification",
      "data_type":"uint16_t",
      "output_type":"mean",
      "resolution":30.0
    }
  ]
}
../../../../_images/rasterization-classification-run-command.png

Visualization

../../../../_images/rasterization-denmark-no-ramp.png

Basic interpolation of data with writers.gdal will output raw classification values into the resulting raster file. We will need to add a color ramp to the data for a satisfactory preview.

Unfortunately, this doesn’t give us a very satisfactory image to view. The reason is there is no color ramp associated with the file, and we’re looking at pixel values with values from 0-31 according to the ASPRS LAS specification.

We want colors that correspond to the classification values a bit more directly. We can use a color ramp to assign explicit values. QGIS allows us to create a text file color ramp that gdaldem can consume to apply colors to the data.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# QGIS Generated Color Map Export File
0,255,0,0,255
1,234,234,234,255
2,222,126,44,255
3,30,62,15,255
4,45,255,6,255
5,209,230,201,255
6,249,12,6,255
7,146,197,222,255
8,133,5,2,255
9,0,0,255,255
10,255,255,255,255

With the ramp, we can use gdaldem to apply it to a new image:

1
2
3
4
5
6
gdaldem color-relief ^
   denmark-classification.tif ^
   ramp.txt ^
   classified-color.png ^
   -exact_color_entry ^
   -of PNG
../../../../_images/rasterization-colored-classification.png

The use of -exact_color_entry for gdaldem ensures that specific classification values are given the requested color. For categorical data such as a classification surface, interpolated output would look poor.

Intensity

With PDAL’s ability to override pipeline via commands, we can generate a relative intensity image:

1
2
3
4
5
6
pdal pipeline classification.json ^
    --writers.gdal.dimension="Intensity" ^
    --writers.gdal.data_type="float" ^
    --writers.gdal.filename="intensity.tif"

gdal_translate intensity.tif intensity.png -of PNG
../../../../_images/rasterization-colored-intensity.png

The same pipeline can be used to generate a preview image of the Intensity channel of the data by overriding pipeline arguments at the command line.

Notes

  1. writers.gdal can output any dimension PDAL can provide, but it is is up to the user to interpolate the values. For categorical data, neighborhood smoothing might produce undesirable results, for example.
  2. Pipeline contains more information about overrides and organizing complex pipelines.