| |
Public Sub SelectFeaturesfromPolyBuffer()
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pFFromLayer As IFeatureLayer, pFToLayer As IFeatureLayer
If pMxDoc.FocusMap.LayerCount < 2 Then Exit Sub 'must be at least two layers
'first two must be feature layers
If Not TypeOf pMxDoc.FocusMap.Layer(0) Is IFeatureLayer Then Exit Sub
If Not TypeOf pMxDoc.FocusMap.Layer(1) Is IFeatureLayer Then Exit Sub
Set pFFromLayer = pMxDoc.FocusMap.Layer(0)
Set pFToLayer = pMxDoc.FocusMap.Layer(1)
If pFFromLayer.FeatureClass.ShapeType <> esriGeometryPolygon Then Exit Sub 'must be polys
If pFToLayer.FeatureClass.ShapeType <> esriGeometryPoint Then Exit Sub 'must be points
Dim pFSel As IFeatureSelection
Set pFSel = pFFromLayer
If pFSel.SelectionSet.Count = 0 Then Exit Sub 'get a selected polygon
Dim pFCur As IFeatureCursor
pFSel.SelectionSet.Search Nothing, True, pFCur
Dim pFeature As IFeature
Set pFeature = pFCur.NextFeature
If pFeature Is Nothing Then Exit Sub
Dim pPolygon As IPolygon
Set pPolygon = pFeature.ShapeCopy
Dim pTopo As ITopologicalOperator
Set pTopo = pPolygon
Dim pBufPoly As IPolygon
Set pBufPoly = pTopo.Buffer(20) 'set this to your buffer distance
Dim pFilter As ISpatialFilter
Set pFilter = New SpatialFilter
pFilter.SpatialRel = esriSpatialRelContains
Set pFilter.Geometry = pBufPoly
'now select those features in the to layer that are completely within
'the buffer polygon
Set pFSel = pFToLayer
pFSel.SelectFeatures pFilter, esriSelectionResultNew, False
pMxDoc.ActiveView.Refresh
End Sub |