Hi,
How can I insert (or copy, move) features from one featureclass to another with original attributes?
I have two featureclasses, and both of them have same fields.
I want to select part of Featureclass A, then move those selected features to FeatureClass B, with their attributes.
I can do move operations, but it loose all attributes.
How can I do this?
Thank you
Insu
private void copyfeatures(IFeatureLayer FromFeatureLayer, IFeatureLayer ToFeatureLayer) { //take selected features IFeatureSelection pFeatureSelection = FromFeatureLayer as IFeatureSelection; ICursor pFromCursor = null; if (pFeatureSelection.SelectionSet.Count > 1) { //get selected features to cursor pFeatureSelection.SelectionSet.Search(null, false, out pFromCursor); IFeatureCursor pFromFCursor = pFromCursor as IFeatureCursor; IFeature pFeatureFrom = null; //loop selected features while ((pFeatureFrom = pFromFCursor.NextFeature())!=null) { //create new feature IFeature pFeatureToNew = ToFeatureLayer.FeatureClass.CreateFeature(); //assign shape + attributes (Schema should be exactly same) pFeatureNew.Shape = pFeatureFrom.Shape; for (int i = 0; i < pFeatureNew.Fields.FieldCount; i++) { if (pFeatureNew.Fields.get_Field(i).Editable) { pFeatureNew.set_Value(i, pFeatureFrom.get_Value(i)); } } //store it. pFeatureToNew.Store(); } } }