public void ConvertFeatureClassToShapefile()
{
//connect to sde
IWorkspaceFactory sourceWorkspaceFactory = new SdeWorkspaceFactoryClass();
IPropertySet connectionProps = new PropertySetClass();
connectionProps.SetProperty(INSTANCE, sde:oracle11g:ORCL_131);
connectionProps.SetProperty(user, sde);
connectionProps.SetProperty(password, sde);
connectionProps.SetProperty(VERSION, sde.DEFAULT);
var sourceWorkspace = sourceWorkspaceFactory.Open(connectionProps, 0) as IWorkspace;
IFeatureWorkspace feaws = sourceWorkspace as IFeatureWorkspace;
var sourceFeatureClass = feaws.OpenFeatureClass(SDE.sdetoshp) as IFeatureClass;
// Create a name object for the FGDB feature class and cast it to the IDatasetName interface.
IFeatureClassName targetFeatureClassName = new FeatureClassNameClass();
IDatasetName targetDatasetName = (IDatasetName)targetFeatureClassName;
targetDatasetName.Name = test6;
targetDatasetName.WorkspaceName = targetWorkspaceName;
// Create the objects and references necessary for field validation.
IFieldChecker fieldChecker = new FieldCheckerClass();
IFields sourceFields = sourceFeatureClass.Fields;
IFields targetFields = null;
IEnumFieldError enumFieldError = null;
// Set the required properties for the IFieldChecker interface.
fieldChecker.InputWorkspace = sourceWorkspace;
fieldChecker.ValidateWorkspace = targetWorkspace;
// Validate the fields and check for errors.
fieldChecker.Validate(sourceFields, out enumFieldError, out targetFields);
if (enumFieldError != null)
{
// Handle the errors in a way appropriate to your application.
Console.WriteLine(Errors were encountered during field validation.);
}
// Find the shape field.
String shapeFieldName = sourceFeatureClass.ShapeFieldName;
int shapeFieldIndex = sourceFeatureClass.FindField(shapeFieldName);
IField shapeField = sourceFields.get_Field(shapeFieldIndex);
// Get the geometry definition from the shape field and clone it.
IGeometryDef geometryDef = shapeField.GeometryDef;
IClone geometryDefClone = (IClone)geometryDef;
IClone targetGeometryDefClone = geometryDefClone.Clone();
IGeometryDef targetGeometryDef = (IGeometryDef)targetGeometryDefClone;
// Create a query filter to remove ramps, interstates and highways.
IQueryFilter queryFilter = new QueryFilterClass();
string whcl = SQBH=''2012滨海地条申字0001'';
queryFilter.WhereClause = whcl;
// Create the converter and run the conversion.
IFeatureDataConverter featureDataConverter = new FeatureDataConverterClass();
IEnumInvalidObject enumInvalidObject =
featureDataConverter.ConvertFeatureClass(sourceFeatureClassName,
queryFilter, null, targetFeatureClassName, targetGeometryDef, targetFields, , 1000, 0);
// Check for errors.
IInvalidObjectInfo invalidObjectInfo = null;
enumInvalidObject.Reset();
while ((invalidObjectInfo = enumInvalidObject.Next()) != null)
{
// Handle the errors in a way appropriate to the application.
Console.WriteLine(Errors occurred for the following feature: {0},
invalidObjectInfo.InvalidObjectID);
}
}
1 个回复
刘峥 - ArcGIS多面手
赞同来自:
用IFeatureDataConverter接口
要回复问题请先登录或注册