+ Reply to Thread
Results 1 to 3 of 3

Thread: Buffering Multiple Polygon Features with ArcObjects 9.2

  1. #1
    Bruce Nielsen
    Join Date
    Jan 2011
    Posts
    299
    Points
    130
    Answers Provided
    21


    0

    Default Buffering Multiple Polygon Features with ArcObjects 9.2

    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:
    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
    Code:
    A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred...
    Any hints would be appreciated.
    Last edited by bruce.nielsen; 05-04-2012 at 12:22 PM.
    GIS Specialist
    USDA-Natural Resources Conservation Service

  2. #2
    Bruce Nielsen
    Join Date
    Jan 2011
    Posts
    299
    Points
    130
    Answers Provided
    21


    0

    Default Re: Buffering Multiple Polygon Features with ArcObjects 9.2

    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:
    Code:
    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?
    Click image for larger version

Name:	fl2.PNG
Views:	27
Size:	31.9 KB
ID:	14129
    GIS Specialist
    USDA-Natural Resources Conservation Service

  3. #3
    Bruce Nielsen
    Join Date
    Jan 2011
    Posts
    299
    Points
    130
    Answers Provided
    21


    0
    This post is marked as the answer

    Default Re: Buffering Multiple Polygon Features with ArcObjects 9.2

    ...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:
    Code:
    Dim pGFL As IGeoFeatureLayer = pLayer
    Dim pFCursor As IFeatureCursor = pGFL.SearchDisplayFeatures(Nothing, True)
    Hope this thread helps someone in the future.
    GIS Specialist
    USDA-Natural Resources Conservation Service

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts