diff --git a/TopoFeature.cpp b/TopoFeature.cpp index fa1316b7..b0b9dbb5 100644 --- a/TopoFeature.cpp +++ b/TopoFeature.cpp @@ -776,7 +776,7 @@ void TopoFeature::lift_each_boundary_vertices(float percentile) { } ringi++; auto irings = bg::interior_rings(*(_p2)); - for (Ring2& iring: irings) { + for (Ring2& iring : irings) { for (int i = 0; i < iring.size(); i++) { std::vector &l = _lidarelevs[ringi][i]; if (l.empty() == true) @@ -790,38 +790,39 @@ void TopoFeature::lift_each_boundary_vertices(float percentile) { } //-- 2. find average height of the polygon double totalheight = 0.0; - int noheight = 0; + int heightcount = 0; oring = bg::exterior_ring(*(_p2)); for (int i = 0; i < oring.size(); i++) { if (_p2z[0][i] != -9999) { totalheight += double(_p2z[0][i]); - noheight += 1; + heightcount += 1; } } int avgheight; - if (noheight > 0) { - avgheight = int(totalheight / double(noheight)); - // std::clog << "avg height: " << avgheight << std::endl; - // std::clog << "no height " << noheight << std::endl; - - //-- 3. some vertices will have no values (no lidar point within tolerance thus) - //-- assign them the avg - ringi = 0; - oring = bg::exterior_ring(*(_p2)); - int pi; - for (int i = 0; i < oring.size(); i++) { + if (heightcount > 0) + avgheight = int(totalheight / double(heightcount)); + else + avgheight = 0; + // std::clog << "avg height: " << avgheight << std::endl; + // std::clog << "height count " << heightcount << std::endl; + + //-- 3. some vertices will have no values (no lidar point within tolerance thus) + //-- assign them the avg + ringi = 0; + oring = bg::exterior_ring(*(_p2)); + int pi; + for (int i = 0; i < oring.size(); i++) { + if (_p2z[ringi][i] == -9999) + _p2z[ringi][i] = avgheight; + } + ringi++; + irings = bg::interior_rings(*(_p2)); + for (Ring2& iring : irings) { + for (int i = 0; i < iring.size(); i++) { if (_p2z[ringi][i] == -9999) _p2z[ringi][i] = avgheight; } ringi++; - irings = bg::interior_rings(*(_p2)); - for (Ring2& iring : irings) { - for (int i = 0; i < iring.size(); i++) { - if (_p2z[ringi][i] == -9999) - _p2z[ringi][i] = avgheight; - } - ringi++; - } } }