在这里感谢 “端木飘零”
procedure ConvertFeatureClassToShapesFile(pFeatureClass: IFeatureClass; pFilePath, pFileName: string);
var
pInDataSet, pOutDataSet: IDataSet;
pInWorkSpace: IWorkSpace;
pInFeatureClassName, pOutFeatureClassName: IFeatureClassName;
pOutWorkspaceFactory: IWorkspaceFactory;
pOutWorkerspace: IFeatureWorkspace;
pOutWorkspaceName: IWorkspaceName;
pOutDataSetName: IDatasetName;
pFieldChecker: IFieldChecker;
pEnumFieldError: IEnumFieldError;
pOutFields: IFields;
pFeatureDataConvert: IFeatureDataConverter;
pQueryFilter: IQueryFilter;
pSpatialFilter: ISpatialFilter;
pFeature: IFeature;
begin
if pFeatureClass = nil then
begin
exit;
end;
//得到输入
pInDataSet := pFeatureClass as IDataSet;
pInWorkSpace := pInDataSet.Workspace;
pInFeatureClassName := pInDataSet.FullName as IFeatureClassName;
//定义输出
pOutWorkspaceFactory := CoShapefileWorkspaceFactory.create as IWorkspaceFactory;
pOutWorkerspace := pOutWorkspaceFactory.OpenFromFile(pFilePath, 0) as IFeatureWorkspace;
pOutDataSet := pOutWorkerspace as IDataset;
pOutWorkspaceName := pOutDataSet.FullName as IWorkspaceName;
pOutFeatureClassName := coFeatureClassName.Create as IFeatureClassName;
pOutDataSetName := pOutFeatureClassName as IDatasetName;
pOutDataSetName.Name := pFileName;
pOutDataSetName.WorkspaceName := pOutWorkspaceName;
//检查字段
pFieldChecker := coFieldChecker.Create as IFieldChecker;
pFieldChecker.InputWorkspace := pInWorkSpace;
pFieldChecker.ValidateWorkspace := pOutWorkerspace as IWorkspace;
pFieldChecker.Validate(pFeatureClass.Fields, pEnumFieldError, pOutFields);
//要素筛选
pQueryFilter := coQueryFilter.Create as IQueryFilter;
pQueryFilter.WhereClause := '';
//转换输出
pFeatureDataConvert := coFeatureDataConverter.Create as IFeatureDataConverter;
pFeatureDataConvert.ConvertFeatureClass(pInFeatureClassName, pQueryFilter, nil, pOutFeatureClassName, nil, pOutFields, '', 100, 0);
end;