Combining Lidar Point Clouds To Calculating Tree Height

#!/bin/bash

# To get the source data

# Visit this webpage:
# https://apps.nationalmap.gov/downloader/

# Check  Elevation Source Data (3DEP) - Lidar, IfSAR
# Check Lidar Point Cloud (LPC)
# Use the Map and the Area of Interest Tools to Select Files to Download
# Click the Products Tab
# Click the [TXT] icon to download the listing and save in the folder you plan to use

cat data.txt | tr -d '\n' | xargs -d '\r' -I {} wget -c -nc '{}'

# create the pipeline-unclassified.json
cat  > pipeline-unclassified.json <<EOF
{ 
    "pipeline": [
        { 
            "type": "readers.las"
        },
        {
            "type": "filters.range",
            "limits": "Classification[1:1]"
        },
        {
            "gdaldriver":"GTiff",
            "resolution": 1.0,
            "output_type": "max",
            "type":"writers.gdal"
        }
    ]
}
EOF

ls *.laz | xargs -I {} basename {} .laz | xargs -P3 -I {} pdal pipeline pipeline-unclassified.json --readers.las.filename={}.laz --writers.gdal.filename={}-unclassified.tif

# create the pipeline-ground.json
cat > pipeline-ground.json <<EOF
{ 
    "pipeline": [
        { 
            "type": "readers.las"
        },
        {
            "type": "filters.range",
            "limits": "Classification[2:2]"
        },
        {
            "gdaldriver":"GTiff",
            "resolution": 1.0,
            "output_type": "max",
            "type":"writers.gdal"
        }
    ]
}
EOF

ls *.laz | xargs -I {} basename {} .laz | xargs -P3 -I {} pdal pipeline pipeline-ground.json --readers.las.filename={}.laz --writers.gdal.filename={}-ground.tif

gdalbuildvrt unclassified.vrt *-unclassified.tif
gdalbuildvrt ground.vrt *-ground.tif

gdal_fillnodata ground.vrt ground.tif
gdal_fillnodata unclassified.vrt unclassified.tif

gdal_calc -A unclassified.tif --outfile=unclassified.tif --calc="A*3.28084"
gdal_calc -A ground.tif --outfile=ground.tif --calc="A*3.28084"

gdal_calc -A unclassified.tif -B ground.tif --extent=union --outfile=height.tif --calc="A-B" 

Leave a Reply

Your email address will not be published. Required fields are marked *