1
0
Fork 0

[elevations] Maintenance

This commit is contained in:
scttgs0 2023-05-14 02:56:20 -05:00
parent c2646de887
commit 95c62c0f30

View file

@ -21,74 +21,76 @@
//
#ifdef HAVE_CONFIG_H
# include <config.h>
#include <config.h>
#endif
#include <simgear/constants.h>
#include <simgear/math/SGMath.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/math/SGMath.hxx>
#include <Array/array.hxx>
#include "global.hxx"
#include "debug.hxx"
#include "global.hxx"
// lookup node elevations for each point in the SGGeod list. Returns
// average of all points. Doesn't modify the original list.
double tgAverageElevation( const std::string &root, const string_list elev_src,
const std::vector<SGGeod>& points_source )
double tgAverageElevation(const std::string& root, const string_list elev_src,
const std::vector<SGGeod>& points_source)
{
using namespace std::string_literals;
bool done = false;
unsigned int i;
unsigned i;
TGArray array;
// make a copy so our routine is non-destructive.
std::vector<SGGeod> points = points_source;
// just bail if no work to do
if ( points.empty() ) {
if (points.empty()) {
return 0.0;
}
// set all elevations to -9999
for ( i = 0; i < points.size(); ++i ) {
points[i].setElevationM( -9999.0 );
for (i = 0; i < points.size(); ++i) {
points[i].setElevationM(-9999.0);
}
while ( !done ) {
while (!done) {
// find first node with -9999 elevation
SGGeod first = SGGeod();
bool found_one = false;
for ( i = 0; i < points.size(); ++i ) {
if ( points[i].getElevationM() < -9000.0 && !found_one ) {
for (i = 0; i < points.size(); ++i) {
if (points[i].getElevationM() < -9000.0 && !found_one) {
first = points[i];
TG_LOG( SG_GENERAL, SG_DEBUG, "found first = " << first );
TG_LOG(SG_GENERAL, SG_DEBUG, "found first = " << first);
found_one = true;
}
}
if ( found_one ) {
SGBucket b( first );
if (found_one) {
SGBucket b(first);
std::string base = b.gen_base_path();
// try the various elevation sources
i = 0;
bool found_file = false;
while ( !found_file && i < elev_src.size() ) {
std::string array_path = root + "/" + elev_src[i] + "/" + base + "/" + b.gen_index_str();
while (!found_file && i < elev_src.size()) {
std::string array_path = root + "/"s + elev_src[i] + "/"s + base + "/"s + b.gen_index_str();
if ( array.open(array_path) ) {
if (array.open(array_path)) {
found_file = true;
TG_LOG( SG_GENERAL, SG_DEBUG, "Using array_path = " << array_path );
TG_LOG(SG_GENERAL, SG_DEBUG, "Using array_path = " << array_path);
}
i++;
++i;
}
// this will fill in a zero structure if no array data
// found/opened
array.parse( b );
array.parse(b);
// this will do a hasty job of removing voids by inserting
// data from the nearest neighbor (sort of)
@ -98,13 +100,13 @@ double tgAverageElevation( const std::string &root, const string_list elev_src,
// this array file
double elev;
done = true;
for ( i = 0; i < points.size(); ++i ) {
if ( points[i].getElevationM() < -9000.0 ) {
for (i = 0; i < points.size(); ++i) {
if (points[i].getElevationM() < -9000.0) {
done = false;
elev = array.altitude_from_grid( points[i].getLongitudeDeg() * 3600.0,
points[i].getLatitudeDeg() * 3600.0 );
if ( elev > -9000 ) {
points[i].setElevationM( elev );
elev = array.altitude_from_grid(points[i].getLongitudeDeg() * 3600.0,
points[i].getLatitudeDeg() * 3600.0);
if (elev > -9000.0) {
points[i].setElevationM(elev);
}
}
}
@ -118,11 +120,12 @@ double tgAverageElevation( const std::string &root, const string_list elev_src,
// now find the average height of the queried points
double total = 0.0;
int count = 0;
for ( i = 0; i < points.size(); ++i ) {
total += points[i].getElevationM();
count++;
for (auto& point : points) {
total += point.getElevationM();
++count;
}
double average = total / (double) count;
double average = total / (double)count;
TG_LOG(SG_GENERAL, SG_DEBUG, "Average surface height of point list = " << average);
return average;