diff --git a/doc/stages/filters.head.rst b/doc/stages/filters.head.rst index bb3529e387..f6433fb457 100644 --- a/doc/stages/filters.head.rst +++ b/doc/stages/filters.head.rst @@ -6,6 +6,11 @@ filters.head The HeadFilter returns a specified number of points from the beginning of the PointView. +.. note:: + + If the requested number of points exceeds the size of the point cloud, all + points are passed with a warning. + Example #1 ---------- diff --git a/doc/stages/filters.tail.rst b/doc/stages/filters.tail.rst index 929ea6f1a4..39ae73d53c 100644 --- a/doc/stages/filters.tail.rst +++ b/doc/stages/filters.tail.rst @@ -6,6 +6,11 @@ filters.tail The TailFilter returns a specified number of points from the end of the PointView. +.. note:: + + If the requested number of points exceeds the size of the point cloud, all + points are passed with a warning. + Example #1 ---------- @@ -28,7 +33,7 @@ Sort and extract the 100 lowest intensity points. } ] } - + .. seealso:: diff --git a/filters/HeadFilter.hpp b/filters/HeadFilter.hpp index b256a59f1d..42d65fb1e0 100644 --- a/filters/HeadFilter.hpp +++ b/filters/HeadFilter.hpp @@ -66,9 +66,13 @@ class PDAL_DLL HeadFilter : public Filter PointViewSet run(PointViewPtr view) { + if (m_count > view->size()) + log()->get(LogLevel::Warning) + << "Requested number of points (count=" << m_count + << ") exceeds number of available points.\n"; PointViewSet viewSet; PointViewPtr outView = view->makeNew(); - for (PointId i = 0; i < m_count; ++i) + for (PointId i = 0; i < std::min(m_count, view->size()); ++i) outView->appendPoint(*view, i); viewSet.insert(outView); return viewSet; diff --git a/filters/TailFilter.hpp b/filters/TailFilter.hpp index 15501868c8..fc45ecb85d 100644 --- a/filters/TailFilter.hpp +++ b/filters/TailFilter.hpp @@ -66,9 +66,14 @@ class PDAL_DLL TailFilter : public Filter PointViewSet run(PointViewPtr view) { + if (m_count > view->size()) + log()->get(LogLevel::Warning) + << "Requested number of points (count=" << m_count + << ") exceeds number of available points.\n"; PointViewSet viewSet; PointViewPtr outView = view->makeNew(); - for (PointId i = view->size() - m_count; i < view->size(); ++i) + for (PointId i = view->size() - std::min(m_count, view->size()); + i < view->size(); ++i) outView->appendPoint(*view, i); viewSet.insert(outView); return viewSet;