4

How to flash many features at same time in ArcMap using C# coding?

Currently I call this function in a loop,

private void FlashFeature(IActiveView _activeView, IFeature _feature)
{
    IActiveView activeView = _activeView;
    IFeatureIdentifyObj featIdentify = new FeatureIdentifyObject();
    featIdentify.Feature = _feature;
    IIdentifyObj identify = featIdentify as IIdentifyObj;
    identify.Flash(activeView.ScreenDisplay);
}

but unfortunately it flashes one feature at a time, and while flashing is happening it holds the process. As a result of that it flashes around 2 features in a second, instead of them all at once. I also want to flash thous features without changing my curent feature selection in map, if posable. The default ArcMap Find tool(form or whatever it is) can do it, and i'm trying to find a way to implement that in my tool.

  • I removed my answer--so many stupid things in that class that I decided to drop it. One of the issues that I had was when I was flashing coincident geometries, their symbols would cancel each other out (due to the esriROPNotXOrPen raster operation). So it looked like it was doing nothing (had me stumped for quite a while). Also, I found this: help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/… which I think I used when I built my class. It might be better to start with it and tweak it to handle multiple geoms. – Jay Cummins Aug 2 '12 at 14:03
5

Please see my customized flash routine in the answer to this question: ESRI Flash Command in custom code

I think this will work for you as it accepts GeometryBags along with Polygon, Polyline, Point and Multipoint geometries. It does not union the geometries but draws each one individually.

Alternatively you might try adding the geometries to an array and using IHookActions.DoActionOnMultiple as in this sample.

  • Tried your first solution, and it works great. In a matter of fact "Jay Cummins" answer(which he removed) was actually working as well, but I forgot to zoom out to check if its drawing somewhere else(whick is currently happening in this case as well). I'm probably missing some SpatialReference somewhere. About flashing - its done, works like a charm! – Sunder Aug 3 '12 at 7:09
  • Good to hear. If it's not on the screen obviously it won't flash, but the built-in Identify tool does a nifty crosshairs effect so you can see "something" happen even if it's off-screen. I haven't yet figured out how to replicate that. – blah238 Aug 3 '12 at 21:34
2

The method I used in one of my add-ins was to put all the features into a GeometryBag and use ITopologicalOperator::ConstructUnion to merge it into a single geometry. I passed this geometry into the FlashGeometry snippet.

Here's how I did it (in VB.NET). In my case, I was using an IQueryFilter to make the selection of features (either polygons or polylines) to flash

    Dim pFCursor As ESRI.ArcGIS.Geodatabase.IFeatureCursor
    Dim pFeature As ESRI.ArcGIS.Geodatabase.IFeature
    Dim pGeometry As ESRI.ArcGIS.Geometry.IGeometry
    Dim pGeometryBag As ESRI.ArcGIS.Geometry.IGeometryCollection = New ESRI.ArcGIS.Geometry.GeometryBag
    Dim pPolygon As ESRI.ArcGIS.Geometry.IPolygon
    Dim pPolyline As ESRI.ArcGIS.Geometry.IPolyline
    Dim pQFilter As New ESRI.ArcGIS.Geodatabase.QueryFilter
    Dim pRgbColor As New ESRI.ArcGIS.Display.RgbColor
    Dim pTopoOp As ESRI.ArcGIS.Geometry.ITopologicalOperator4

    Using releaser As New ESRI.ArcGIS.ADF.ComReleaser
       releaser.ManageLifetime(pFCursor)

       pQFilter.WhereClause = [String].Format("{0} in ({1})", pFClass.OIDFieldName, sender.Rows(e.RowIndex).Cells("colAdjacentOIDs").value)
       pFCursor = pFClass.Search(pQFilter, True)
       pFeature = pFCursor.NextFeature

       Do Until pFeature Is Nothing
           pGeometryBag.AddGeometry(pFeature.ShapeCopy)
           pFeature = pFCursor.NextFeature
       Loop

       Select Case pFClass.ShapeType
           Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon
                pTopoOp = New ESRI.ArcGIS.Geometry.Polygon
                pTopoOp.ConstructUnion(pGeometryBag)
                pPolygon = pTopoOp
                pGeometry = pPolygon
           Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline
                pTopoOp = New ESRI.ArcGIS.Geometry.Polyline
                pTopoOp.ConstructUnion(pGeometryBag)
                pPolyline = pTopoOp
                pGeometry = pPolyline
       End Select

       pRgbColor.Red = 255

       FlashGeometry(pGeometry, pRgbColor, My.ArcMap.Document.ActiveView.ScreenDisplay, 500)
   End Using


