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

📄 aoconvertview.cpp

📁 栅格矢量转换的dll,vc+ao写的
💻 CPP
字号:
// AoConvertView.cpp : implementation of the CAoConvertView class
//

#include "stdafx.h"
#include "AoConvert.h"
#include "DlgShpToRaster.h"
#include "DlgClip.h"
#include "AoConvertDoc.h"
#include "AoConvertView.h"
#include "DlgRasterToShp.h"
#include "common.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAoConvertView

IMPLEMENT_DYNCREATE(CAoConvertView, CFormView)

BEGIN_MESSAGE_MAP(CAoConvertView, CFormView)
	//{{AFX_MSG_MAP(CAoConvertView)
	ON_COMMAND(IDM_FILE_OPEN, OnFileOpen)
	ON_WM_SIZE()
	ON_COMMAND(IDM_TO_RASTER, OnToRaster)
	ON_COMMAND(IDD_CLIP, OnClip)
	ON_COMMAND(IDM_RasterToShp, OnRasterToShp)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAoConvertView construction/destruction

CAoConvertView::CAoConvertView()
	: CFormView(CAoConvertView::IDD)
{
   

}

CAoConvertView::~CAoConvertView()
{
}

void CAoConvertView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAoConvertView)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BOOL CAoConvertView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CAoConvertView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
    
	// Get the Control's interfaces 
	CWnd *pWndCal = GetDlgItem(IDC_MAPCONTROL1); 
	LPUNKNOWN pUnk = pWndCal->GetControlUnknown();
	//from there get the mapControl2 interface of control
	pUnk->QueryInterface(IID_IMapControl2,(LPVOID *)&m_ipMapcontrol);
	m_ipMapcontrol->get_Map(&m_ipMap);

	pWndCal = GetDlgItem(IDC_TOCCONTROL1);
	pUnk = pWndCal->GetControlUnknown();
	pUnk->QueryInterface(IID_ITOCControl,(LPVOID *)&m_ipTOCControl);
  //建立控件的伙伴关系
	m_ipTOCControl->SetBuddyControl(m_ipMapcontrol);

}

/////////////////////////////////////////////////////////////////////////////
// CAoConvertView diagnostics

#ifdef _DEBUG
void CAoConvertView::AssertValid() const
{
	CFormView::AssertValid();
}

