1
0
Fork 0

Handle .zip'd SRTM data files directly.

This commit is contained in:
curt 2003-08-19 02:25:48 +00:00
parent aec29df1c8
commit 39222a737e
2 changed files with 40 additions and 2 deletions

View file

@ -53,6 +53,8 @@ TGHgt::TGHgt( int _res ) {
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];
output_data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE];
remove_tmp_file = false;
TGHgt::open( file );
}
@ -79,7 +83,27 @@ TGHgt::open ( const SGPath &f ) {
return false;
}
} 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 ) {
SGPath file_name_gz = file_name;
file_name_gz.append( ".gz" );
@ -112,6 +136,12 @@ TGHgt::open ( const SGPath &f ) {
bool
TGHgt::close () {
gzclose(fd);
if ( remove_tmp_file ) {
string command = "/bin/rm " + remove_file_name;
system( command.c_str() );
}
return true;
}

View file

@ -28,11 +28,16 @@
# include <config.h>
#endif
#include <simgear/compiler.h>
#include <zlib.h>
#include STL_STRING
#include <simgear/bucket/newbucket.hxx>
#include <simgear/misc/sg_path.hxx>
SG_USING_STD(string);
#define MAX_HGT_SIZE 3601
@ -58,7 +63,10 @@ private:
short int (*output_data)[MAX_HGT_SIZE];
int hgt_resolution;
bool remove_tmp_file;
string remove_file_name;
public:
// Constructor, _res must be either "1" for the 1arcsec data or