Hi there,When I use AnalysisTools.Clip to clip a layer (feature class) in C# programming, I found that it didn't work when I specified the in_features and clip_features with IFeatureLayer. It worked when I specified the parameters with IFeatureClass. However, it works in ArcMap with ArcMap Layers. I want to use FeatureLayer because I want to apply some selection on layer (especially for clip_features). Otherwise, I have to use "select" tool to generate a middle shapefile. This code works:
IFeatureClass fcInFeatures = sdeWorkspace.OpenFeatureClass("SDE_DEVL.DBO.SdeHydro");
IFeatureClass fcClipFeatures = sdeWorkspace.OpenFeatureClass("SDE_DEVL.DBO.SdeTownship");
clip.in_features = fcInFeactures;
clip.clip_features = fcClipFeatures;
clip.out_features = @c:\temp\clip_test.shp;
gp.execute(clip, null);
But this didn't work with IFeatureLayer:
IFeatureClass fcInFeatures = sdeWorkspace.OpenFeatureClass("SDE_DEVL.DBO.SdeHydro");
IFeatureClass fcClipFeatures = sdeWorkspace.OpenFeatureClass("SDE_DEVL.DBO.SdeTownship");
IFeatureLayer flClipFeatures = new FeatureLayerClass();
flClipFeatures.FeatureClass = fcClipFeatures;
IFeatureSelection fsClipFeatures = flClipFeatures as IFeatureSelection;
IQueryFilter qfClipper = new QueryFilterClass();
qfClipper.where_clause = "Mrt = 411039";
fsClipFeatures.SelectFeatures(qfClipper, esriSelectionResultEnum.esriSelectionResultNew, false);
log.DebugFormat("There are {0} township(s) used to clip aggrements. ", fsTownship.SelectionSet.Count); //check the select result, it is ok, only one feature selected.
clip.in_features = fcInFeactures;
clip.clip_features = flClipFeatures; // this didn't work
clip.out_features = @c:\temp\clip_test.shp;
gp.execute(clip, null);
It reported "Invalid parameters".Does anyone work with this situation? Any suggestions?Thanks a lot.