📄 subsetdatadlg.cpp
字号:
// SubsetDataDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SubsetPAL.h"
#include "OptionsDlg.h"
#include "SubsetDataDlg.h"
#include "subsetfunc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define GZIP_EXE_PATH "C:\\Windows\\gzip.exe"
#define PAL_NDVI_OFFSET 128
#define PAL_NDVI_GAIN 0.008
#define PAL_CH1_CH2_OFFSET 10
#define PAL_CH1_CH2_GAIN 0.002
#define PAL_CH3_CH4_OFFSET -31990
#define PAL_CH3_CH4_GAIN 0.005
/////////////////////////////////////////////////////////////////////////////
// CSubsetDataDlg dialog
CSubsetDataDlg::CSubsetDataDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSubsetDataDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSubsetDataDlg)
m_bOptionSetted = FALSE;
//}}AFX_DATA_INIT
}
void CSubsetDataDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSubsetDataDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSubsetDataDlg, CDialog)
//{{AFX_MSG_MAP(CSubsetDataDlg)
ON_BN_CLICKED(ID_OPTIONS, OnOptions)
ON_BN_CLICKED(ID_SUBSETBAND1, OnSubsetband1)
ON_BN_CLICKED(ID_SUBSETBAND2, OnSubsetband2)
ON_BN_CLICKED(ID_SUBSETBAND4, OnSubsetband4)
ON_BN_CLICKED(ID_SUBSETBAND5, OnSubsetband5)
ON_BN_CLICKED(ID_SUBSETNDVI, OnSubsetndvi)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSubsetDataDlg message handlers
void CSubsetDataDlg::OnOptions()
{
COptionsDlg dlg;
if (dlg.DoModal() == IDOK)
{
m_bSubsetDecades = dlg.m_bSubsetDecades;
m_bSubsetMonths = dlg.m_bSubsetMonths;
m_iOutputFormat = dlg.m_iOutputFormat;
m_sOutputPath = dlg.m_sOutputPath;
m_sTempFilePath = dlg.m_sTempFilePath;
m_bOptionSetted = TRUE;
}
}
void CSubsetDataDlg::OnSubsetband1()
{
if(m_bOptionSetted)
{
AfxGetApp()->DoWaitCursor(1);
FileSeries selectedFiles;
PreFindFiles(AVHRR_CH1, selectedFiles);
if (selectedFiles.GetFilesCount() > 0)
PreSubsetPAL(selectedFiles, AVHRR_CH1);
AfxGetApp()->DoWaitCursor(-1);
}
else
AfxMessageBox("请先设置subset选项");
}
void CSubsetDataDlg::OnSubsetband2()
{
if(m_bOptionSetted)
{
AfxGetApp()->DoWaitCursor(1);
FileSeries selectedFiles;
PreFindFiles(AVHRR_CH2, selectedFiles);
if (selectedFiles.GetFilesCount() > 0)
PreSubsetPAL(selectedFiles, AVHRR_CH2);
AfxGetApp()->DoWaitCursor(-1);
}
else
AfxMessageBox("请先设置subset选项");
}
void CSubsetDataDlg::OnSubsetband4()
{
if(m_bOptionSetted)
{
AfxGetApp()->DoWaitCursor(1);
FileSeries selectedFiles;
PreFindFiles(AVHRR_CH4, selectedFiles);
if (selectedFiles.GetFilesCount() > 0)
PreSubsetPAL(selectedFiles, AVHRR_CH4);
AfxGetApp()->DoWaitCursor(-1);
}
else
AfxMessageBox("请先设置subset选项");
}
void CSubsetDataDlg::OnSubsetband5()
{
if(m_bOptionSetted)
{
AfxGetApp()->DoWaitCursor(1);
FileSeries selectedFiles;
PreFindFiles(AVHRR_CH5, selectedFiles);
if (selectedFiles.GetFilesCount() > 0)
PreSubsetPAL(selectedFiles, AVHRR_CH5);
AfxGetApp()->DoWaitCursor(-1);
}
else
AfxMessageBox("请先设置subset选项");
}
void CSubsetDataDlg::OnSubsetndvi()
{
if(m_bOptionSetted)
{
AfxGetApp()->DoWaitCursor(1);
FileSeries selectedFiles;
PreFindFiles(AVHRR_NDVI, selectedFiles);
if (selectedFiles.GetFilesCount() > 0)
PreSubsetPAL(selectedFiles, AVHRR_NDVI);
AfxGetApp()->DoWaitCursor(-1);
}
else
AfxMessageBox("请先设置subset选项");
}
void CSubsetDataDlg::PreFindFiles(DataType dt, FileSeries &fs)
{
CString filePath = SelectFolder();
if (filePath != _T(""))
{
filePath += "*.*";
FindFiles(dt, fs, filePath);
}
}
void CSubsetDataDlg::FindFiles(DataType dt, FileSeries& files, CString pathName)
{
CFileFind fileFind;
if (fileFind.FindFile(pathName) != 0)
{
BOOL flag = FALSE;
while(TRUE)
{
if (fileFind.FindNextFile() == 0)
flag = TRUE;
if(fileFind.IsDots())
{
if (flag)
break;
else
continue;
}
if(fileFind.IsDirectory())
FindFiles(dt, files, fileFind.GetFilePath()+"\\*.*");
else
{
CString temp = fileFind.GetFilePath();
switch (dt)
{
case AVHRR_NDVI:
if (temp.Find("ndvi") < 0)
if(flag) goto stop; else continue;
break;
case AVHRR_CH1:
if (temp.Find("ch1") < 0)
if(flag) goto stop; else continue;
break;
case AVHRR_CH2:
if (temp.Find("ch2") < 0)
if(flag) goto stop; else continue;
break;
case AVHRR_CH4:
if (temp.Find("ch4") < 0)
if(flag) goto stop; else continue;
break;
case AVHRR_CH5:
if (temp.Find("ch5") < 0)
if(flag) goto stop; else continue;
break;
default:
break;
}
if (m_bSubsetMonths)
{
int pos1 = temp.Find(".gz"), pos2 = (temp.Left(pos1)).ReverseFind('.');
if((temp.Mid(pos2, pos1-pos2)).GetLength() < 6)
files.AddFile(temp);
}
if (m_bSubsetDecades)
{
int pos1 = temp.Find(".gz"), pos2 = (temp.Left(pos1)).ReverseFind('.');
if((temp.Mid(pos2, pos1-pos2)).GetLength() > 6)
files.AddFile(temp);
}
}
stop: if (flag)
break;
}
fileFind.Close();
}
}
void CSubsetDataDlg::PreSubsetPAL(FileSeries &fs, DataType dt)
{
Files * pData = fs.GetData();
CString temp, newfileName;
while (pData != NULL)
{
temp = pData->filePathName;
if (temp.Find(".gz") >= 0)
{
newfileName = m_sTempFilePath+temp.Right(temp.GetLength()-temp.ReverseFind('\\')-1);
::CopyFile(temp, newfileName, TRUE);
CString cmdLine;
cmdLine = GZIP_EXE_PATH;
cmdLine += " -q -d ";
cmdLine += newfileName;
::WinExec(cmdLine, SW_HIDE);
}
newfileName = newfileName.Left(newfileName.Find(".gz"));
CFileFind ff;
CFile f;
BOOL bFileDecompressed=FALSE;
while(!bFileDecompressed)
{
if(ff.FindFile(newfileName))
{
if(f.Open(newfileName, CFile::modeRead))
{
bFileDecompressed = TRUE;
f.Close();
}
}
else
bFileDecompressed = FALSE;
}
SubsetPAL(newfileName, dt);
pData = pData->pNext;
}
}
void CSubsetDataDlg::SubsetPAL(CString fileName, DataType dt)
{
int offset;
double gain;
if(dt == AVHRR_NDVI)
{
offset = PAL_NDVI_OFFSET;
gain = PAL_NDVI_GAIN;
}
else if(dt == AVHRR_CH1 || dt == AVHRR_CH2)
{
offset = PAL_CH1_CH2_OFFSET;
gain = PAL_CH1_CH2_GAIN;
}
else if(dt == AVHRR_CH4 || dt == AVHRR_CH5)
{
offset = PAL_CH3_CH4_OFFSET;
gain = PAL_CH3_CH4_GAIN;
}
UINT recordSize;
if (dt == AVHRR_NDVI) recordSize = 1;
else recordSize = 2;
Corner nc = ((CSubsetPALApp*)AfxGetApp())->m_northCorner,
sc = ((CSubsetPALApp*)AfxGetApp())->m_southCorner;
switch (m_iOutputFormat)
{
case ASCII_TEXT:
SubsetToASCII(fileName, m_sOutputPath, nc, sc, recordSize, offset, gain);
break;
case ARCINFO_GRID:
SubsetToGrid(fileName, m_sOutputPath, nc, sc, recordSize, offset, gain);
break;
case ERDAS_IMG:
SubsetToImg(fileName, m_sOutputPath, nc, sc, recordSize, offset, gain);
break;
case ENVI_STANDARD:
SubsetToEnvi(fileName, m_sOutputPath, nc, sc, recordSize, offset, gain);
break;
default:;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -