从FileGDB导出shp

//Create inworkspace name.
            ESRI.ArcGIS.esriSystem.IPropertySet propertySet = new ESRI.ArcGIS.esriSystem.PropertySetClass();
            propertySet.SetProperty("DATABASE",@"J:/work/xingshan.gdb");
            IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
            IWorkspace wSpace=workspaceFactory.Open(propertySet,0);
            IDataset inWorkspaceDataset = (IDataset)wSpace;
            IWorkspaceName inWorkspaceName = (IWorkspaceName)inWorkspaceDataset.FullName;

            // Set in dataset and feature class names.
            IFeatureClassName inFeatureClassName = new FeatureClassNameClass();
            IDatasetName inDatasetName = (IDatasetName)inFeatureClassName;
            inDatasetName.WorkspaceName = inWorkspaceName;
            inDatasetName.Name = "高切坡";

            //Create outworkspace name.
            IWorkspaceFactory2 workspaceFactory2;
            workspaceFactory2 = (IWorkspaceFactory2)new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
            IWorkspaceName worName = workspaceFactory2.Create("j://","targetDirectory",null,0);           //j:/targetDirectory为生成shp的目标文件夹,写成workspaceFactory2.Create(",""j://targetDirectory",null,0);貌似也可以
            ESRI.ArcGIS.esriSystem.IName name = (ESRI.ArcGIS.esriSystem.IName)worName;
            IWorkspace wSpace2 = (IWorkspace)name.Open();            
            IDataset outWorkspaceDataset = (IDataset)wSpace2;
            IWorkspaceName outWorkspaceName = (IWorkspaceName)outWorkspaceDataset.FullName;

            // Set out dataset and feature class names.
            IFeatureClassName outFeatureClassName = new FeatureClassNameClass();
            IDatasetName outDatasetName = (IDatasetName)outFeatureClassName;
            outDatasetName.WorkspaceName = outWorkspaceName;
            outDatasetName.Name = "ctgFeatureshp_out.shp";

            //Open input Featureclass to get field definitions.
            IName inName = (IName)inFeatureClassName;
            IFeatureClass inFeatureClass = (IFeatureClass)inName.Open();

            //Validate the field names.
            IFieldChecker fieldChecker = new FieldCheckerClass();
            IFields outFeatureClassFields;
            IFields inFeatureClassFields = inFeatureClass.Fields;
            IEnumFieldError enumFieldError;
            fieldChecker.InputWorkspace = wSpace;
            fieldChecker.ValidateWorkspace = wSpace2;

            // Validate the fields.
            fieldChecker.Validate(inFeatureClassFields,out enumFieldError,out outFeatureClassFields);

            // Set up the geometry definition.
            IField geometryField;
            geometryField = outFeatureClassFields.get_Field(outFeatureClassFields.FindField(inFeatureClass.ShapeFieldName));
            // Get the geometry field's geometry definition.
            IGeometryDef geometryDef = geometryField.GeometryDef;

            //Set up the IQueryFilter to convert all the features by leaving a blank WhereClause
            QueryFilter qf = new QueryFilterClass();
            qf.WhereClause = "";

            //Load the feature class
            IFeatureDataConverter fctofc = new FeatureDataConverterClass();
            IEnumInvalidObject enumErrors = fctofc.ConvertFeatureClass(inFeatureClassName,qf,null,outFeatureClassName,geometryDef,outFeatureClassFields,"",1000,0);

你可能感兴趣的:(从FileGDB导出shp)