⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpstoexchangdialog.cpp

📁 自己编的用于ENVI
💻 CPP
字号:
// GpsToExChangDialog.cpp : implementation file
//

#include "stdafx.h"
#include "MagneticPro.h"
#include "GpsToExChangDialog.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGpsToExChangDialog dialog


CGpsToExChangDialog::CGpsToExChangDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CGpsToExChangDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGpsToExChangDialog)
	m_PicAngle = 0.0f;
	m_PicColor = 6;
	m_PicHigh = 1.0;
	m_PicLayer = 7;
	m_PicLineWidth = 0;
	m_PicNum = 100;
	m_PicTransparence = 1;
	m_PicWidth = 1.0;
	m_StrAngle = 0.0f;
	m_StrColor = 6;
	m_StrFont = 0;
	m_StrHigh = 1.0;
	m_StrLayer = 7;
	m_StrSpace = 0.0;
	m_StrTransparence = 1;
	m_StrWidth = 1.0;
	//}}AFX_DATA_INIT
}


void CGpsToExChangDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGpsToExChangDialog)
	DDX_Text(pDX, IDC_Picture_Angle, m_PicAngle);
	DDX_Text(pDX, IDC_Picture_Color, m_PicColor);
	DDV_MinMaxInt(pDX, m_PicColor, 0, 8);
	DDX_Text(pDX, IDC_Picture_High, m_PicHigh);
	DDV_MinMaxDouble(pDX, m_PicHigh, 0., 500.);
	DDX_Text(pDX, IDC_Picture_Layer, m_PicLayer);
	DDX_Text(pDX, IDC_Picture_LineWidth, m_PicLineWidth);
	DDX_Text(pDX, IDC_Picture_PicNum, m_PicNum);
	DDX_Text(pDX, IDC_Picture_Transparence, m_PicTransparence);
	DDV_MinMaxInt(pDX, m_PicTransparence, 0, 1);
	DDX_Text(pDX, IDC_Picture_Width, m_PicWidth);
	DDX_Text(pDX, IDC_String_Angle, m_StrAngle);
	DDX_Text(pDX, IDC_String_Color, m_StrColor);
	DDV_MinMaxInt(pDX, m_StrColor, 0, 1020);
	DDX_Text(pDX, IDC_String_Font, m_StrFont);
	DDX_Text(pDX, IDC_String_High, m_StrHigh);
	DDX_Text(pDX, IDC_String_Layer, m_StrLayer);
	DDX_Text(pDX, IDC_String_Space, m_StrSpace);
	DDX_Text(pDX, IDC_String_Transparence, m_StrTransparence);
	DDV_MinMaxInt(pDX, m_StrTransparence, 0, 1);
	DDX_Text(pDX, IDC_String_Width, m_StrWidth);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CGpsToExChangDialog, CDialog)
	//{{AFX_MSG_MAP(CGpsToExChangDialog)
	ON_BN_CLICKED(ID_SAVE_MAPGIS_WAT, OnSaveMapgisWat)
	ON_BN_CLICKED(ID_OPEN_GPS_TXT, OnOpenGpsTxt)
	ON_BN_CLICKED(ID_OPEN_GPS_JINGWEI, OnOpenGpsJingwei)
	ON_BN_CLICKED(ID_SAVE_MAPGIS_LLATITUDE, OnSaveMapgisLonglatitude)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGpsToExChangDialog message handlers