void CAoConvertView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CAoConvertDoc* CAoConvertView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAoConvertDoc)));
	return (CAoConvertDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CAoConvertView message handlers

void CAoConvertView::OnFileOpen() 
{
   HRESULT  hr;

   IActiveViewPtr ipActiveView(m_ipMap);
   
   IGxDialogPtr  ipGxDialog(CLSID_GxDialog);

    //得到Gxdialog对象的IGxObjectFilterCollection接口以方便设置Filter
   IGxObjectFilterCollectionPtr pGxObjectFilterCollect(ipGxDialog);
      //将一个IGxObjectFilter对象添加到Gxdialog
   IGxObjectFilterPtr ipGxObjectFilter1(CLSID_GxFilterShapefiles);
   pGxObjectFilterCollect->AddFilter(ipGxObjectFilter1,TRUE);
  
   //添加一个IGxObjectFilter对象添加到Gxdialog
   IGxObjectFilterPtr ipGxObjectFilter2(CLSID_GxFilterRasterDatasets);
   pGxObjectFilterCollect->AddFilter(ipGxObjectFilter2,FALSE);
    
   ipGxDialog->put_AllowMultiSelect(VARIANT_TRUE);
   ipGxDialog->put_Title(CComBSTR("选择数据"));
   
   IEnumGxObjectPtr ipEnumGxObject;
   VARIANT_BOOL bResult;
   hr = ipGxDialog->DoModalOpen(0, &ipEnumGxObject, &bResult);
   if(FAILED(hr)) return;
  
   
   hr = ipEnumGxObject->Reset();
   IGxObjectPtr ipGxObject;
   while(! ipEnumGxObject->Next(&ipGxObject))
   {
        IGxDatasetPtr ipGxDataset(ipGxObject);
		if( ipGxDataset == 0) return;
		esriDatasetType pType; 
        ipGxDataset->get_Type(&pType);
		
		IDatasetPtr ipDataset;
		hr = ipGxDataset->get_Dataset(&ipDataset);
		if(FAILED(hr)) return;

		if(pType == esriDTFeatureClass)
		{
		  // IDatasetPtr ipDataset;
		  // hr = ipGxDataset->get_Dataset(&ipDataset);
		   if(FAILED(hr)) return;
		   IFeatureClassPtr  ipFeatureClass(ipDataset);	
		   IFeatureLayerPtr ipFeatureLayer(CLSID_FeatureLayer);
		   hr = ipFeatureLayer->putref_FeatureClass(ipFeatureClass);
		   if(FAILED(hr)) return;
		   
		   hr = ipFeatureLayer->put_Visible(VARIANT_TRUE);
		   if(FAILED(hr)) return;

		   ILayerPtr ipLayer(ipFeatureLayer);
		   
		   hr = m_ipMap->AddLayer(ipLayer);
		   if(FAILED(hr)) return;
		 
		}
		
		if(pType == esriDTRasterDataset)
		{
			IRasterDatasetPtr ipRasterDataset(ipDataset);
			IRasterLayerPtr ipRasterLy(CLSID_RasterLayer);
			ipRasterLy->CreateFromDataset(ipRasterDataset);
			
			ILayerPtr ipLyr(ipRasterLy);
			m_ipMap->AddLayer(ipLyr);
		
		}
	
   
   }

  ipActiveView->Refresh();
  
}

void CAoConvertView::OnSize(UINT nType, int cx, int cy) 
{
	CFormView::OnSize(nType, cx, cy);
	
	CWnd *MapControl = GetDlgItem(IDC_MAPCONTROL1);
	CWnd *TocControl = GetDlgItem(IDC_TOCCONTROL1);
    CRect ControlRect;
	GetClientRect(&ControlRect);

	if (TocControl) //第一次 调用onSize 函数时指针为0
	{
	    TocControl->MoveWindow(0,0,ControlRect.Width()/5,ControlRect.Height());
	}
	if(MapControl)
	{
		MapControl->MoveWindow(ControlRect.Width()/5,0,ControlRect.Width(),ControlRect.Height());
          	
	}
	
}

//矢量转栅格
void CAoConvertView::OnToRaster() 
{
	CDlgShpToRaster dlgShptoRaster;
	
	CString strSrcPath; //SHP文件路径
	CString strOutPath; //输入栅格文件路径
	CString strAtrField;//属性字段
    double   dCellSzie;  //    转换称栅格的分辨率
    LONG lTag;
	if(dlgShptoRaster.DoModal() == IDOK)
	{

   
		dCellSzie = dlgShptoRaster.m_dCellSize;
		strSrcPath = dlgShptoRaster.m_strShpPath;
		strOutPath = dlgShptoRaster.m_strRasterPath;
		strAtrField = dlgShptoRaster.m_strFeature;
     	
		ASSERT( dCellSzie> 0);
		ASSERT(strSrcPath != "");
		ASSERT(strOutPath != "");
		ASSERT(strAtrField != "");
		BeginWaitCursor();
	    lTag = gShpToRaster(strSrcPath, strOutPath,strAtrField,dCellSzie);
		EndWaitCursor();
		if(lTag != 0L) MessageBox("Failed");
		

	}
	
	
	
}

//栅格转矢量
void CAoConvertView::OnRasterToShp() 
{

	CString strRaster;
	CString strShp;
	CString strType;
	CDlgRasterToShp dlgRasterToshp;
	if(dlgRasterToshp.DoModal()== IDOK)
	{
		strRaster = dlgRasterToshp.m_strInputRaster;
		strShp = dlgRasterToshp.m_strOutShp;
		strType =dlgRasterToshp.m_strFeatureClass;
		ASSERT(strRaster!="");
        ASSERT(strShp!="");
		ASSERT(strType!="");
		BeginWaitCursor();
		LONG lTag = gRasterToShp(strRaster,strShp,strType);
		if(lTag != 0L)
			MessageBox("FAILED!");
		EndWaitCursor();
		
	}

	
}





void CAoConvertView::OnClip() 
{
/*	CDlgClip dlgClip;
	CString strSrcPath;     //shp path
	CString strOutPath;      //shp out path
	CString strRefRaster;    //raster path(Clip shp)
    
	if(dlgClip.DoModal() == IDOK)
	{
		ASSERT((strSrcPath = dlgClip.strShpPath) != "");
		ASSERT((strRefRaster = dlgClip.strRasterPath) != "");
		ASSERT((strOutPath = dlgClip.strOutPath) != "");

		gClipShp(strSrcPath, strOutPath, strRefRaster);

		
	
	}
	
	*/

    

	
}



⌨️ 快捷键说明

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