📄 trancoordidlg.cpp
字号:
// TranCoordiDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TranCoordi.h"
#include "TranCoordiDlg.h"
#include "TextProgressDll.h"
//#include <esriCatalogUI.tlh>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTranCoordiDlg dialog
CTranCoordiDlg::CTranCoordiDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTranCoordiDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTranCoordiDlg)
m_strDataBaseName = _T("");
m_strRefName = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTranCoordiDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTranCoordiDlg)
DDX_Text(pDX, IDC_EDITDATABASE, m_strDataBaseName);
DDX_Text(pDX, IDC_EDITCOORD, m_strRefName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTranCoordiDlg, CDialog)
//{{AFX_MSG_MAP(CTranCoordiDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTNOPENDATABASE, OnBtnOpenDatabase)
ON_BN_CLICKED(IDC_BTNOPENCOOR, OnBtnOpenCoor)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTranCoordiDlg message handlers
BOOL CTranCoordiDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTranCoordiDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTranCoordiDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTranCoordiDlg::OnBtnOpenDatabase()
{
IGxDialogPtr ipGxDialog = NULL;
IGxObjectFilterPtr ipGxObjectFilter = NULL;
IEnumGxObjectPtr ipEnumGxObject = NULL;
IGxObjectPtr ipGxObject = NULL;
IWorkspaceNamePtr ipWksName = NULL;
VARIANT_BOOL bResult;
HRESULT hr;
BSTR bstrDataBaseName;
UpdateData(TRUE);
GetDlgItem(IDC_EDITDATABASE)->EnableWindow(TRUE);
GetDlgItem(IDC_EDITDATABASE)->SetWindowText("");
hr = ipGxDialog.CreateInstance(CLSID_GxDialog);
if(FAILED(hr)) return;
hr = ipGxObjectFilter.CreateInstance(CLSID_GxFilterWorkspaces);
if(FAILED(hr)) return;
ipGxDialog->putref_ObjectFilter(ipGxObjectFilter);
ipGxDialog->put_AllowMultiSelect(VARIANT_TRUE);
ipGxDialog->put_Title(CComBSTR("选择ArcGis数据库"));
hr = ipGxDialog->DoModalOpen(0,&ipEnumGxObject,&bResult);
if(FAILED(hr)) return;
if(bResult == VARIANT_FALSE) return;
// 获得地理数据库名称
hr = ipEnumGxObject->Reset();
while(!ipEnumGxObject->Next(&ipGxObject))
{
ipGxObject->QueryInterface(IID_IGxDatabase,(void **)&m_ipGxDatabase);
if(m_ipGxDatabase !=0)
{
hr = m_ipGxDatabase->get_WorkspaceName(&ipWksName);
if(FAILED(hr)) return;
ipWksName->get_PathName(&bstrDataBaseName);
m_strDataBaseName = bstrDataBaseName;
}
}
GetDlgItem(IDC_EDITDATABASE)->EnableWindow(FALSE);
UpdateData(FALSE);
}
void CTranCoordiDlg::OnBtnOpenCoor()
{
IGxDialogPtr ipGxDialog = NULL;
IGxObjectFilterPtr ipGxObjectFilter = NULL;
IEnumGxObjectPtr ipEnumGxRefCoordi = NULL;
IGxObjectPtr ipGxObject = NULL;
VARIANT_BOOL bResult = FALSE ;
HRESULT hr = 1 ;
BSTR bstrRefPath ;
UpdateData(TRUE);
GetDlgItem(IDC_EDITCOORD)->EnableWindow(TRUE);
GetDlgItem(IDC_EDITCOORD)->SetWindowText("");
hr = ipGxDialog.CreateInstance(CLSID_GxDialog);
if(FAILED(hr)) return;
hr = ipGxObjectFilter.CreateInstance(CLSID_GxFilterSpatialReferences);
if(FAILED(hr)) return;
ipGxDialog->putref_ObjectFilter(ipGxObjectFilter);
ipGxDialog->put_AllowMultiSelect(VARIANT_TRUE);
ipGxDialog->put_Title(CComBSTR("选择坐标系"));
hr = ipGxDialog->DoModalOpen(0,&ipEnumGxRefCoordi,&bResult);
if(FAILED(hr))
return;
if(bResult == VARIANT_FALSE)
return;
hr = ipEnumGxRefCoordi->Reset();
while(!ipEnumGxRefCoordi->Next(&ipGxObject))
{
IGxPrjFilePtr ipGxRefFold(ipGxObject);
if(ipGxRefFold !=0)
{
hr =ipGxRefFold->get_SpatialReference(&m_ipSpatialRef);
m_ipSpatialRef->get_Name(&bstrRefPath);
if(FAILED(hr)) return;
m_strRefName = bstrRefPath;
}
}
GetDlgItem(IDC_EDITCOORD)->EnableWindow(FALSE);
UpdateData(FALSE);
}
void CTranCoordiDlg::OnOK()
{
IWorkspacePtr ipWks = NULL;
IDEBrowseOptionsPtr pEDBrsPpt =NULL;
IWorkspaceDataElementsPtr pWksDateElemt =NULL;
IDataElementPtr pDataEmt = NULL;
IDEGeoDatasetPtr pDGSetEmt=NULL;
IGeoDatasetSchemaEditPtr ipGeoDataSetEdit;
IEnumDatasetPtr pEnumData=NULL;
IDatasetPtr pDataSet =NULL;
HRESULT hr;
long rtn = 1;
int i=0;
// 0.设置参数
hr = pEDBrsPpt.CreateInstance(CLSID_DEBrowseOptions);
if(FAILED(hr)) {rtn = 0; goto Tran_End;}
hr = pEDBrsPpt->put_RetrieveFullProperties(TRUE);
hr = pEDBrsPpt->put_ExpandType(esriDEExpandDescendants);
hr = pEDBrsPpt->put_RetrieveMetadata(TRUE);
hr = m_ipGxDatabase->get_Workspace(&ipWks);
if(FAILED(hr)) {rtn = 0; goto Tran_End;}
// 1.获得地理数据库下的所有数据集
hr = ipWks->get_Datasets(esriDTFeatureDataset,&pEnumData);
if(FAILED(hr)) {rtn = 0; goto Tran_End;}
// 2.获得数据集元数据
hr = _nCreatePercentWnd("批量转换进行中...",1);
pWksDateElemt=ipWks;
while(!pEnumData->Next(&pDataSet))
{
i++;
_nDispPercent((short)i*100/20);
ipGeoDataSetEdit=pDataSet;
hr = pWksDateElemt->GetDatasetDataElement(pDataSet,pEDBrsPpt,&pDataEmt);
if(FAILED(hr)) {rtn = 0; goto Tran_End;}
pDataEmt->put_MetadataRetrieved(TRUE);
pDGSetEmt = pDataEmt;
//3.更改坐标系
hr = pDGSetEmt->putref_SpatialReference(m_ipSpatialRef);
hr = ipGeoDataSetEdit->AlterSpatialReference(m_ipSpatialRef);
}
_nDestroyPercentWnd();
Tran_End:
if (rtn ==0)
MessageBox("坐标系统修改失败!","提示");
else
MessageBox("坐标系统修改成功!","提示");
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -