实现添加featureclass

前提是,已经#import "D:/Program Files/ArcGIS/com/esriDataSourcesFile.olb" raw_interfaces_only,raw_native_types,no_namespace,named_guids,exclude("OLE_HANDLE","OLE_COLOR")

加入到stdafx.h中了。注意顺序,要在import其他olb之后,这个主要是引入GxDialog的。

1、添加相应的菜单及菜单函数addLayer。

2、实现函数如下:

 

void CAoEx1View::OnAddshp()

{

m_ipMap = m_ctrlMap.get_Map();

HRESULT hr;

IActiveViewPtr ipActiveView(m_ipMap);

IDisplayPtr pDis;(ipActiveView);

IGxDialogPtr  ipGxDialog(CLSID_GxDialog);

IGxObjectFilterCollectionPtr pGxObjectFilterCollect(ipGxDialog);

IGxObjectFilterPtr ipGxObjectFilter(CLSID_GxFilterDatasets);

pGxObjectFilterCollect->AddFilter(ipGxObjectFilter,TRUE);

 

IGxObjectFilterPtr pGxObjectFilter(CLSID_GxFilterDatasets);

pGxObjectFilterCollect->AddFilter(pGxObjectFilter,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;

if(bResult == VARIANT_FALSE) return;

hr = ipEnumGxObject->Reset();

IFeatureLayerPtr ipFeatureLayer(CLSID_FeatureLayer);

IGxObjectPtr ipGxObject;

while (!ipEnumGxObject->Next(&ipGxObject))

{

IGxDatasetPtr ipGxDataset(ipGxObject);

if(ipGxDataset != 0)

{

IDatasetPtr ipDataset;

hr = ipGxDataset->get_Dataset(&ipDataset);

if(FAILED(hr)) return;

IFeatureClassPtr ipFeatureClass(ipDataset);

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;

}

}

IEnvelopePtr ipEnv;

hr = ipActiveView->get_FullExtent(&ipEnv);

if(FAILED(hr)) return;

hr = ipActiveView->put_Extent(ipEnv);

if(FAILED(hr)) return;

hr = ipActiveView->Refresh();

if(FAILED(hr)) return;

 

// TODO: 在此添加命令处理程序代码

}

 

你可能感兴趣的:(import,dataset,Types)