When the input to the following method is a feature class on disk the geoprocessor gives the expected results. However, when I pass in a feature class that is created via arcobjects to an in_memory workspace then I get either a result with no features or only a few of the clipped features. The clip_features input has only one polygon and it is in the same spatial reference as the in_features to be clipped.

private void ClipFeatures(string fileNameAndPath, ref IFeatureClass inMemPolyFc)
        Geoprocessor gp = new Geoprocessor();
        Clip clip = new Clip();
        clip.clip_features = inMemPolyFc;
        clip.in_features = fileNameAndPath;
        clip.out_feature_class = @"in_memory\clippedFile";
        gp.OverwriteOutput = true;
        gp.AddOutputsToMap = true;

            gp.Execute(clip, null);
        catch (Exception)
            string gpError = getGPMessages(gp);
            MessageBox.Show(@"A geoprocessing error occurred: " + Environment.NewLine + Environment.NewLine + gpError,

The gp executes sucessfully with the in_memory fc but the results are wrong. After creating the in_memory fc via arcobjects I added it the map during debugging and it appears correctly in the map document. Is this a bug in the gp tool?

  • Are you simplifying the inmemory polygon? Sometimes writing to disk does a simplify on it without you realizing it. – Kirk Kuykendall Jan 17 '13 at 19:28
  • There seems to be something wrong with my polygon. Although it appears correct after adding it to the map, it has incorrect values for shape_area and shape_length. – Rich Wawrzonek Jan 17 '13 at 19:46
  • arcmap might be projecting it on the fly ... when it does that it will display in the correct location, but arcmap is not smart enough to dynamically update the shape_area and shape_length to reflect projected values. – Kirk Kuykendall Jan 17 '13 at 21:10
  • Turns out the problem is related to not simplifying my polygon. The source polygon comes from an INewPolygonFeedback object. Calling SimplifyPreserveFromTo() on it before adding to the in_memory feature class fixes the problem. Thanks Kirk, if you post your suggestion as an answer I can give you credit. – Rich Wawrzonek Jan 18 '13 at 1:35

Try simplifying your polygon before running the clip. This can be done be setting ITopologicalOperator2.IsKnownSimple = false

And then calling ITopologicalOperator2.Simplify(). (Also apparently SimplifyPreserveFromTo() works, as you indicate in the comment, but I've never tried that).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.