IMap.ClipGeometry can't work in arcobject10

1024
6
03-14-2011 12:14 AM
weskeralbert
New Contributor II
Hello!
I have install arcobjects10 for .net and arcdesktop 10,i want to make a tool that only show the area i want,so i use imap.ClipGeometry to do that,but i find it does not work ,nothing happens,is anybody has the same situation?
PS:it works at 9.3
Thanks
0 Kudos
6 Replies
RobinWolframe
New Contributor
We're finding the same issue upgrading our 9.3.1 code base to 10.  It compiles and executes without error, it just doesn't clip.
0 Kudos
ShiminCai
Occasional Contributor III
Hi,

I'm having the same problem and couldn't get it to work in Arc10. Have you found a solution for it?

Thanks,

Shimin Cai
0 Kudos
JohnHauck
Occasional Contributor II
I've not personally done any testing with this so I'm not aware of any workarounds right now. If you have support please contact ESRI Technical Support and get added to the report for this:

NIM066487: The sample provided in the ESRI Help documentation for IMap.ClipGeometry does not generate any output in ArcGIS 10.
0 Kudos
JohnHauck
Occasional Contributor II
I was looking at this and noticed a new interface called IMapClipOptions. It seems that IMapClipOptions.ClipType is the key, currently it defaults to esriMapClipNone. Please set the IMapClipOptions.ClipType to esriMapClipMapExtent and test your code again. The code provided with the NIM was in VBA. Here is a modified version of the code that successfully clips based on a selected graphic.


Sub ClipMapWithGraphic()
    Dim pMxDocument As IMxDocument
    Dim pMap As IMap
    Dim pViewManager As IViewManager
    Dim pEnumElement As IEnumElement
    Dim pElement As IElement
    Dim pActiveView As IActiveView
    Dim pBorder As IBorder
    Dim mco As IMapClipOptions
    
    Set pMxDocument = Application.Document
    Set pMap = pMxDocument.FocusMap
    
    Set pViewManager = pMap
    Set pEnumElement = pViewManager.ElementSelection
    pEnumElement.Reset
    Set pElement = pEnumElement.Next
    If pElement Is Nothing Then
        MsgBox "No element selected"
        Exit Sub
    End If
    If pElement.Geometry.GeometryType = esriGeometryPolygon Then
        Set pBorder = New SymbolBorder 'Use default line symbol
        Set mco = pMap
        mco.ClipType = esriMapClipMapExtent
        pMap.ClipBorder = pBorder
        pMap.ClipGeometry = pElement.Geometry
        Set pActiveView = pMap
        pActiveView.Refresh
    End If
End Sub
0 Kudos
by Anonymous User
Not applicable
Thanks John for the workaround tip!
-I had been working on this for Shimin, and sent a test case through to ESRI support, highlighting that this issue went beyond just the Help documentation, as implied by the subject header of NIM066487. Anyway, just tried your tip in my .Net  equivalent (included below), and it works a treat. (Needless-to-say the subject header for NIM066487 may need to be changed)
Thanks very much
Allison,
ESRI Australia

        Dim mxDoc As IMxDocument = m_application.Document
        Dim pMap As IMap = mxDoc.FocusMap
        Dim cliplayer As IFeatureLayer = pMap.Layer(0)
        'get the features in the clipLayer to construct a geometry to be assigned to the IMap.ClipGeometry
        Dim pFeatCursor As IFeatureCursor = cliplayer.Search(Nothing, False)
        Dim feature As IFeature = pFeatCursor.NextFeature
        'loop through the features to construct a geometry to be assigned ti the IMap:ClipGeometry
        Dim counter As Integer = 0
        Dim topoOperator As ITopologicalOperator
        Dim unionGeometry As IGeometry = Nothing
        While (feature) IsNot Nothing

            Dim geometry As ESRI.ArcGIS.Geometry.IGeometry = feature.Shape

            If (counter = 0) Then
                topoOperator = feature.ShapeCopy
                counter = counter + 1
            Else
                unionGeometry = topoOperator.Union(feature.ShapeCopy)
                topoOperator = CType(unionGeometry, ITopologicalOperator)

            End If
            feature = pFeatCursor.NextFeature
        End While
        Dim mco As IMapClipOptions = CType(pMap, IMapClipOptions) 
        mco.ClipType = esriMapClipType.esriMapClipMapExtent      
        If (unionGeometry) IsNot Nothing Then
            pMap.ClipGeometry = unionGeometry
        End If
        mxDoc.ActiveView.Refresh()
0 Kudos
GabrielaCastillo
New Contributor
Hi everybody!

I'm developing in arc engine and i try to programmer the clip tool in editing sesion and i try with your code but i have a problem when i try to refresh my map, because when i move the element selected for the clip all my map chenge to white and only keep my element selected and the clip that do.

Can you help me?

this is my code for the clip

    Public Sub ClipB()
        If pClipEditor.EditState = esriEngineEditState.esriEngineStateEditing Then
            pClipEnumFeature = TryCast(Principal.m_mapControl.Map.FeatureSelection, IEnumFeature)
            pFeatureClip = pClipEnumFeature.Next
            If pFeatureClip Is Nothing Then
                MsgBox(" Selecciona dos elementos ")
            Else
                Select Case pFeatureClip.Shape.GeometryType
                    Case esriGeometryType.esriGeometryPolygon
                        pPolygon = New Polygon
                        pPolygon = pFeatureClip.Shape  'QI
                        pGeometry = pPolygon
                        'pelement = New MarkerElement
                    Case esriGeometryType.esriGeometryPolyline
                        pPolyline = New Polyline
                        pPolyline = pFeatureClip.Shape 'QI
                        pGeometry = pPolyline
                        'pelement = New LineElement
                    Case esriGeometryType.esriGeometryPoint
                        pPoint = New Point
                        pPoint = pFeatureClip.Shape 'QI
                        pGeometry = pPoint
                        'pelement = New PolygonElement
                End Select

                Dim pgeometryenv As ESRI.ArcGIS.Geometry.IGeometry
                pgeometryenv = pFeatureClip.Shape

                'Verifica la opción elegida por el usuario
                If frmClip.rbnDescartar.Checked = True Then
                    If pFeatureClip.Shape.GeometryType = esriGeometryType.esriGeometryPolygon Then
                        pActiveviewClip = Principal.m_mapControl.ActiveView.FocusMap
                        pMap = Principal.m_mapControl.Map
                        pBorder = New SymbolBorder
                        mco = pMap
                        mco.ClipType = esriMapClipType.esriMapClipShape
                        pMap.ClipBorder = pBorder
                        pMap.ClipGeometry = pGeometry
                        pActiveviewClip = pMap
                        pActiveviewClip.Refresh()
                    End If
                End If
            End If
    End Sub

And after that in the map if i selected discard the clip in my pmap must be deleted and i selected preserve must be there but i can see all my map after click

If anyone knows of something that could help me or maybe I'm wrong and I could correct or if they have any tip or suggestion they are grateful.

thanks ...
0 Kudos