void CGpsToExChangDialog::OnSaveMapgisWat() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE); 
    //GpsPN=0;
	CFileDialog dlg(false,_T("wat"),_T("*.wat"),
	                 OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
	                 _T("文本文件 (*.wat)|*.wat|"));
	if (dlg.DoModal()) 
    {
       CStdioFile *pFile=new CStdioFile;

	   CString strTemp="",str1,str2,str5,str6,str7,str8,str3,str4,str9,str10,str11,str12,str13,str14;
	   
	   strTemp=dlg.GetFileName();
	   if(strTemp=="")
	   {
		   ::AfxMessageBox("Filename is empty!");
	   }
	   else
	   {

		   try{

		   pFile->Open(dlg.GetFileName(),CFile::modeWrite | CFile::modeCreate); // 打开文件指针  
           pFile->WriteString("WMAP9022\n");
		   strTemp.Format("%d",2*GpsPN);
		   strTemp+="\n";
		   pFile->WriteString(strTemp);
           
		   for(int i=0;i<GpsPN;i++)
		   {
               str1.Format("%6.6f",GpsData[i].xValue);
			   str2.Format("%7.6f",GpsData[i].yValue);
			   str3.Format("%d",2*i);
               str4.Format("%d",0);
			   str5=GpsData[i].Description;
			   str6.Format("%3.6f",m_StrHigh);
			   str7.Format("%3.6f",m_StrWidth);
               str8.Format("%3.6f",m_StrSpace);
			   str9.Format("%3.6f",m_StrAngle);
			   str10="1,0";
			   str11.Format("%d",m_StrFont);
			   str11=str11+",0";
			   str12.Format("%d",m_StrColor);
			   str13.Format("%d",m_StrLayer);
               str14.Format("%d",m_StrTransparence);
               strTemp=str1+","+str2+","+str3+","+str4+","+str5+","+str6
				    +","+str7+","+str8+","+str9+","+str10+","+str11+","+str12+","
				    +str13+","+str14
				    +"\n";
			   //str6="3.000000,3.000000,0.000000,0.000000,1,0,0,0,7,7,0";
			   //strTemp=str1+","+str2+","+str3+","+str4+","+str5+","+str6+"\n";
               pFile->WriteString(strTemp);
               

			   str1.Format("%6.6f",GpsData[i].xValue);
			   str2.Format("%7.6f",GpsData[i].yValue);
			   str3.Format("%d",2*i+1);
               str4.Format("%d",1);
			   str5.Format("%d",m_PicNum);
			   str6.Format("%3.6f",m_PicHigh);
			   str7.Format("%3.6f",m_PicWidth);
               
			   str9.Format("%3.6f",m_PicAngle);
			   str10="0";
			   
			   str12.Format("%d",m_PicColor);
			   str11.Format("%3.6f",m_PicLineWidth);
			   str13.Format("%d",m_PicLayer);

               str14.Format("%d",m_StrTransparence);
               strTemp=str1+","+str2+","+str3+","+str4+","+str5+","+str6
			    	  +","+str7+","+str9+","+str10+","+str12+","+str11+","
			     	  +str13+","+str14
			    	  +"\n";
			  
               pFile->WriteString(strTemp);             
		   }

	     pFile->Close();
           }
		   catch(...)
		   {
             ::AfxMessageBox("The format of the file is not match!");
		   }
	   } 
	}
}

void CGpsToExChangDialog::OnOpenGpsTxt() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE); 
    GpsPN=0;
	CFileDialog dlg(TRUE,_T("txt"),_T("*.txt"),
	                 OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
	                 _T("文本文件 (*.txT)|*.txt|"));
	if (dlg.DoModal()) 
    {
       CStdioFile *pFile=new CStdioFile;

	   CString strTemp="",str1,str2;
	   int iLong=40;
	   strTemp=dlg.GetFileName();
	   if(strTemp=="")
	   {
		   ::AfxMessageBox("Filename is empty!");
	   }
	   else
	   {

		   try{

		   pFile->Open(dlg.GetFileName(),CFile::modeRead); // 打开文件指针  
           for(int i=0;i<6;i++ )
             pFile->ReadString(strTemp); //Start form the six line!
             
		     iLong=strTemp.GetLength();  //-------------
     	   for(int i=0;(i<10000)&&(iLong>40);i++)  
		   {
		     if(iLong<40)
				 goto s;
             GpsData[i].Description=strTemp.Mid(9,6);

            
			 if(iLong<120)
			 {
			  GpsData[i].Description=strTemp.Mid(9,6);
			 // str1=strTemp.Right(iLong-117+87);
			  GpsData[i].xValue=atof(strTemp.Mid(29,7))/50.0;   //50。0为1:50000比例尺
			  GpsData[i].yValue=atof(strTemp.Mid(36,8))/50.0;
			  pFile->ReadString(strTemp);
			  iLong=strTemp.GetLength();
			  GpsPN++;
			 }
			  else if(iLong>120)
			 {
				 
			  GpsData[i].xValue=atof(strTemp.Mid(45,7))/50.0;   //50。0为1:50000比例尺
			  GpsData[i].yValue=atof(strTemp.Mid(52,8))/50.0;
			  GpsData[i].Description=strTemp.Mid(9,6);
			  pFile->ReadString(strTemp);
			  iLong=strTemp.GetLength();
			  GpsPN++;
			 }
			 
			  
			}
            
s:	     pFile->Close();
           }
		   catch(...)
		   {
             ::AfxMessageBox("The format of the file is not match!");
		   }
	   } 
	}
}

