I want to clip the features based on selected polygon.I have the two layers "suburban" and "lot". I want to clip features of lot layer based on selected polygon from suburban layer. I have tried manually in arc map 10.3 using Analaysis tools->Extract->Clip. It clipped lot features only which are underlying on selected polygons of suburban layer. But it's not working correctly when trying the same from ArcObjects .Net using geoprocessor interface.
selected polygon on suburb layer
It's not clipping the lot feature based on selected polygon of suburban layer.Instead of clipping the lot features based on all the polygon of the suburban layer.
Expected output:
I am also tried ITopologicalOperator QueryClipped functionality.It clip the features only in rectangular (envelop) size.It's not exactly clip the features based on irregular polygon boundary.
I am using the following code.
Private Sub lotClip(ByVal pInFClass As ESRI.ArcGIS.Geodatabase.IFeatureClass, ByVal clipGeometry As IGeometry, ByVal pClipFClass As ESRI.ArcGIS.Geodatabase.IFeatureClass, ByVal outputName As String)
Dim clipperGeo As New ESRI.ArcGIS.AnalysisTools.Clip
Dim Result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2
Try
Using releaser As New ESRI.ArcGIS.ADF.ComReleaser
releaser.ManageLifetime(clipperGeo)
clipperGeo.in_features = pInFClass
clipperGeo.clip_features = clipGeometry
clipperGeo.out_feature_class = outputName
Result = runClipTool(clipperGeo, Nothing)
If Result Is Nothing Then
System.Windows.Forms.MessageBox.Show("Could not clip dataset")
Exit Sub
End If
ReturnObjectfromResult(Result, "Feature Class")
End Using
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.ToString, "Clip error")
End Try
End Sub
Friend Function runClipTool(ByVal Process As ESRI.ArcGIS.Geoprocessor.IGPProcess, ByVal TC As ESRI.ArcGIS.esriSystem.ITrackCancel2) As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2
Dim Result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2
Dim GP As New ESRI.ArcGIS.Geoprocessor.Geoprocessor
Try
Result = CType(GP.Execute(Process, Nothing), ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2)
If Result.Status <> ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded Then returnMessages(Result, "Geoprocessing Error")
GP.ClearMessages()
Catch ex As Exception
returnMessages(Result, "Fail")
System.Windows.Forms.MessageBox.Show(ex.ToString, "Run Geoprocessor")
End Try
Return Result
End Function
Friend Sub ReturnObjectfromResult(ByVal result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2, ByVal Type As String)
Dim GPVal As ESRI.ArcGIS.Geodatabase.IGPValue
Dim InMemFC As String
Dim GPUtil As ESRI.ArcGIS.Geoprocessing.IGPUtilities3 = New ESRI.ArcGIS.Geoprocessing.GPUtilities
Dim pOutputFc As ESRI.ArcGIS.Geodatabase.IFeatureClass
Try
GPVal = result.GetOutput(0)
InMemFC = GPVal.GetAsText()
Select Case Type
Case "Feature Class"
pOutputFc = GPUtil.OpenFeatureClassFromString(InMemFC)
Case "Table"
GPUtil.OpenTableFromString(InMemFC)
End Select
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.ToString, "Return FeatureClass error")
End Try
End Sub
How do I clip the features based on an irregular polygon?
-
Pass in a FeatureLayer, these support Selections, not a FeatureClass.Hornbydd– Hornbydd2019年02月26日 15:17:09 +00:00Commented Feb 26, 2019 at 15:17
2 Answers 2
If you're already calling GP tools within your code, the easiest way to accomplish what your asking is to pass the result of the Select Layer By Attribute GP tool (or other selection tool) to the Clip GP tool. You will need to convert the "suburban" feature class to a feature layer first. The simple steps would be:
- Convert suburban feature class to feature layer
- Make selection on the suburban feature layer
- Pass the result of the selection to the Clip tool as the clipping geometry
The Clip tool should work, but I too have seen it not work correctly, even with the use of FeatureLayers. If Clip isn't behaving, my process is the following:
- Get the clipping geometry and cast as ITopologicalOperator
- Loop through the features will be clipped
- Use ITopological.Intersect to get the clipped geometry (Use intersect)
- If the returned geometry is empty/null, then your feature completely outside the clipping boundary.
-
Get the selected clip feature from pClipFClass with the IFeatureSelection interface, cursor and Union the clipping geometries with ITopologicalOperator for the final clip geometry and put it into an ISpatialFilter to select the lots from pInFClass with Search then this all works good... doing it this way means not processing geometries that have no spatial relationship with the clip which should be quicker provided the clip geometry doesn't cover almost all features to be clipped, but there's no way to tell that before running the Search.Michael Stimson– Michael Stimson2019年02月27日 04:17:39 +00:00Commented Feb 27, 2019 at 4:17