POST
|
Hi Jeff, Thank you so much for the quick response, and the suggestion! I actually found my mistake - someone changed the meaning of the "SUBTYPE" attribute in the polygon layer in the newer version of the data sets I am working with, so it should actually have been a 1 instead of a 2. In other words, I was using the wrong polygon for the spatial query (one that did not have any point features contained within it). Once I changed this, the code worked. So it was a logical error on my part. It's funny how you find the answer yourself after you have decided to admit defeat and ask for help 🙂 Thanks again for the help! I've found these forums to be very informative many, many times, and it is all due to people like you. Regards, Jen
... View more
08-12-2010
09:55 AM
|
0
|
0
|
277
|
POST
|
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
... View more
08-11-2010
12:47 PM
|
0
|
3
|
798
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|