Buffering Multiple Polygon Features with ArcObjects 9.2

605
2
Jump to solution
05-04-2012 11:12 AM
BruceNielsen
Occasional Contributor III
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.
0 Kudos
1 Solution

Accepted Solutions
BruceNielsen
Occasional Contributor III
...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.

View solution in original post

0 Kudos
2 Replies
BruceNielsen
Occasional Contributor III
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]
0 Kudos
BruceNielsen
Occasional Contributor III
...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.
0 Kudos