| 122 | } |
| 123 | |
| 124 | bool HagDemFilter::processOne(PointRef& point) |
| 125 | { |
| 126 | using namespace pdal::Dimension; |
| 127 | static std::vector<double> data; |
| 128 | static std::array<double, 2> pix; |
| 129 | |
| 130 | double x = point.getFieldAs<double>(Id::X); |
| 131 | double y = point.getFieldAs<double>(Id::Y); |
| 132 | double z; |
| 133 | double val; |
| 134 | double hag(m_noDataHeight); |
| 135 | |
| 136 | if (m_zeroGround) |
| 137 | { |
| 138 | if (point.getFieldAs<uint8_t>(Id::Classification) == m_class) |
| 139 | { |
| 140 | point.setField(Dimension::Id::HeightAboveGround, 0); |
| 141 | return true; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | // If raster has a point at X, Y of pointcloud point, use it. |
| 146 | // Otherwise the HAG value is not set. |
| 147 | gdal::GDALError readStatus = m_raster->read(x, y, data, pix); |
| 148 | if (readStatus == gdal::GDALError::None) |
| 149 | { |
| 150 | double z = point.getFieldAs<double>(Id::Z); |
| 151 | val = data[m_band - 1]; |
| 152 | hag = z - val; |
| 153 | |
| 154 | if (val == m_bandNoData) |
| 155 | hag = m_noDataHeight; |
| 156 | |
| 157 | else if (hag < m_minClamp) |
| 158 | hag = m_minClamp; |
| 159 | |
| 160 | else if (hag > m_maxClamp) |
| 161 | hag = m_maxClamp; |
| 162 | |
| 163 | } |
| 164 | else if (readStatus == gdal::GDALError::NoData) |
| 165 | { |
| 166 | hag = m_noDataHeight; |
| 167 | } else |
| 168 | { |
| 169 | // skip any other errors |
| 170 | return true; |
| 171 | } |
| 172 | |
| 173 | point.setField(Dimension::Id::HeightAboveGround, hag); |
| 174 | return true; |
| 175 | } |
| 176 | |
| 177 | } // namespace pdal |