2 Replies Latest reply on May 7, 2012 5:44 AM by bruce.nielsen

    Buffering Multiple Polygon Features with ArcObjects 9.2

    bruce.nielsen
      I have a polygon layer (pLayer) in a project that is created with a Definition Query to a FeatureClass within a FeatureDataset in a Personal Geodatabase (.mdb). I am trying to use ArcObjects (9.2, Visual Studio 2005) to create a 1 mile buffer around the features in the layer. I'm having a problem with the following code:
              'Create a union-ed geometry of all of the features in the layer         Dim pFL2 As IFeatureLayer2 = pLayer         Dim pFClass As IFeatureClass = pFL2.FeatureClass         'Dim pFLD As IFeatureLayerDefinition = pFL2         'Dim pQF As IQueryFilter = New QueryFilter         'pQF.WhereClause = pFLD.DefinitionExpression         Dim pFCursor As IFeatureCursor = pFClass.Search(Nothing, True) 'Replace Nothing with pQF         Dim pFeature As IFeature = pFCursor.NextFeature         Dim pBag As IGeometryCollection = New GeometryBag         Do Until pFeature Is Nothing             pBag.AddGeometry(pFeature.Shape, , 0)             pFeature = pFCursor.NextFeature         Loop

      If the code is run as you see it now, it cycles through all of the features in the source featureclass, not just those defined by the definition query. If I try to use the definition query as a query filter (uncomment the 3 lines of code and change the search parameter from Nothing to pQF), it errors out on the Search with the message
      A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred...

      Any hints would be appreciated.
        • Re: Buffering Multiple Polygon Features with ArcObjects 9.2
          bruce.nielsen
          I took another look at this issue this morning, and after studying the Carto OMD (see attachment) realized that I should be able to simplify the code like this:
          Dim pFL2 As IFeatureLayer2 = pLayer
          Dim pFCursor As IFeatureCursor = pFL2.Search(Nothing, True)
          Dim pFeature As IFeature = pFCursor.NextFeature
          Dim pBag As IGeometryCollection = New GeometryBag
              Do Until pFeature Is Nothing
                  pBag.AddGeometry(pFeature.Shape, , 0)
                  pFeature = pFCursor.NextFeature
              Loop
          

          But the same error occurs during the Search assignment.

          Any ideas?
          [ATTACH=CONFIG]14129[/ATTACH]
          • Re: Buffering Multiple Polygon Features with ArcObjects 9.2
            bruce.nielsen
            ...More digging...

            The documentation on IFeatureLayer2::Search says:
            This Search method will not work on joined fields. If the FeatureLayer has any joins, you should use the IGeoFeatureLayer::SearchDisplayFeatures method instead.

            Success!

            Updated code:
            Dim pGFL As IGeoFeatureLayer = pLayer Dim pFCursor As IFeatureCursor = pGFL.SearchDisplayFeatures(Nothing, True)


            Hope this thread helps someone in the future.