Skip to content

Commit

Permalink
make filters.hag_dem streamable, improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jtfell committed Jan 29, 2020
1 parent 6ee6595 commit cbf97d4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
16 changes: 4 additions & 12 deletions doc/stages/filters.hag_dem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,6 @@
filters.hag_dem
===============================================================================

loads a GDAL readable raster
specifying the DEM to calculate ``HeightAboveGround`` from. The ``Z`` value
of each point is compared against the value at the corresponding X,Y point in
the DEM raster.

If `respect_ground_classification`_ is set, any points classified as ground will
have their ``HeightAboveGround`` value set to 0 regardless of the raster.

Any points that do not have a corresponding value in the raster DEM will not have
a ``HeightAboveGround`` value set.

The **Height Above Ground (HAG) Digital Elevation Model (DEM) filter** loads
a GDAL-readable raster image specifying the DEM. The ``Z`` value of each point
in the input is compared against the value at the corresponding X,Y location
Expand All @@ -27,6 +16,8 @@ opposed to its raw elevation value.

.. embed::

.. streamable::

Example #1
----------

Expand All @@ -39,7 +30,8 @@ and a DEM generated from it

::
# pdal translate autzen.laz autzen-dem.tiff filters.smrf
# pdal translate autzen.laz autzen-dem.tiff filters.smrf \
--writers.gdal.resolution=1

we execute the following pipeline

Expand Down
4 changes: 4 additions & 0 deletions doc/stages/filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ invalidate an existing KD-tree.
filters.elm
filters.ferry
filters.hag
filters.hag_dem
filters.info
filters.lof
filters.miniball
Expand Down Expand Up @@ -97,6 +98,9 @@ invalidate an existing KD-tree.
Compute pointwise height above ground estimate. Requires points to be
classified as ground/non-ground prior to estimating.

:ref:`filters.hag_dem`
Compute pointwise height above GDAL-readable DEM raster.

:ref:`filters.lof`
Compute pointwise Local Outlier Factor (along with K-Distance and Local
Reachability Distance).
Expand Down
48 changes: 25 additions & 23 deletions filters/HAGDEMFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,8 @@

#include "HAGDEMFilter.hpp"

#include <pdal/KDIndex.hpp>
#include <pdal/GDALUtils.hpp>

#include <string>
#include <vector>
#include <cmath>

namespace pdal
{

Expand Down Expand Up @@ -96,33 +91,40 @@ void HAGDEMFilter::prepared(PointTableRef table)
}

void HAGDEMFilter::filter(PointView& view)
{
PointRef point(view, 0);
for (PointId i = 0; i < view.size(); ++i)
{
point.setPointId(i);
processOne(point);
}
}

bool HAGDEMFilter::processOne(PointRef& point)
{
using namespace pdal::Dimension;
static std::vector<double> data;

for (PointId i = 0; i < view.size(); ++i)
// If "zero_ground" option is set, all ground points get HAG of 0
if (m_zeroGround && point.getFieldAs<uint8_t>(Id::Classification) == ClassLabel::Ground)
{
point.setField(Id::HeightAboveGround, 0);
}
else
{
double x = point.getFieldAs<double>(Id::X);
double y = point.getFieldAs<double>(Id::Y);
double z = point.getFieldAs<double>(Id::Z);

// If "zero_ground" option is set, all ground points get HAG of 0
if (m_zeroGround && view.getFieldAs<uint8_t>(Id::Classification, i) == ClassLabel::Ground)
// If raster has a point at X, Y of pointcloud point, use it. Otherwise the HAG
// value is not set.
if (m_raster->read(x, y, data) == gdal::GDALError::None)
{
view.setField(Id::HeightAboveGround, i, 0);
double hag = z - data[m_band - 1];
point.setField(Dimension::Id::HeightAboveGround, hag);
}
else
{
double x = view.getFieldAs<double>(Id::X, i);
double y = view.getFieldAs<double>(Id::Y, i);
double z = view.getFieldAs<double>(Id::Z, i);

// If raster has a point at X, Y of pointcloud point, use it. Otherwise the HAG
// value is not set.
if (m_raster->read(x, y, data) == gdal::GDALError::None)
{
double hag = z - data[m_band - 1];
view.setField(Dimension::Id::HeightAboveGround, i, hag);
}
}
}
return true;
}

} // namespace pdal
4 changes: 3 additions & 1 deletion filters/HAGDEMFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#pragma once

#include <pdal/Filter.hpp>
#include <pdal/Streamable.hpp>

#include <cstdint>
#include <memory>
Expand All @@ -48,7 +49,7 @@ class Options;
class PointLayout;
class PointView;

class PDAL_DLL HAGDEMFilter : public Filter
class PDAL_DLL HAGDEMFilter : public Filter, public Streamable
{
public:
HAGDEMFilter();
Expand All @@ -63,6 +64,7 @@ class PDAL_DLL HAGDEMFilter : public Filter
virtual void prepared(PointTableRef table);
virtual void ready(PointTableRef table);
virtual void filter(PointView& view);
virtual bool processOne(PointRef& point);

std::unique_ptr<gdal::Raster> m_raster;
std::string m_rasterName;
Expand Down

0 comments on commit cbf97d4

Please sign in to comment.