bool ArcmapDataBase::convertFeatureDataset(dan::Object<iDataPlugin::IPGLayer> layer, dan::DString ipNowFeatureClassName, dan::DString ipNowFeatureDatasetName) //往要素数据集里面导入要素 { /*相关变量定义*/ dan::DString ipOldFeatureClassName = layer->layerName(); IFeatureDataConverterPtr ipFeatureDataConvert(CLSID_FeatureDataConverter); dan::Object<ArcmapLayer> aLayer = layer; //获取当前空间参照(get ISpatialReference) IFeatureClassPtr ipFeatureClass = aLayer->getFeatureClass(); IGeoDatasetPtr ipGeoDataset = ipFeatureClass; ISpatialReferencePtr ipSpatialRefrence; ipGeoDataset->get_SpatialReference(&ipSpatialRefrence); //得到空间参照SpatialReference IWorkspacePtr ipWorkspace = getWorkspace(); IFeatureWorkspacePtr ipFeatureWorkspace = ipWorkspace; IDatasetPtr ipDataset = ipWorkspace; INamePtr ipName; ipDataset->get_FullName(&ipName); IWorkspaceNamePtr ipWorkspaceName = ipName; IFeatureClassNamePtr ipCurFeatureClassName(CLSID_FeatureClassName); IDatasetNamePtr ipDatasetName = ipCurFeatureClassName; ipDatasetName->putref_WorkspaceName(ipWorkspaceName); ipDatasetName->put_Name(_bstr_t((LPCTSTR)ipOldFeatureClassName.utf16())); //get InputDatasetName; IQueryFilterPtr ipQueryFilter(CLSID_QueryFilter); IFieldsPtr ipFields; ipFeatureClass->get_Fields(&ipFields); //get IFields IFeatureDatasetNamePtr ipCurFeatureDatasetName(CLSID_FeatureDatasetName); IDatasetNamePtr ipNowDatasetName= ipCurFeatureDatasetName; ipNowDatasetName->putref_WorkspaceName(ipWorkspaceName); ipNowDatasetName->put_Name(_bstr_t((LPCTSTR)ipNowFeatureDatasetName.utf16())); //get OutputDatasetName IFeatureClassNamePtr ipCurrentFeatureClassName(CLSID_FeatureClassName); IDatasetNamePtr ipCurDatasetName = ipCurrentFeatureClassName; ipCurDatasetName->putref_WorkspaceName(ipWorkspaceName); ipCurDatasetName->put_Name(_bstr_t((LPCTSTR)ipNowFeatureClassName.utf16())); //get OutputFeatureClassName IEnumInvalidObjectPtr ipEnumValid; ipFeatureDataConvert->ConvertFeatureClass(ipCurFeatureClassName, ipQueryFilter, ipCurFeatureDatasetName, ipCurrentFeatureClassName, nullptr, ipFields, L"", 1000, 0, &ipEnumValid); if (ipEnumValid != nullptr) { return true; } else { return true; } return false; }
注释比较少 --大家理解一下