feat: 新增航测航线,待完善
parent
f3696d4f5b
commit
33052d8140
@ -0,0 +1,354 @@
|
||||
// designsurveylinedlg.cpp : 实现文件
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "designsurveylinedlg.h"
|
||||
#include "afxdialogex.h"
|
||||
|
||||
|
||||
// DesignSurveyLineDlg 对话框
|
||||
|
||||
IMPLEMENT_DYNAMIC(DesignSurveyLineDlg, CBCGPDialog)
|
||||
|
||||
DesignSurveyLineDlg::DesignSurveyLineDlg(CWnd* pParent /*=NULL*/)
|
||||
: CBCGPDialog(DesignSurveyLineDlg::IDD, pParent)
|
||||
{
|
||||
EnableVisualManagerStyle(TRUE, TRUE);
|
||||
|
||||
bDrawRegion = false;
|
||||
}
|
||||
|
||||
DesignSurveyLineDlg::~DesignSurveyLineDlg()
|
||||
{
|
||||
}
|
||||
|
||||
void DesignSurveyLineDlg::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CBCGPDialog::DoDataExchange(pDX);
|
||||
DDX_Control(pDX, IDC_BTN_SAVEREGION, m_btnSaveRegion);
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(DesignSurveyLineDlg, CBCGPDialog)
|
||||
ON_BN_CLICKED(IDC_BTN_INPUTREGION, &DesignSurveyLineDlg::OnBnClickedBtnInputregion)
|
||||
ON_BN_CLICKED(IDC_BTN_DRAWREGION, &DesignSurveyLineDlg::OnBnClickedBtnDrawregion)
|
||||
ON_BN_CLICKED(IDC_BTN_SAVEREGION, &DesignSurveyLineDlg::OnBnClickedBtnSaveregion)
|
||||
ON_BN_CLICKED(IDC_BTN_BINDLINE, &DesignSurveyLineDlg::OnBnClickedBtnBindline)
|
||||
ON_BN_CLICKED(IDC_BTN_CALCULATELINE, &DesignSurveyLineDlg::OnBnClickedBtnCalculateline)
|
||||
ON_WM_CLOSE()
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
BOOL DesignSurveyLineDlg::OnInitDialog()
|
||||
{
|
||||
CBCGPDialog::OnInitDialog();
|
||||
CenterWindow();
|
||||
GetDlgItem( IDC_BTN_CALCULATELINE )->EnableWindow( false );
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//提取没有后缀名的文件名
|
||||
CString DesignSurveyLineDlg::extractFileName(CString fileName)
|
||||
{
|
||||
// 查找最后一个点的位置
|
||||
int dotIndex = fileName.ReverseFind(_T('.'));
|
||||
|
||||
// 如果找到了点,并且点不是第一个字符
|
||||
if (dotIndex != -1)
|
||||
{
|
||||
// 提取文件名,不包括后缀
|
||||
CString fileNameWithoutExtension = fileName.Left(dotIndex);
|
||||
return fileNameWithoutExtension;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果没有找到点,说明没有后缀,直接显示文件名
|
||||
return fileName;
|
||||
}
|
||||
}
|
||||
|
||||
//设置航测区域
|
||||
void DesignSurveyLineDlg::SetSurveyRegion(const vector<double>& lons,const vector<double>& lats)
|
||||
{
|
||||
for (int i=0;i<lons.size();++i)
|
||||
{
|
||||
surveyRegionLons.push_back(lons[i]);
|
||||
surveyRegionLats.push_back(lats[i]);
|
||||
}
|
||||
GetDlgItem( IDC_BTN_CALCULATELINE )->EnableWindow( true );
|
||||
}
|
||||
|
||||
//计算测绘航线
|
||||
void DesignSurveyLineDlg::calculateSurveyLine(double lineInterval,vector<double>&surveyLineLons,vector<double>& surveyLineLats)
|
||||
{
|
||||
vector<double> recLons;
|
||||
vector<double> recLats;
|
||||
TopologicalAnalysis analysis;
|
||||
GeoCompute geocompute;
|
||||
analysis.GetBoundingBoxVertices(surveyRegionLons,surveyRegionLats,recLons,recLats);
|
||||
double lon1,lat1,lon2,lat2;
|
||||
//第一条切割线为航线间隔一半
|
||||
geocompute.computeOffsetGeoPosition(recLons[0],recLats[0],180,lineInterval/2000,lon1,lat1);
|
||||
geocompute.computeOffsetGeoPosition(recLons[1],recLats[1],180,lineInterval/2000,lon2,lat2);
|
||||
Point2D pt1,pt2;
|
||||
pt1.x = lon1;
|
||||
pt1.y = lat1;
|
||||
pt2.x = lon2;
|
||||
pt2.y = lat2;
|
||||
vector<Point2D> result;
|
||||
analysis.linePolygonIntersections(pt1,pt2,surveyRegionLons,surveyRegionLats,result);
|
||||
|
||||
while(lat1>recLats[2]){
|
||||
//平移切割线
|
||||
geocompute.computeOffsetGeoPosition(lon1,lat1,180,lineInterval/1000,lon1,lat1);
|
||||
geocompute.computeOffsetGeoPosition(lon2,lat2,180,lineInterval/1000,lon2,lat2);
|
||||
pt1.x = lon1;
|
||||
pt1.y = lat1;
|
||||
pt2.x = lon2;
|
||||
pt2.y = lat2;
|
||||
//计算交点
|
||||
analysis.linePolygonIntersections(pt1,pt2,surveyRegionLons,surveyRegionLats,result);
|
||||
}
|
||||
//串联交点
|
||||
int j = 1;
|
||||
for (int i=0;i<result.size();i+=2)
|
||||
{
|
||||
if (j == 1)
|
||||
{
|
||||
surveyLineLons.push_back(result[i+1].x);
|
||||
surveyLineLons.push_back(result[i].x);
|
||||
surveyLineLats.push_back(result[i+1].y);
|
||||
surveyLineLats.push_back(result[i].y);
|
||||
j = 0;
|
||||
continue;
|
||||
}
|
||||
else if (j==0)
|
||||
{
|
||||
surveyLineLons.push_back(result[i].x);
|
||||
surveyLineLons.push_back(result[i+1].x);
|
||||
surveyLineLats.push_back(result[i].y);
|
||||
surveyLineLats.push_back(result[i+1].y);
|
||||
j=1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//保存测绘航线
|
||||
void DesignSurveyLineDlg::saveSurveyLine(const vector<double>&surveyLineLons,const vector<double>& surveyLineLats,double height)
|
||||
{
|
||||
//写航线
|
||||
CString filename;
|
||||
CString strRouteFileDir = GetSoftwareCurrentDirectory() + _T("\\Route\\") + _T("测绘航线\\");
|
||||
//测绘航线文件夹不存在则创建
|
||||
if (!SearchDirectory(strRouteFileDir))
|
||||
{
|
||||
CreateDirectory(strRouteFileDir);
|
||||
}
|
||||
|
||||
TCHAR s[10000];
|
||||
s[0]=0;
|
||||
CString defaultName = g_regionFileName + "-测绘航线.route";
|
||||
CFileDialog dlg(FALSE, _T(".route"), defaultName);
|
||||
dlg.m_ofn.lpstrTitle=_T("保存测绘航线文件");
|
||||
/*
|
||||
dlg.m_ofn.lpstrFile=s;
|
||||
dlg.m_ofn.nMaxFile=sizeof(s)/sizeof(TCHAR);*/
|
||||
|
||||
TCHAR filter[500]=_T("测绘航线文件(*.route)\0*.route\0");
|
||||
dlg.m_ofn.lpstrFilter=filter;
|
||||
dlg.m_ofn.Flags|=OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_CREATEPROMPT;
|
||||
dlg.m_ofn.lpstrInitialDir = strRouteFileDir;
|
||||
|
||||
if (IDOK == dlg.DoModal())
|
||||
{
|
||||
filename = dlg.GetPathName();
|
||||
g_linePathName = filename;
|
||||
g_lineFileName = extractFileName(dlg.GetFileName());
|
||||
|
||||
FILE* fp = fopen(filename,"w");
|
||||
int iLineNum = 5;
|
||||
fprintf(fp,"%d, 0, %.7f, %.7f, %.2f, 0, 00, 03\n", iLineNum, 0.0, 0.0, 0.0);
|
||||
int i = 0;
|
||||
for (i;i<surveyLineLons.size()-1;++i)
|
||||
{
|
||||
fprintf(fp,"%d, %d, %.7f, %.7f, %.2f, 0, 00, 03\n", iLineNum,i+1, surveyLineLons[i], surveyLineLats[i], height);
|
||||
}
|
||||
fprintf(fp,"%d, %d, %.7f, %.7f, %.2f, 0, 02, 01\n", iLineNum,i+1, surveyLineLons[i], surveyLineLats[i], height);
|
||||
fclose(fp);
|
||||
}else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//保存航测区域
|
||||
bool DesignSurveyLineDlg::saveSurveyRegion(const vector<double>&surveyRegionLons,const vector<double>& surveyRegionLats)
|
||||
{
|
||||
//写航线
|
||||
CString filename;
|
||||
CString strRouteFileDir = GetSoftwareCurrentDirectory() + _T("\\Route\\") + _T("测绘航线\\");
|
||||
//测绘航线文件夹不存在则创建
|
||||
if (!SearchDirectory(strRouteFileDir))
|
||||
{
|
||||
CreateDirectory(strRouteFileDir);
|
||||
}
|
||||
|
||||
TCHAR s[10000];
|
||||
s[0]=0;
|
||||
CFileDialog dlg(FALSE, _T(".txt"), _T("测绘区域1.txt"));
|
||||
dlg.m_ofn.lpstrTitle=_T("保存测绘区域文件");
|
||||
/*
|
||||
dlg.m_ofn.lpstrFile=s;
|
||||
dlg.m_ofn.nMaxFile=sizeof(s)/sizeof(TCHAR);*/
|
||||
|
||||
TCHAR filter[500]=_T("测绘区域文件(*.txt)\0*.txt\0");
|
||||
dlg.m_ofn.lpstrFilter=filter;
|
||||
dlg.m_ofn.Flags|=OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_CREATEPROMPT;
|
||||
dlg.m_ofn.lpstrInitialDir = strRouteFileDir;
|
||||
|
||||
if (IDOK == dlg.DoModal())
|
||||
{
|
||||
filename = dlg.GetPathName();
|
||||
g_regionPathName = filename;
|
||||
g_regionFileName = extractFileName(dlg.GetFileName());
|
||||
|
||||
FILE* fp = fopen(filename,"w");
|
||||
int iLineNum = 5;
|
||||
fprintf(fp,"%d, 0, %.7f, %.7f, %.2f, 0, 00, 03\n", iLineNum, 0.0, 0.0, 0.0);
|
||||
int i = 0;
|
||||
for (i;i<surveyRegionLons.size()-2;++i)
|
||||
{
|
||||
fprintf(fp,"%d, %d, %.7f, %.7f, %.2f, 0, 00, 03\n", iLineNum,i+1, surveyRegionLons[i], surveyRegionLats[i], 0);
|
||||
}
|
||||
fprintf(fp,"%d, %d, %.7f, %.7f, %.2f, 0, 03, 01\n", iLineNum,i+1, surveyRegionLons[i], surveyRegionLats[i], 0);
|
||||
fclose(fp);
|
||||
return true;
|
||||
}else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// DesignSurveyLineDlg 消息处理程序
|
||||
|
||||
//导入航测区
|
||||
void DesignSurveyLineDlg::OnBnClickedBtnInputregion()
|
||||
{
|
||||
//写航线
|
||||
CString filename;
|
||||
CString strRouteFileDir = GetSoftwareCurrentDirectory() + _T("\\Route\\") + _T("测绘航线\\");
|
||||
|
||||
TCHAR s[10000];
|
||||
s[0]=0;
|
||||
CFileDialog dlg(TRUE);
|
||||
dlg.m_ofn.lpstrTitle=_T("打开航测区域文件");
|
||||
dlg.m_ofn.lpstrFile=s;
|
||||
dlg.m_ofn.nMaxFile=sizeof(s)/sizeof(TCHAR);
|
||||
|
||||
TCHAR filter[500]=_T("航测区域文件(*.txt)\0*.txt\0所有文件(*.*)\0*.*\0");
|
||||
dlg.m_ofn.lpstrFilter=filter;
|
||||
dlg.m_ofn.Flags|=OFN_HIDEREADONLY;
|
||||
dlg.m_ofn.lpstrInitialDir = strRouteFileDir;
|
||||
|
||||
// 显示对话框并获取用户的选择
|
||||
if (dlg.DoModal() == IDOK)
|
||||
{
|
||||
// 获取选择的文件路径
|
||||
CString filePath = dlg.GetPathName();
|
||||
g_regionPathName = filePath;
|
||||
g_regionFileName = extractFileName(dlg.GetFileName());
|
||||
|
||||
char* path = filePath.GetBuffer();
|
||||
//发送消息到主程序,进行显示
|
||||
if (g_mapHwnd != NULL)
|
||||
{
|
||||
::SendMessage(g_mapHwnd, WM_SEND_SHOWSURVEYREGION, (WPARAM)path, 0);
|
||||
}
|
||||
GetDlgItem( IDC_BTN_CALCULATELINE )->EnableWindow( true );
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//绘制航测区
|
||||
void DesignSurveyLineDlg::OnBnClickedBtnDrawregion()
|
||||
{
|
||||
bDrawRegion = true;
|
||||
}
|
||||
|
||||
//保存航测区
|
||||
void DesignSurveyLineDlg::OnBnClickedBtnSaveregion()
|
||||
{
|
||||
m_btnSaveRegion.EnableWindow(false);
|
||||
if (saveSurveyRegion(surveyRegionLons,surveyRegionLats))
|
||||
{
|
||||
char* path = g_regionPathName.GetBuffer();
|
||||
//发送消息到主程序,进行标绘
|
||||
if (g_mapHwnd != NULL)
|
||||
{
|
||||
::SendMessage(g_mapHwnd, WM_SEND_SHOWSURVEYREGION, (WPARAM)path, 0);
|
||||
}
|
||||
}
|
||||
m_btnSaveRegion.EnableWindow(true);
|
||||
}
|
||||
|
||||
//装订测绘航线
|
||||
void DesignSurveyLineDlg::OnBnClickedBtnBindline()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
}
|
||||
|
||||
//生成航测航线
|
||||
void DesignSurveyLineDlg::OnBnClickedBtnCalculateline()
|
||||
{
|
||||
if (surveyRegionLats.size()<3)
|
||||
{
|
||||
BCGPMessageBox("航测区域无效或缺少航测区域!");
|
||||
return;
|
||||
}
|
||||
|
||||
CString cstr;
|
||||
GetDlgItemText(IDC_EDIT_HEIGHT,cstr);
|
||||
double height = _ttof(cstr);
|
||||
if (height<=0||height>500)
|
||||
{
|
||||
BCGPMessageBox("航高范围为(0,500]m!");
|
||||
return;
|
||||
}
|
||||
GetDlgItemText(IDC_EDIT_LINEINTERVAL,cstr);
|
||||
double lineInterval = _ttof(cstr);
|
||||
if (lineInterval < 1 )
|
||||
{
|
||||
BCGPMessageBox("航线间隔必须大于1m");
|
||||
return;
|
||||
}
|
||||
|
||||
g_Height = height;
|
||||
//测绘航线坐标
|
||||
vector<double> surveyLineLons;
|
||||
vector<double> surveyLineLats;
|
||||
//计算航测航线
|
||||
calculateSurveyLine(lineInterval,surveyLineLons,surveyLineLats);
|
||||
//保存航测航线
|
||||
saveSurveyLine(surveyLineLons,surveyLineLats,height);
|
||||
//发送消息到主程序,进行标绘
|
||||
if (g_mapHwnd != NULL)
|
||||
{
|
||||
char* path = g_linePathName.GetBuffer();
|
||||
::SendMessage(g_mapHwnd, WM_SEND_SHOWSURVEYLINE, (WPARAM)path, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void DesignSurveyLineDlg::OnClose()
|
||||
{
|
||||
CBCGPDialog::OnClose();
|
||||
|
||||
//发送消息到主程序,进行显示
|
||||
if (g_mapHwnd != NULL)
|
||||
{
|
||||
::SendMessage(g_mapHwnd, WM_CLEAR_TMPSURVEYFEATURE, 0, 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
#include "Resource.h"
|
||||
#include <vector>
|
||||
#include "topologicalanalysis.h"
|
||||
#include "geocompute.h"
|
||||
#include "Globe.h"
|
||||
#include "afxwin.h"
|
||||
|
||||
// DesignSurveyLineDlg 对话框
|
||||
|
||||
// DesignSurveyLineDlg 对话框
|
||||
class DesignSurveyLineDlg : public CBCGPDialog
|
||||
{
|
||||
DECLARE_DYNAMIC(DesignSurveyLineDlg)
|
||||
|
||||
public:
|
||||
DesignSurveyLineDlg(CWnd* pParent = NULL); // 标准构造函数
|
||||
virtual ~DesignSurveyLineDlg();
|
||||
|
||||
bool bDrawRegion;
|
||||
void SetSurveyRegion(const vector<double>& lons,const vector<double>& lats);
|
||||
//测绘区域坐标
|
||||
vector<double> surveyRegionLons;
|
||||
vector<double> surveyRegionLats;
|
||||
|
||||
// 对话框数据
|
||||
enum { IDD = IDD_DLG_DESIGNSURVEYLINE };
|
||||
|
||||
private:
|
||||
void calculateSurveyLine(double lineInterval,vector<double>&surveyLineLons,vector<double>& surveyLineLats);//计算测绘航线
|
||||
void saveSurveyLine(const vector<double>&surveyLineLons,const vector<double>& surveyLineLats,double height); //保存测绘航线
|
||||
bool saveSurveyRegion(const vector<double>&surveyRegionLons,const vector<double>& surveyRegionLats); //保存航测区域
|
||||
//测绘航线坐标
|
||||
vector<double> surveyLineLons;
|
||||
vector<double> surveyLineLats;
|
||||
double g_Height;
|
||||
|
||||
// 测绘区域文件路径
|
||||
CString g_regionPathName;
|
||||
CString g_regionFileName;
|
||||
CString g_linePathName;
|
||||
CString g_lineFileName;
|
||||
|
||||
CString extractFileName(CString fileName); //提取没有后缀名的文件名
|
||||
protected:
|
||||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
public:
|
||||
virtual BOOL OnInitDialog();
|
||||
afx_msg void OnBnClickedBtnInputregion();
|
||||
afx_msg void OnBnClickedBtnDrawregion();
|
||||
afx_msg void OnBnClickedBtnSaveregion();
|
||||
afx_msg void OnBnClickedBtnBindline();
|
||||
afx_msg void OnBnClickedBtnCalculateline();
|
||||
afx_msg void OnClose();
|
||||
CBCGPButton m_btnSaveRegion;
|
||||
};
|
@ -0,0 +1,12 @@
|
||||
#include "stdafx.h"
|
||||
#include "geocompute.h"
|
||||
|
||||
|
||||
GeoCompute::GeoCompute(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GeoCompute::~GeoCompute(void)
|
||||
{
|
||||
}
|
Loading…
Reference in New Issue