From 39222a737e30fdd6d3c796e554d4d173c670a5ba Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 19 Aug 2003 02:25:48 +0000 Subject: [PATCH] Handle .zip'd SRTM data files directly. --- src/Lib/HGT/hgt.cxx | 32 +++++++++++++++++++++++++++++++- src/Lib/HGT/hgt.hxx | 10 +++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/Lib/HGT/hgt.cxx b/src/Lib/HGT/hgt.cxx index 49330cb5..60a93c03 100644 --- a/src/Lib/HGT/hgt.cxx +++ b/src/Lib/HGT/hgt.cxx @@ -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; } diff --git a/src/Lib/HGT/hgt.hxx b/src/Lib/HGT/hgt.hxx index 395a0afe..79d3c13b 100644 --- a/src/Lib/HGT/hgt.hxx +++ b/src/Lib/HGT/hgt.hxx @@ -28,11 +28,16 @@ # include #endif +#include + #include +#include STL_STRING + #include #include +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