VC++开发GIS系统(288)已知线段量算类的设计及实现
发布时间: 2016-07-17
所属分类: VC++开发GIS系统
本文创建一个类用于实现线文件中折线的测量工作。功能演示如下:
GIS系统线段量算类的定义
在 _malaAnalysis.h 中定义GIS折线量算的类,代码如下:
/*
* 已知线段量算
*/
class malaanalysisdll CmalaLineMeasure :public CmalaMouseAction
{
public:
CmalaLineMeasure(CView* mView, malaScreen *pScreen, CString &fileFullPath);
~CmalaLineMeasure();
void LButtonDown(UINT nFlags, malaPoint point);
void LButtonUp(UINT nFlags, malaPoint point);
void MouseMove(UINT nFlags, malaPoint point);
private:
malaLinePro m_linepro;
vector<malaPoint>m_line;
CmalaLinesSelect m_SelectLine;
bool m_Selected;
bool m_bDraw;
malaPoint m_ptOrigin;
malaPoint m_perPoint;
malaScreen *m_Screen;
CString mPath;//文件路径
};
- @
*m_Screen
屏幕坐标 - @
mPath
文件路径 - @
m_Selected
控制要素是否被选中 - @
m_bDraw
标记是否按下左键 - @
m_SelectLine
选择的线 - @
m_linepro
线的属性 - @
m_line
组成折线的每一个点
类的实现
在 _malaAnalysis.cpp 中实现上述类的定义,代码如下:
//已知直线量算
CmalaLineMeasure::CmalaLineMeasure(CView* mView, malaScreen *pScreen, CString &fileFullPath)
{
mBaseView = mView;
//m_LinePro.lineColor = RGB(0, 0, 0);
//m_LinePro.lineStyle = 0;
//m_LinePro.lineWidth = 1;
mPath = fileFullPath;
m_Screen = pScreen;
CmalaLinesSelect obj(mBaseView, m_Screen, mPath);
m_SelectLine = obj;
this->m_Selected = m_SelectLine.m_Selected;
}
CmalaLineMeasure::~CmalaLineMeasure()
{
}
void CmalaLineMeasure::LButtonDown(UINT nFlags, malaPoint point)
{
if (!m_Selected)
m_SelectLine.LButtonDown(nFlags, point);
else
{
m_bDraw = TRUE;
m_ptOrigin = m_perPoint = point;
}
}
void CmalaLineMeasure::LButtonUp(UINT nFlags, malaPoint point)
{
if (!m_Selected)
m_SelectLine.LButtonUp(nFlags, point);
m_Selected = m_SelectLine.m_Selected;
if (m_Selected)
{
m_line = m_SelectLine.mLine;
m_linepro = m_SelectLine.mLinePro;
malaLogic tMath;
double dis = tMath.distanceLine(m_line);
CString str;
str.Format(L"%f", dis);
MessageBox(mBaseView->m_hWnd, str, L"坐标长度", MB_OK);
m_Selected = FALSE;
m_SelectLine.m_Selected = FALSE;
}
}
void CmalaLineMeasure::MouseMove(UINT nFlags, malaPoint point)
{
if (!m_Selected)
m_SelectLine.MouseMove(nFlags, point);
}
其中 distanceLine
的实现参考文章《VC++开发GIS系统(287)计算一条折线的长度》
详细代码可以参考:GitHub
相关阅读
声明
1.本文所分享的所有需要用户下载使用的内容(包括但不限于软件、数据、图片)来自于网络或者麻辣GIS粉丝自行分享,版权归该下载资源的合法拥有者所有,如有侵权请第一时间联系本站删除。
2.下载内容仅限个人学习使用,请切勿用作商用等其他用途,否则后果自负。
手机阅读
公众号关注
知识星球
手机阅读
最新GIS干货
私享圈子