public static void Project(IFeatureDataset ifeatureDataset_0, ISpatialReference ispatialReference_0, IWorkspace iworkspace_0, string string_0) { IGeometryDef geometryDefClass = new GeometryDef(); ISpatialReference spatialReference = ((IGeoDataset)ifeatureDataset_0).SpatialReference; ((IGeometryDefEdit)geometryDefClass).SpatialReference_2 = ispatialReference_0; IWorkspace workspace = ifeatureDataset_0.Workspace; IFeatureDataConverter featureDataConverterClass = new FeatureDataConverter(); IWorkspaceName workspaceNameClass = new WorkspaceName() as IWorkspaceName as IWorkspaceName; workspaceNameClass.ConnectionProperties = workspace.ConnectionProperties; workspaceNameClass.WorkspaceFactoryProgID = workspace.WorkspaceFactory.GetClassID().Value.ToString(); IWorkspaceName connectionProperties = new WorkspaceName() as IWorkspaceName as IWorkspaceName; PropertySet propertySetClass = new PropertySet(); connectionProperties.ConnectionProperties = iworkspace_0.ConnectionProperties; connectionProperties.WorkspaceFactoryProgID = iworkspace_0.WorkspaceFactory.GetClassID().Value.ToString(); IDatasetName featureDatasetNameClass = new FeatureDatasetName() as IDatasetName; string name = ifeatureDataset_0.Name; int num = name.LastIndexOf("."); if (num != -1) { name = name.Substring(num + 1); } featureDatasetNameClass.Name = name; featureDatasetNameClass.WorkspaceName = workspaceNameClass; IDatasetName datasetName = new FeatureDatasetName() as IDatasetName; { datasetName.WorkspaceName = connectionProperties; datasetName.Name = string_0; } ; featureDataConverterClass.ConvertFeatureDataset((IFeatureDatasetName)featureDatasetNameClass, (IFeatureDatasetName)datasetName, geometryDefClass, "", 1000, 0); }
/// <summary> /// 将指定要素类复制到目标数据库中(在目标数据库中创建要素类) /// </summary> /// <param name="pSrcFC">源要素类</param> /// <param name="pQueryFilter">查询条件</param> /// <param name="pTargetWks">目标数据库</param> /// <param name="sMessage">转换消息</param> /// <param name="sTargetName">目标要素类名</param> /// <param name="sAlias">目标要素类别名</param> /// <param name="sFDatasetName">目标要素数据集</param> /// <returns></returns> public bool TranslateFeatureClass(IFeatureClass pSrcFC, IQueryFilter pQueryFilter, IWorkspace pTargetWks, string sTargetName = null, string sAlias = null, string sFDatasetName = null) { GeoDataUtils geoDataUtils = new GeoDataUtils(); IDataset pSrcDataset = pSrcFC as IDataset; IFeatureClassName pSrcName = pSrcDataset.FullName as IFeatureClassName; IFeatureDatasetName pFeatureDatasetName = null; if (pTargetWks.Type != esriWorkspaceType.esriFileSystemWorkspace) { string sFeatureDatasetName = sFDatasetName; if (string.IsNullOrEmpty(sFeatureDatasetName) && pSrcFC.FeatureDataset != null) { sFeatureDatasetName = geoDataUtils.ExtractDatasetName(pSrcFC.FeatureDataset.Name); } if (!string.IsNullOrEmpty(sFeatureDatasetName)) { if (geoDataUtils.IsNameExist(pTargetWks, sFeatureDatasetName, esriDatasetType.esriDTFeatureDataset)) { IFeatureDataset pTargetFeatureDataset = (pTargetWks as IFeatureWorkspace).OpenFeatureDataset(sFeatureDatasetName); pFeatureDatasetName = pTargetFeatureDataset.FullName as IFeatureDatasetName; Marshal.ReleaseComObject(pTargetFeatureDataset); } else { pFeatureDatasetName = new FeatureDatasetName() as IFeatureDatasetName; IDatasetName pDatasetName = pFeatureDatasetName as IDatasetName; pDatasetName.Name = sFeatureDatasetName; pDatasetName.WorkspaceName = (pTargetWks as IDataset).FullName as IWorkspaceName; } } } //目标要素类名 FeatureClassName pTargetName = new FeatureClassName(); IDatasetName pTargetDatasetName = pTargetName as IDatasetName; if (string.IsNullOrEmpty(sTargetName)) { sTargetName = geoDataUtils.ExtractDatasetName(pSrcDataset.Name); } pTargetDatasetName.Name = sTargetName; pTargetDatasetName.WorkspaceName = (pTargetWks as IDataset).FullName as IWorkspaceName; geoDataUtils.DeleteDataset(pTargetWks, pTargetDatasetName); // 验证字段 IFields pTargetFields; string sShapeFieldName; geoDataUtils.CheckFields(pSrcFC, pTargetWks, out pTargetFields, out sShapeFieldName); IEnumInvalidObject pEnumInvalidObject = null; IFeatureDataConverter pConverter = null; try { int iIndex = pTargetFields.FindField(sShapeFieldName); IGeometryDef pTargetGeometryDef = pTargetFields.get_Field(iIndex).GeometryDef; // 执行批量转换 pConverter = new FeatureDataConverter(); pEnumInvalidObject = pConverter.ConvertFeatureClass(pSrcName, pQueryFilter, pFeatureDatasetName as IFeatureDatasetName, pTargetName as IFeatureClassName, pTargetGeometryDef, pTargetFields, "", 1000, 0); // 检查转换过程中是否产生错误 if (pEnumInvalidObject != null) { IInvalidObjectInfo pInvalidInfo = null; pEnumInvalidObject.Reset(); while ((pInvalidInfo = pEnumInvalidObject.Next()) != null) { ErrorMessage += pSrcFC.AliasName + "图层要素:" + pInvalidInfo.InvalidObjectID + "执行失败!"; } } } finally //释放资源 { if (pEnumInvalidObject != null) { Marshal.ReleaseComObject(pEnumInvalidObject); } if (pConverter != null) { Marshal.ReleaseComObject(pConverter); } } //修改要素类别名 if (string.IsNullOrEmpty(sAlias)) { sAlias = pSrcFC.AliasName; } IFeatureClass pTargetFC = (pTargetWks as IFeatureWorkspace).OpenFeatureClass(sTargetName); geoDataUtils.AlterDatasetAlias(pTargetFC, sAlias); Marshal.ReleaseComObject(pTargetFC); return(true); }