3

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);
 }
 }
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 21, 2013 at 10:44

1 Answer 1

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.

IDataExtraction ArcObjects SDK 10

answered Nov 21, 2013 at 12:12
1
  • 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. Commented Nov 22, 2013 at 7:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.