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

📄 gen.cpp

📁 基于小波的SAR斑点处理
💻 CPP
字号:
////////////////////////////////////////////////////
// Gen.cpp--implement of CGenFile
//

#include "stdafx.h"
#include "string.h"
#include "tchar.h"
#include "gen.h"
#include "project.h"
#include "gauss.h"
#include "blxy54.h"

//////////////////////////////////////////////////
//////////////////////////////////////////////////

IMPLEMENT_DYNAMIC(CGenFile, CObject)

CGenFile::CGenFile(UINT width, UINT zone)
{
	m_Width = width;
	m_Zone = zone;
}

//3度带经纬度转坐标
bool CGenFile::Transform(const CString& szReadName, const CString& szWriteName)
{
	CStdioFile flRead, flWrite;
	char bufRead[50], bufWrite[50];
	CString cszRead,cszLong, cszLatt,cszXco,cszYco;
	double fB,fL;
	//,fB54, fL54;
	//, fBdms, fLdms, fB54dms, fL54dms;
	int iNumber, iCount;
	int j;
	double dfX[10000], dfY[10000];
	char* token;

	// 打开读文件
	try
	{
		flRead.Open(szReadName, CFile::modeRead | CFile::shareDenyNone|CFile::typeText);
	}
	catch (CFileException e)
	{
		#ifdef _DEBUG
			afxDump << "File could not be opened" << e.m_cause<<"\n";
		#endif
	}

	// 打开写文件
	try
	{
		flWrite.Open(szWriteName, CFile::modeCreate | CFile::modeWrite |
									CFile::typeText);
	}
	catch (CFileException e)
	{
		#ifdef _DEBUG
			afxDump << "File could not be opened" << e.m_cause<<"\n";
		#endif
	}

	//CGauss   Gauss(6378245.0, 6356863.0, m_cLongitude, m_Width);
	definite_ellipsolid_parameter();
	
	// 从读文件中读50个字节,并进行循环初始化
	try
	{
		flRead.ReadString(bufRead, 50);
	}
	catch (CFileException e)
	{
		#ifdef _DEBUG
			afxDump << "Error when reading from file" << e.m_cause<<"\n";
		#endif
	}
	iCount = 0;

	// 循环读数据,并进行坐标转换
	do
	{
		token = strtok(bufRead, "," );  
		sscanf(token, "%d", &iNumber);     
		token = strtok(NULL, "," );  
		sscanf(token, "%lf", &fB);
		token = strtok(NULL, "," );  
		sscanf(token, "%lf", &fL);
		//fBdms = ::Degree_to_dms(fB);
		//fLdms = ::Degree_to_dms(fL);
		//::change(fLdms, fBdms, &fL54dms, &fB54dms);
		//fL54 = ::Dms_to_degree(fL54dms);
		//fB54 = ::Dms_to_degree(fB54dms); 
		//trbltoxy is Gauss transform
		//dfX[iCount] = fL54;
		//dfY[iCount] = fB54;
		::trbltoxy(m_Width,m_Zone,fL,fB,&dfX[iCount],&dfY[iCount]);	
		//::trbltoxy(m_Width,m_Zone,fL54,fB54,&dfX[iCount],&dfY[iCount]);
		iCount++;
		
		//从读文件中读50个字节,并继续循环
		try
		{
			flRead.ReadString(bufRead, 50);
		}
		catch (CFileException e)
		{
			#ifdef _DEBUG
				afxDump << "Error when reading from file" << e.m_cause<<"\n";
			#endif
		}
	} 
	while (strncmp("END", bufRead, 3) != 0);
	
	// 将转换的公里网坐标保存为文件
	flWrite.WriteString("1\n");
	for (j = 0; j < iCount; j++)
	{
		sprintf(bufWrite,"%11.2lf,%11.2lf\n", dfX[j], dfY[j]);
		//sprintf(bufWrite,"%11.7lf,%11.7lf\n", dfX[j], dfY[j]);
		try
		{
			flWrite.WriteString(bufWrite);
		}
		catch (CFileException e)
		{
			#ifdef _DEBUG
				afxDump << "File could not be written" << e.m_cause<<"\n";
			#endif
		}
	}
	flWrite.WriteString("END\n");
	flWrite.WriteString("END");
	flWrite.Close();
	
	AfxMessageBox("3度带经纬度转坐标成功");
	return TRUE;
}

