VC++开发GIS系统(288)已知线段量算类的设计及实现

本文创建一个类用于实现线文件中折线的测量工作。功能演示如下:

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

VC++开发GIS系统(287)计算一条折线的长度 VC++开发GIS系统(289)已知线段量算之菜单响应

作者:,GIS爱好者。
分享本文,请您带上本文链接
分享到:

发表评论