比如,将某一shp文件中面积大于某值的图斑查找出,然后另存为一个新的shp文件 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;
|