BOOL CGenFile::Trans6bl2xy(const CString& szReadName, const CString& szWriteName)
{
	CStdioFile flRead, flWrite;
	char bufRead[50], bufWrite[50];
	CString cszRead,cszLong, cszLatt,cszXco,cszYco;
	double fB,fL, fBdms, fLdms; 
	//fB54dms, fL54dms;fB54, fL54,
	int iNumber, iCount;
	int j;
	double dfX[10000], dfY[10000];
	char* token;
	PRJXY prjXY;
	double cLongitude;

	// 打开读文件
	try
	{
		flRead.Open(szReadName, CFile::modeRead | CFile::shareDenyNone|CFile::typeText);
	}
	catch (CFileException e)
	{
		#ifdef _DEBUG
			afxDump << "File could not be opened" << e.m_cause<<"\n";
		#endif
	}

	// 打开写文件
	try
	{
		flWrite.Open(szWriteName, CFile::modeCreate | CFile::modeWrite |
									CFile::typeText);
	}
	catch (CFileException e)
	{
		#ifdef _DEBUG
			afxDump << "File could not be opened" << e.m_cause<<"\n";
		#endif
	}
	
	cLongitude = m_Zone * m_Width - m_Width/2.0;
	CGauss   Gauss(6378245.0, 6356863.0, cLongitude, m_Width);
	
	// 从读文件中读50个字节,为循环做初始化
	try
	{
		flRead.ReadString(bufRead, 50);
	}
	catch (CFileException e)
	{
		#ifdef _DEBUG
			afxDump << "Error when reading from file" << e.m_cause<<"\n";
		#endif
	}
	iCount = 0;
	
	// 循环读数据,并进行坐标转换
	do
	{
		token = strtok(bufRead, "," );  
		sscanf(token, "%d", &iNumber);     
		token = strtok(NULL, "," );  
		sscanf(token, "%lf", &fB);
		token = strtok(NULL, "," );  
		sscanf(token, "%lf", &fL);
		fBdms = ::Degree_to_dms(fB);
		fLdms = ::Degree_to_dms(fL);
		prjXY = Gauss.Project_xy(fLdms, fBdms);
		
		// because the unit of prjXY is KM, so multiply 1000.
		dfX[iCount] = prjXY.x * 1000;
		dfY[iCount] = prjXY.y * 1000;
		
		iCount++;
		try
		{
			flRead.ReadString(bufRead, 50);
		}
		catch (CFileException e)
		{
			#ifdef _DEBUG
				afxDump << "Error when reading from file" << e.m_cause<<"\n";
			#endif
		}
	} 
	while (strncmp("END", bufRead, 3) != 0);
	
	flWrite.WriteString("1\n");
	for (j = 0; j < iCount; j++)
	{
		sprintf(bufWrite,"%11.2lf,%11.2lf\n", dfX[j], dfY[j]);
		try
		{
			flWrite.WriteString(bufWrite);
		}
		catch (CFileException e)
		{
			#ifdef _DEBUG
				afxDump << "File could not be written" << e.m_cause<<"\n";
			#endif
		}
	}
	flWrite.WriteString("END\n");
	flWrite.WriteString("END");
	flWrite.Close();
	
	AfxMessageBox("6度带经纬度转公里网坐标成功!");
	return TRUE;
}

BOOL CGenFile::Trans6xy2bl(const CString& szReadName, const CString& szWriteName)
{
	CStdioFile flRead, flWrite;
	char bufRead[50], bufWrite[50];
	CString cszRead,cszLong, cszLatt,cszXco,cszYco;
	double fX,fY;
	int iCount;
	int j;
	double dfB[10000], dfL[10000];
	char* token;
	PRJBL prjBL;
	double cLongitude;

	try
	{
		flRead.Open(szReadName, CFile::modeRead | CFile::shareDenyNone|CFile::typeText);
	}
	catch (CFileException e)
	{
		#ifdef _DEBUG
			afxDump << "File could not be opened" << e.m_cause<<"\n";
		#endif
	}

	try
	{
		flWrite.Open(szWriteName, CFile::modeCreate | CFile::modeWrite |
									CFile::typeText);
	}
	catch (CFileException e)
	{
		#ifdef _DEBUG
			afxDump << "File could not be opened" << e.m_cause<<"\n";
		#endif
	}
	
	cLongitude = m_Zone * m_Width - m_Width/2.0;
	CGauss   Gauss(6378245.0, 6356863.0, cLongitude, m_Width);
	
	try
	{
		flRead.ReadString(bufRead, 50);
		//flRead.ReadString(bufRead, 50);
	}
	catch (CFileException e)
	{
		#ifdef _DEBUG
			afxDump << "Error when reading from file" << e.m_cause<<"\n";
		#endif
	}
	iCount = 0;
	
	do
	{
		token = strtok(bufRead, "," );  
		sscanf(token, "%lf", &fX);
		token = strtok(NULL, "," );  
		sscanf(token, "%lf", &fY);
//		because prjBL use data of KM
		prjBL = Gauss.Project_bl(fX/1000, fY/1000);
		dfB[iCount] = ::Dms_to_degree(prjBL.B);
		dfL[iCount] = ::Dms_to_degree(prjBL.L);
		
		iCount++;
		try
		{
			flRead.ReadString(bufRead, 50);
		}
		catch (CFileException e)
		{
			#ifdef _DEBUG
				afxDump << "Error when reading from file" << e.m_cause<<"\n";
			#endif
		}
	} 
	while (strncmp("END", bufRead, 3) != 0);

	for (j = 0; j < iCount; j++)
	{
		sprintf(bufWrite,"%6d,%11.6lf,%11.6lf\n", j+1,dfL[j], dfB[j]);

		try
		{
			flWrite.WriteString(bufWrite);
		}
		catch (CFileException e)
		{
			#ifdef _DEBUG
				afxDump << "File could not be written" << e.m_cause<<"\n";
			#endif
		}
	}
	flWrite.WriteString("END\n");
	flWrite.Close();
	
	AfxMessageBox("6度带公里网坐标转经纬度成功!");
	return TRUE;
}

⌨️ 快捷键说明

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