Public Sub FlashGeometry(ByVal geometry As ESRI.ArcGIS.Geometry.IGeometry, ByVal color As ESRI.ArcGIS.Display.IRgbColor, ByVal display As ESRI.ArcGIS.Display.IDisplay, ByVal delay As System.Int32)

    If geometry Is Nothing OrElse color Is Nothing OrElse display Is Nothing Then
        Return
    End If

    display.StartDrawing(display.hDC, CShort(ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache))

    Select Case geometry.GeometryType
        Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon

            'Set the flash geometry's symbol.
            Dim simpleFillSymbol As ESRI.ArcGIS.Display.ISimpleFillSymbol = New ESRI.ArcGIS.Display.SimpleFillSymbolClass
            simpleFillSymbol.Color = color
            Dim symbol As ESRI.ArcGIS.Display.ISymbol = TryCast(simpleFillSymbol, ESRI.ArcGIS.Display.ISymbol) ' Dynamic Cast
            symbol.ROP2 = ESRI.ArcGIS.Display.esriRasterOpCode.esriROPNotXOrPen

            'Flash the input polygon geometry.
            display.SetSymbol(symbol)
            display.DrawPolygon(geometry)
            System.Threading.Thread.Sleep(delay)
            display.DrawPolygon(geometry)
            Exit Select

        Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline

            'Set the flash geometry's symbol.
            Dim simpleLineSymbol As ESRI.ArcGIS.Display.ISimpleLineSymbol = New ESRI.ArcGIS.Display.SimpleLineSymbolClass
            simpleLineSymbol.Width = 4
            simpleLineSymbol.Color = color
            Dim symbol As ESRI.ArcGIS.Display.ISymbol = TryCast(simpleLineSymbol, ESRI.ArcGIS.Display.ISymbol) ' Dynamic Cast
            symbol.ROP2 = ESRI.ArcGIS.Display.esriRasterOpCode.esriROPNotXOrPen

            'Flash the input polyline geometry.
            display.SetSymbol(symbol)
            display.DrawPolyline(geometry)
            System.Threading.Thread.Sleep(delay)
            display.DrawPolyline(geometry)
            Exit Select

        Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint

            'Set the flash geometry's symbol.
            Dim simpleMarkerSymbol As ESRI.ArcGIS.Display.ISimpleMarkerSymbol = New ESRI.ArcGIS.Display.SimpleMarkerSymbolClass
            simpleMarkerSymbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle
            simpleMarkerSymbol.Size = 12
            simpleMarkerSymbol.Color = color
            Dim symbol As ESRI.ArcGIS.Display.ISymbol = TryCast(simpleMarkerSymbol, ESRI.ArcGIS.Display.ISymbol) ' Dynamic Cast
            symbol.ROP2 = ESRI.ArcGIS.Display.esriRasterOpCode.esriROPNotXOrPen

            'Flash the input point geometry.
            display.SetSymbol(symbol)
            display.DrawPoint(geometry)
            System.Threading.Thread.Sleep(delay)
            display.DrawPoint(geometry)
            Exit Select

        Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultipoint

            'Set the flash geometry's symbol.
            Dim simpleMarkerSymbol As ESRI.ArcGIS.Display.ISimpleMarkerSymbol = New ESRI.ArcGIS.Display.SimpleMarkerSymbolClass
            simpleMarkerSymbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle
            simpleMarkerSymbol.Size = 12
            simpleMarkerSymbol.Color = color
            Dim symbol As ESRI.ArcGIS.Display.ISymbol = TryCast(simpleMarkerSymbol, ESRI.ArcGIS.Display.ISymbol) ' Dynamic Cast
            symbol.ROP2 = ESRI.ArcGIS.Display.esriRasterOpCode.esriROPNotXOrPen

            'Flash the input multipoint geometry.
            display.SetSymbol(symbol)
            display.DrawMultipoint(geometry)
            System.Threading.Thread.Sleep(delay)
            display.DrawMultipoint(geometry)
            Exit Select

    End Select

    display.FinishDrawing()

End Sub
  • I were already considering this, and your suggestion seems like a valid solution if you'r dealing with one type of geometries. The drawback is that it can't functionate with different kind of geometries because you cant merge points, polylines and polygons in single geometry... or can it? In worst case I can flash them in order - first points, then polylines, etc. I'll replay my results on this matter tomorrow. – Sunder Aug 2 '12 at 15:07
  • In the end I sticked with blah238 answer. As it is more viable in my case. – Sunder Aug 3 '12 at 7:12
  • What is FlashGeometry(....) in above code? – user98848 Jun 9 '17 at 15:30
  • Added that function to the code – kenbuja Jun 9 '17 at 19:57

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.