Hello,
I am a novice with ArcObjects programming (VBA/VB6). I am trying to select features from a point feature class that intersect with a particular polygon in a polygon feature class. I have tried using both the ISelectionSet interface (with the pFeatureClass.Select method), and the IFeatureSelection interface (the SelectFeatures method). I do not run into any compile or run-time errors, but in both cases the pSelectionSet.Count property returns a '0' at the end of the code. I know that this number should not be '0' (it should be upwards of 100 for some of my File Geodatabses). Why does it return a SelectionSet with 0 features in it?
Here is the code in which I try to use ISelectionSet:
***************************************
'pPtFClass is a point feature class
'pPplotFClass is a polygon feature class
'The above are both within the same FileGeodatabase
'Set up a cursor to move through the features in the polygon feature class
'-------------------------------------------------------------------------
Dim pPPlotFields As IFields
Set pPPlotFields = pPplotFClass.Fields
Dim intPosSUBTYPEField As Integer
intPosSUBTYPEField = pPPlotFields.FindField("SUBTYPE")
Dim intPosOBJECTIDField As Integer
intPosOBJECTIDField = pPPlotFields.FindField("OBJECTID")
Dim pPPlotFeatCursor As IFeatureCursor
Set pPPlotFeatCursor = pPplotFClass.Update(Nothing, True)
If pPPlotFeat Is Nothing Then
MsgBox "No features in abmi_pplot feature class." & vbCrLf & "Exiting subroutine."
Exit Function
End If
Do Until pPPlotFeat Is Nothing
'Select all point features that intersect the polygon whose SUBTYPE = 2
'----------------------------------------------------------------------
If pPPlotFeat.Value(intPosSUBTYPEField) = 2 Then
Dim pPplotIndivFeat As IFeature
Set pPplotIndivFeat = pPplotFClass.GetFeature(pPPlotFeat.Value(intPosOBJECTIDField))
Dim pQueryGeometry As IGeometry
Set pQueryGeometry = pPplotIndivFeat.Shape
Dim pSpatialFilter As ISpatialFilter
Set pSpatialFilter = New SpatialFilter
With pSpatialFilter
Set .Geometry = pQueryGeometry
.GeometryField = pPtFClass.ShapeFieldName
.SpatialRel = esriSpatialRelIntersects
End With
Dim pScratchWSFactory As IScratchWorkspaceFactory
Set pScratchWSFactory = New ScratchWorkspaceFactory
Dim pScratchWS As IWorkspace
Set pScratchWS = pScratchWSFactory.DefaultScratchWorkspace
Dim pInCoreSelSet As ISelectionSet
Set pInCoreSelSet = pPtFClass.Select(pSpatialFilter, _
esriSelectionTypeIDSet, esriSelectionOptionNormal, pScratchWS)
MsgBox "Number of point features in pInCoreSelSet: " & pInCoreSelSet.Count '*<<<<<<<<<<*
End if
Set pPPlotFeat = pPPlotFeatCursor.NextFeature
Loop
Alternatively, here is the code in which I try to use IFeatureSelection:
****************************************************
'pPtFClass is a point feature class
'pPplotFClass is a polygon feature class
'The above are both within the same FileGeodatabase
'Set up a cursor to move through the features in the polygon feature class
'-------------------------------------------------------------------------
Dim pPPlotFields As IFields
Set pPPlotFields = pPplotFClass.Fields
Dim intPosSUBTYPEField As Integer
intPosSUBTYPEField = pPPlotFields.FindField("SUBTYPE")
Dim intPosOBJECTIDField As Integer
intPosOBJECTIDField = pPPlotFields.FindField("OBJECTID")
Dim pPPlotFeatCursor As IFeatureCursor
Set pPPlotFeatCursor = pPplotFClass.Update(Nothing, True)
If pPPlotFeat Is Nothing Then
MsgBox "No features in abmi_pplot feature class." & vbCrLf & _
"Exiting subroutine."
Exit Function
End If
Do Until pPPlotFeat Is Nothing
'Select all point features that intersect the polygon whose SUBTYPE = 2
'----------------------------------------------------------------------
If pPPlotFeat.Value(intPosSUBTYPEField) = 2 Then
Dim pCorePtFLayer As IFeatureLayer
Set pCorePtFLayer = New FeatureLayer
Set pCorePtFLayer.FeatureClass = pPtFClass
Dim pPtCoreFeatSel As IFeatureSelection
Set pPtCoreFeatSel = pCorePtFLayer
Dim pPplotIndivFeat As IFeature
Set pPplotIndivFeat = pPplotFClass.GetFeature(pPPlotFeat.Value(intPosOBJECTIDField))
Dim pQueryGeometry As IGeometry
Set pQueryGeometry = pPplotIndivFeat.Shape
Dim pSpatialFilter As ISpatialFilter
Set pSpatialFilter = New SpatialFilter
With pSpatialFilter
Set .Geometry = pQueryGeometry
.GeometryField = pPtFClass.ShapeFieldName
.SpatialRel = esriSpatialRelIntersects
End With
pPtCoreFeatSel.SelectFeatures pSpatialFilter, esriSelectionResultAdd, False
MsgBox "Number of point features in pInCoreSelSet: " & pInCoreSelSet.Count '*<<<<<<<<<<*
End if
Set pPPlotFeat = pPPlotFeatCursor.NextFeature
Loop
Both of these return a '0' on for the .Count method (see lines with '*<<<<<<<<<<*).
I very much appreciate any advice or suggestions! Thank you!
Regards,
Jen Hird