Select to view content in your preferred language

Clip parameters issue (C#, AnalysisTools)

1736
2
04-09-2010 06:52 AM
by Anonymous User
Not applicable
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.
0 Kudos
2 Replies
AndrewEgleton
Deactivated User
Hi,

I'm having exactly the same problem, clip works fine with Feature Classes, but not with Feature Layers which I need to use as they have a selection. Did you ever solve this?

I've tried alot of the solutions to this I could find with Google from the old forums, and the problem is always the invalid parameter of the feature layer. 2 of the mehtods I've tried are copied in below.

 
Dim GP As ESRI.ArcGIS.Geoprocessing.IGeoProcessor
GP = New ESRI.ArcGIS.Geoprocessing.GeoProcessor
Dim Parameters As IVariantArray
Parameters = New VarArray
Parameters.Add(pClipFtrLyr)
Parameters.Add(pInLayer)
Parameters.Add(pOutFtrClsNmDS.WorkspaceName.PathName & "\" & pOutFtrClsNmDS.Name)
Try
GP.Execute("Clip_analysis", Parameters, Nothing)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Doh!")
End Try


second method tested:
 
Dim GP As ESRI.ArcGIS.Geoprocessor.Geoprocessor = New ESRI.ArcGIS.Geoprocessor.Geoprocessor()
GP.OverwriteOutput = True
GP.AddOutputsToMap = False
Dim pClipTool As ESRI.ArcGIS.AnalysisTools.Clip = New ESRI.ArcGIS.AnalysisTools.Clip
pClipTool.in_features = pClipFtrLyr
pClipTool.clip_features = pInLayer
pClipTool.out_feature_class = pOutFtrClsNmDS.WorkspaceName.PathName & "\" & pOutFtrClsNmDS.Name
Dim pResult As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult
pResult = CType(GP.Execute(pClipTool, Nothing), ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult)
If Not pResult Is Nothing Then
 Dim GPError As String = ""
 Dim ErrCount As Integer
 If GP.MessageCount > 0 Then
  For ErrCount = 0 To GP.MessageCount - 1
  GPError += (GP.GetMessage(ErrCount)) & vbNewLine
  Next
  MsgBox(GPError, MsgBoxStyle.OkOnly, "Failed")
 End If
Else
 Dim GPError As String = Nothing
 Dim ErrCount As Integer
 If GP.MessageCount > 0 Then
   For ErrCount = 0 To GP.MessageCount - 1
  GPError += (GP.GetMessage(ErrCount)) & vbNewLine
  Next
  MsgBox(GPError, MsgBoxStyle.OkOnly, "Failed")
 End If
End If
0 Kudos
ChristopherDresel
New Contributor
I did run into the same issue, after one hour of googling i found a solution. Have you tried setting a Layername?

IFeatureLayer featureLayer = new FeatureLayer();
featureLayer.FeatureClass = featureClass;
featureLayer.Name = featureLayer.FeatureClass.AliasName;

Adding a name to the FeatureLayer worked fine for me...

Alternatively you can try creating a layer via ESRI.ArcGIS.DataManagementTools.MakeFeatureLayer.

Greetz
0 Kudos