Handle .zip'd SRTM data files directly.
This commit is contained in:
parent
aec29df1c8
commit
39222a737e
2 changed files with 40 additions and 2 deletions
|
@ -53,6 +53,8 @@ TGHgt::TGHgt( int _res ) {
|
||||||
|
|
||||||
data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE];
|
data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE];
|
||||||
output_data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE];
|
output_data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE];
|
||||||
|
|
||||||
|
remove_tmp_file = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,6 +64,8 @@ TGHgt::TGHgt( int _res, const SGPath &file ) {
|
||||||
data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE];
|
data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE];
|
||||||
output_data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE];
|
output_data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE];
|
||||||
|
|
||||||
|
remove_tmp_file = false;
|
||||||
|
|
||||||
TGHgt::open( file );
|
TGHgt::open( file );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +83,27 @@ TGHgt::open ( const SGPath &f ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cout << "Loading HGT data file: " << file_name.str() << endl;
|
if ( file_name.extension() == "zip" ) {
|
||||||
|
// extract the .zip file to /tmp and point the file name
|
||||||
|
// to the extracted file
|
||||||
|
cout << "Extracting " << file_name.str() << " to /tmp" << endl;
|
||||||
|
string command = "unzip -d /tmp " + file_name.base();
|
||||||
|
system( command.c_str() );
|
||||||
|
|
||||||
|
SGPath full_name = file_name.base();
|
||||||
|
file_name.set( "/tmp" );
|
||||||
|
if ( full_name.file().empty() ) {
|
||||||
|
file_name.append( full_name.str() );
|
||||||
|
} else {
|
||||||
|
file_name.append( full_name.file() );
|
||||||
|
}
|
||||||
|
remove_tmp_file = true;
|
||||||
|
remove_file_name = file_name.str();
|
||||||
|
|
||||||
|
cout << "Proceeding with " << file_name.str() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Loading HGT data file: " << file_name.str() << endl;
|
||||||
if ( (fd = gzopen( file_name.c_str(), "rb" )) == NULL ) {
|
if ( (fd = gzopen( file_name.c_str(), "rb" )) == NULL ) {
|
||||||
SGPath file_name_gz = file_name;
|
SGPath file_name_gz = file_name;
|
||||||
file_name_gz.append( ".gz" );
|
file_name_gz.append( ".gz" );
|
||||||
|
@ -112,6 +136,12 @@ TGHgt::open ( const SGPath &f ) {
|
||||||
bool
|
bool
|
||||||
TGHgt::close () {
|
TGHgt::close () {
|
||||||
gzclose(fd);
|
gzclose(fd);
|
||||||
|
|
||||||
|
if ( remove_tmp_file ) {
|
||||||
|
string command = "/bin/rm " + remove_file_name;
|
||||||
|
system( command.c_str() );
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,11 +28,16 @@
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <simgear/compiler.h>
|
||||||
|
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
|
#include STL_STRING
|
||||||
|
|
||||||
#include <simgear/bucket/newbucket.hxx>
|
#include <simgear/bucket/newbucket.hxx>
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
|
|
||||||
|
SG_USING_STD(string);
|
||||||
|
|
||||||
#define MAX_HGT_SIZE 3601
|
#define MAX_HGT_SIZE 3601
|
||||||
|
|
||||||
|
@ -58,7 +63,10 @@ private:
|
||||||
short int (*output_data)[MAX_HGT_SIZE];
|
short int (*output_data)[MAX_HGT_SIZE];
|
||||||
|
|
||||||
int hgt_resolution;
|
int hgt_resolution;
|
||||||
|
|
||||||
|
bool remove_tmp_file;
|
||||||
|
string remove_file_name;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructor, _res must be either "1" for the 1arcsec data or
|
// Constructor, _res must be either "1" for the 1arcsec data or
|
||||||
|
|
Loading…
Add table
Reference in a new issue