For this post, let’s combine the work in the last 4 posts in order to get a single pipeline for doing the following:
- Calculate relative height of LiDAR data
- Slice that data into bands of heights
- Load the data into a PostgreSQL/PostGIS/pgPointCloud database.
#!/bin/bash # readlink gets us the full path to the file. This is necessary for docker readlinker=`readlink -f $1` # returns just the directory name pathname=`dirname $readlinker` # basename will strip off the directory name and the extension name=`basename $1 .las` # Docker run allows us to leverage a pdal machine with pcl built in, # thus allowing us to calculate height. # See http://www.pdal.io/tutorial/calculating-normalized-heights.html docker run -v $pathname:/data pdal/master pdal translate //data/"$name".las //data/"$name"_height.bpf height --writers.bpf.output_dims="X,Y,Z,Intensity,ReturnNumber,NumberOfReturns,ScanDirectionFlag,EdgeOfFlightLine,Classification,ScanAngleRank,UserData,PointSourceId,Height"; # Now we split the lidar data into slices of heights, from 0-1.5 ft, etc. # on up to 200 feet. We're working in the Midwest, so we don't anticipate # trees much taller than ~190 feet for START in 0:1.5 1.5:3 3:6 6:15 15:30 30:45 45:60 60:105 105:150 150:200 do # We'll use the height classes to name our output files and tablename. # A little cleanup is necessary, so we're removing the colon ":". nameend=`echo $START | sed s/:/-/g` # Name our output bpfname=$name"_"$nameend.bpf # Implement the height range filter pdal translate $name"_height".bpf $bpfname -f range --filters.range.limits="Height[$START)" # Now we put our data in the PostgreSQL database. pdal pipeline -i pipeline.xml --writers.pgpointcloud.table='layer_'$nameend --readers.bpf.filename=$bpfname --writers.pgpointcloud.overwrite='false' done
Now, we can use parallel to make this run a little faster:
find . -name "*.las" | parallel -j6 ./pdal_processor.sh {}&
Sadly, we can run into issues in running this in parallel:
PDAL: ERROR: duplicate key value violates unique constraint "pointcloud_formats_pkey" DETAIL: Key (pcid)=(1) already exists. PDAL: ERROR: duplicate key value violates unique constraint "pointcloud_formats_pkey" DETAIL: Key (pcid)=(1) already exists.
This issue is a one time issue, however — we just can’t parallelize table creation. Once the tables are created however, I believe we can parallelize without issue. I’ll report if I find otherwise.