void CGpsToExChangDialog::OnOpenGpsJingwei() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE); 
    GpsPN=0;
	CFileDialog dlg(TRUE,_T("txt"),_T("*.txt"),
	                 OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
	                 _T("文本文件 (*.txT)|*.txt|"));
	if (dlg.DoModal()) 
    {
       CStdioFile *pFile=new CStdioFile;

	   CString strTemp="",str1,str2;
	   int iLong=40;
	   strTemp=dlg.GetFileName();
	   if(strTemp=="")
	   {
		   ::AfxMessageBox("Filename is empty!");
	   }
	   else
	   {

		   try{

		   pFile->Open(dlg.GetFileName(),CFile::modeRead); // 打开文件指针  
           for(int i=0;i<6;i++ )
             pFile->ReadString(strTemp); //Start form the six line!
             
		     iLong=strTemp.GetLength();  //-------------
     	   for(int i=0;(i<1000)&&(iLong>40);i++)  
		   {
		     if(iLong<40)
				 goto s;
			 GpsData[i].xValue=atof(strTemp.Mid(31,8));
			 GpsData[i].yValue=atof(strTemp.Mid(41,9));
             GpsData[i].Elevation=atof(strTemp.Mid(51,4));
			 GpsData[i].Description=strTemp.Mid(9,8);
			 pFile->ReadString(strTemp);
			 iLong=strTemp.GetLength();
			 GpsPN++;
			}
            
s:	     pFile->Close();
           }
		   catch(...)
		   {
             ::AfxMessageBox("The format of the file is not match!");
		   }
	   } 
	}
}

void CGpsToExChangDialog::OnSaveMapgisLonglatitude() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);   //刷新对话框数据
	
	CFileDialog dlg(false,_T("txt"),_T("*.txt"),
	                 OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
	                 _T("文本文件 (*.txt)|*.txt|"));
	if (dlg.DoModal()) 
    {
       CStdioFile *pFile=new CStdioFile;
	   CString f1,f2,f3,f4,f5,fTemp="";
	   fTemp=dlg.GetFileName();
	 
	   if(fTemp=="")
	   {
		   ::AfxMessageBox(" The filename is empty!");
	   }
       else
	   {   
		   pFile->Open(fTemp,CFile::modeWrite | CFile::modeCreate);
           
           for(int i=0;i<GpsPN;i++)
		   {
              f1.Format("%5.6f",GpsData[i].xValue);
			  f2.Format("%5.6f",GpsData[i].yValue);
			  f3.Format("%5.0f",GpsData[i].Elevation);
		       fTemp=GpsData[i].Description+"      "+f1+"      "+f2+"      "+f3+"\n";
			  pFile->WriteString(fTemp); 
		   }
	      
		   pFile->Close();
		   ::AfxMessageBox("经纬度高程数据输出完毕!");
	   }

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -