I'm trying to import a shapefile into a featuredataset under a geodatabase using FeatureDataConverter.ConvertFeatureClass. All the examples that I found are not concerning the import under an existing featuredataset. I checked that the spatial reference it's the same and the domain it's enough big to contain the features. When I try to run stop at featureDataConverter.ConvertFeatureClass and exit with out any information.
...
ISpatialReferenceFactory srFactory = new SpatialReferenceEnvironmentClass();
Int32 EPGS = 25832;
ISpatialReference spatialReference = (srFactory as ISpatialReferenceFactory4).CreateSpatialReference((int) EPGS);
IEnvelope envelope = RvrFtrLyr.AreaOfInterest;
spatialReference.SetDomain(envelope.XMin-1000, envelope.XMax+1000, envelope.YMin-1000, envelope.YMax+1000);
IFeatureDataset targetFeatureDataset = coreEngine.CreateFeatureDataset(targetWS, "Rivers", spatialReference);
coreEngine.FeatureLoader(targetFeatureDataset, "Lines", RvrFtrClsSHP);
...
internal void FeatureLoader(IFeatureDataset targetFDS, String name, IFeatureClass sourceFeatureClass)
{
//Source feature
IDataset sourceDataset = (IDataset)sourceFeatureClass;
IWorkspace sourceWS = (IWorkspace)sourceDataset.Workspace;
IFeatureClassName sourceFtrClsName = (IFeatureClassName)sourceDataset.FullName;
//Target feature
ESRI.ArcGIS.esriSystem.UIDClass clsid = new ESRI.ArcGIS.esriSystem.UIDClass();
clsid.Value= "esriGeoDatabase.Feature";
IFeatureClass ftrCl = targetFDS.CreateFeatureClass(name, sourceFeatureClass.Fields, clsid, null, esriFeatureType.esriFTSimple, "Shape", null);
IDataset dataset = (IDataset)ftrCl;
IFeatureClassName trgFCN = (IFeatureClassName)dataset.FullName;
IFeatureDatasetName trgFDN = (IFeatureDatasetName)trgFCN.FeatureDatasetName;
IFieldChecker fieldChecker = new FieldCheckerClass();
IFields sourceFields = sourceFeatureClass.Fields;
IFields targetFields = null;
IEnumFieldError enumFieldError = null;
fieldChecker.InputWorkspace = sourceWS;
fieldChecker.ValidateWorkspace = targetFDS.Workspace;
fieldChecker.Validate(sourceFields, out enumFieldError, out targetFields);
if (enumFieldError != null)
{
Console.WriteLine("Error in fields validation");
}
String shapeFieldName = sourceFeatureClass.ShapeFieldName;
Int32 shapeFieldIndex = sourceFeatureClass.FindField(shapeFieldName);
IField shapeField = sourceFields.get_Field(shapeFieldIndex);
IGeometryDef geometryDef = shapeField.GeometryDef;
IClone geometryDefClone = (IClone)geometryDef;
IClone targetGeometryDefClone = geometryDefClone.Clone();
IGeometryDef targetGeometryDef = (IGeometryDef)targetGeometryDefClone;
IFeatureDataConverter featureDataConverter = new FeatureDataConverterClass();
IEnumInvalidObject enumInvalidObject = featureDataConverter.ConvertFeatureClass(sourceFtrClsName, null, trgFDN, trgFCN, targetGeometryDef, targetFields, "", 1000, 0);
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 Answer 1
I see in your code you create the target featureclass. So you basically have your target data model set up you just want to copy in the shapefile as new Feature, right? You could try to use the IDataExtraction Interface instead of FeatureDataConverter. Its extract method takes an IReplicaDescription as parameter. This has a init method where you can set a flag "ReuseSchema". Then it might work with existing datasets at the target.
-
Hi Chris, may be I wasn't so clear, what I want to do it's just import a shape file inside a file geodatabase. But inside this geoDB I've a feature dataset and I want that my imported features go inside this. I checked your solution but on the help they say that you can use IDataExtraction to copy data between personal and file geodatabases.Cursore– Cursore2013年11月22日 07:49:31 +00:00Commented Nov 22, 2013 at 7:49