AnsweredAssumed Answered

Copy a feature.shpe to another FeatureClass - Not right one

Question asked by shaningesri on Jul 19, 2017
Latest reply on Jul 19, 2017 by shaningesri

I have an ArcObjects project.  In this project, FeatureClass Source (termed as fc_Source here) is compared with FeatureClass Target (termed as fc_Target).  The general logic is described below:

1)  Loop through fc_Source, get a feature, termed featureS.

2)  Check if the featureS. exists (or overlaps with a feature in fc_Target.

3)  If the return is true on 2), set featureS as fc_Source.NextFeature.  If the return is false in 2), featureS will be inserted into fc_Target, and then set featureS as fc_Source.NextFeature till all of the features in fc_Sourceare looped through.

In 3)'s Inserting a feature into fc_Target, I got such problem: the feature inserted does carry the featureS values but NOT its right geometry.  The inserted one's geometry is actually the NextFeature of fc_Source.  The simplified related code is below.

What is wrong in my code?  I do wish someone can point out.  Thanks a LOT.

 

            // Loop though fc_Source

                featCursor = fc_Source.Search(qfQuery, true); 
                IFeature featureS = featCursor.NextFeature();

                // Loop featureS though fc_Target.  If found featureT != null; else Not Fount, featureT = null;

                IFeature featureT = getFeature_GeometryCompare(featureS, fc_Target);

              while ( featureS != null)  {

                    if (featureT != null) {

                        ...

                    } else  {  

                       featureT = Assign_TargetFeature(featureS, fc_Target);

                       featureT.Store();

                    }

                    featureS = featCursor.NextFeature();

                }

 

//  "Assign Geometry & Values"
        IFeature Assign_TargetFeature(IFeature f_Source, IFeatureClass fc_Target) {

            IFeature f_Target = fc_Target.CreateFeature();
            f_Target.Shape = f_Source.Shape;

            // Assign values

            ......

            return f_Target;

        }

Outcomes