zerelli

DXF->shape error!! help please !!

Discussion created by zerelli on Oct 13, 2011
Latest reply on Nov 16, 2011 by qemmal
HI!!
i have a problem with ConvertFeatureClass(..) , i have Error "Open featureclass failed"
i Need a help please about this methode! why i have this error ?


*****************
this is my code        *
*****************
----------------------------------------------------------------------------------------------
private void Conversion2(string fileName, string currentView, string alias)
{
string nom_repertoire = System.IO.Path.GetDirectoryName(fileName);
string nom_fichier = System.IO.Path.GetFileName(fileName);
String targetWorkspacePath = Environment.CurrentDirectory;

int Count;

IWorkspaceFactory pCadWKSFact = new CadWorkspaceFactory();
IWorkspaceFactory targetWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
IFeatureWorkspace pWorkspace = (IFeatureWorkspace)pCadWKSFact.OpenFromFile(nom_repertoire, 0);
IWorkspace targetWorkspace = (IWorkspace)targetWorkspaceFactory.OpenFromFile(targetWorkspacePath, 0);
IWorkspace sourceWorkspace = (IWorkspace)pCadWKSFact.OpenFromFile(nom_repertoire, 0);
//IFeatureDataConverter_ConvertFeatureClass_Example(sourceWorkspace, targetWorkspace, "DXFfeatureclass", "shapefeatureclass");
IFeatureWorkspace targetFeatureWorkspace = (IFeatureWorkspace)targetWorkspaceFactory.OpenFromFile(targetWorkspacePath, 0);
IFeatureDataset pFeatureDataset = pWorkspace.OpenFeatureDataset(nom_fichier);
// IFeatureDataset targetFeatureWorkspaceDataset = (IFeatureDataset)targetFeatureWorkspace;
IDataset targetWorkspaceDataset = (IDataset)targetWorkspace;
IDataset sourceWorkspaceDataset = (IDataset)sourceWorkspace;
IName sourceWorkspaceDatasetName = sourceWorkspaceDataset.FullName;
IName targetWorkspaceDatasetName = targetWorkspaceDataset.FullName;
IWorkspaceName sourceWorkspaceName = (IWorkspaceName)sourceWorkspaceDatasetName;
IWorkspaceName targetWorkspaceName = (IWorkspaceName)targetWorkspaceDatasetName;
IFeatureClassContainer pFeatureClassContainer = (IFeatureClassContainer)pFeatureDataset;
// Create a name object for the shapefile and cast it to the IDatasetName interface.
IFeatureClassName sourceFeatureClassName = new FeatureClassNameClass();
IDatasetName sourceDatasetName = (IDatasetName)sourceFeatureClassName;
sourceDatasetName.Name = "streets";
sourceDatasetName.WorkspaceName = sourceWorkspaceName;

// Create a name object for the DXF feature class and cast it to the IDatasetName interface.
IFeatureClassName targetFeatureClassName = new FeatureClassNameClass();
IDatasetName targetDatasetName = (IDatasetName)targetFeatureClassName;
targetDatasetName.Name = "AtlantaStreets";
targetDatasetName.WorkspaceName = targetWorkspaceName;
IFeatureClass pFeatureClass;

// Conversion(fileName, currentView, alias);
for (Count = 0; Count < pFeatureClassContainer.ClassCount - 1; Count++)
{
pFeatureClass = pFeatureClassContainer.get_Class(Count);
// Create the objects and references necessary for field validation.
IFieldChecker fieldChecker = new FieldCheckerClass();
IFields sourceFields = pFeatureClass.Fields;
IFields targetFields = null;
IEnumFieldError enumFieldError = null;

// Set the required properties for the IFieldChecker interface.
fieldChecker.InputWorkspace = (IWorkspace) pWorkspace ;
fieldChecker.ValidateWorkspace = (IWorkspace) targetFeatureWorkspace;

// 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.");
}
// Loop through the output fields to find the geomerty field
IField geometryField;
for (int i = 0; i < targetFields.FieldCount; i++)
{
if (targetFields.get_Field(i).Type == esriFieldType.esriFieldTypeGeometry)
{
geometryField = targetFields.get_Field(i);
// Get the geometry field's geometry defenition
IGeometryDef geometryDef = geometryField.GeometryDef;

//Give the geometry definition a spatial index grid count and grid size
IGeometryDefEdit targetFCGeoDefEdit = (IGeometryDefEdit)geometryDef;

targetFCGeoDefEdit.GridCount_2 = 1;
targetFCGeoDefEdit.set_GridSize(0, 0); //Allow ArcGIS to determine a valid grid size for the data loaded
targetFCGeoDefEdit.SpatialReference_2 = geometryField.GeometryDef.SpatialReference;

// we want to convert all of the features
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.WhereClause = "";

// Load the feature class
IFeatureDataConverter fctofc = new FeatureDataConverterClass();
IEnumInvalidObject enumErrors = fctofc.ConvertFeatureClass(sourceFeatureClassName, queryFilter, null, targetFeatureClassName, geometryDef, targetFields, "", 1000, 0);:confused:
break;
}
}

}

}
-----------------------------------------------------------------------------------------

Outcomes